Example usage for javax.persistence TupleElement getAlias

List of usage examples for javax.persistence TupleElement getAlias

Introduction

In this page you can find the example usage for javax.persistence TupleElement getAlias.

Prototype

String getAlias();

Source Link

Document

Return the alias assigned to the tuple element or null, if no alias has been assigned.

Usage

From source file:com.evanzeimet.queryinfo.jpa.result.AbstractTupleToPojoQueryInfoResultConverter.java

protected MethodHandle getMethodHandleForElement(TupleElement<?> element) throws QueryInfoException {
    String elementAlias = element.getAlias();
    String memberName = attributeUtils.convertAttributeNameToMemberName(elementAlias);
    Class<?> elementJavaType = element.getJavaType();

    MethodHandle result = findFieldSetterHandle(memberName, elementJavaType);

    if (result == null) {
        result = findFieldPutHandle(memberName, elementJavaType);
    }//  ww  w.  ja  va2  s  . c  o m

    if (result == null) {
        String message = String.format("Could not find accessible setter or field for attribute [%s]",
                elementAlias);
        throw new QueryInfoException(message);
    }

    return result;
}

From source file:com.evanzeimet.queryinfo.jpa.result.AbstractTupleToPojoQueryInfoResultConverter.java

protected Map<String, MethodHandle> mapElementMethodHandles(List<TupleElement<?>> tupleElements)
        throws QueryInfoException {
    int elementCount = tupleElements.size();
    Map<String, MethodHandle> result = new HashMap<>(elementCount);

    Iterator<TupleElement<?>> elementIterator = tupleElements.iterator();

    while (elementIterator.hasNext()) {
        TupleElement<?> element = elementIterator.next();
        String elementAlias = element.getAlias();

        MethodHandle methodHandle = getMethodHandleForElement(element);

        result.put(elementAlias, methodHandle);
    }// ww  w. j  ava  2 s  . c  om

    return result;
}

From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpa2.JpaHelper.java

/**
 *
 * @param <T>/* w w  w . j  a va 2 s . c o  m*/
 * @param tuple
 * @param object
 * @return
 */
public static <T> T mapTupleToObject(Tuple tuple, T object)
        throws IllegalAccessException, InvocationTargetException {
    assert tuple != null;
    assert object != null;
    try {
        for (TupleElement<?> element : tuple.getElements()) {
            if (element.getAlias() != null) {
                BeanUtils.setProperty(object, element.getAlias(), tuple.get(element.getAlias()));
            }
        }
        return object;
    } catch (Exception e) {
        log.error("mapTupleToObject not successful", e);
        throw new QueryConfigException("mapTupleToObject not successful");
    }
}