Example usage for javax.persistence.criteria Root getJoins

List of usage examples for javax.persistence.criteria Root getJoins

Introduction

In this page you can find the example usage for javax.persistence.criteria Root getJoins.

Prototype

Set<Join<X, ?>> getJoins();

Source Link

Document

Return the joins that have been made from this bound type.

Usage

From source file:org.jdal.dao.jpa.JpaUtils.java

/**
 * Find Joined Root of type clazz//from   w ww .j a  v  a  2s .  co m
 * @param <T>
 * @param query the criteria query
 * @param rootClass the root class
 * @param joinClass the join class
 * @return the Join
 */
@SuppressWarnings("unchecked")
public static <T, K> Join<T, K> findJoinedType(CriteriaQuery<T> query, Class<T> rootClass, Class<K> joinClass) {
    Root<T> root = findRoot(query, rootClass);
    Join<T, K> join = null;
    for (Join<T, ?> j : root.getJoins()) {
        if (j.getJoinType().equals(joinClass)) {
            join = (Join<T, K>) j;
        }
    }
    return join;
}

From source file:org.querybyexample.jpa.JpaUtil.java

/**
 * Convert the passed propertyPath into a JPA path.
 * <p>// ww  w . j  ava2s.  c om
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
public static <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
    Path<?> path = root;
    for (Attribute<?, ?> attribute : attributes) {
        boolean found = false;
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
                path = (Join<E, ?>) fetch;
                found = true;
                break;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (attribute.getName().equals(join.getAttribute().getName())) {
                path = join;
                found = true;
                break;
            }
        }
        if (!found) {
            path = path.get(attribute.getName());
        }
    }
    return (Path<F>) path;
}

From source file:org.apache.openjpa.persistence.criteria.CriteriaQueryImpl.java

private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
    if (roots == null)
        return;//from   w w  w .  j a va2 s .  co  m
    int i = 0;
    for (Root r : roots) {
        buffer.append(((ExpressionImpl<?>) r).asVariable(this));
        if (++i != roots.size())
            buffer.append(", ");
        renderJoins(buffer, r.getJoins());
        renderFetches(buffer, r.getFetches());
    }
}

From source file:org.jboss.pressgang.ccms.filter.utils.JPAUtils.java

/**
 * Find Joined Root of type clazz//from ww  w  . ja v  a2s  .c  o  m
 *
 * @param <T>
 * @param query     the criteria query
 * @param rootClass the root class
 * @param joinClass the join class
 * @return the Join
 */
@SuppressWarnings("unchecked")
public static <T, K> Join<T, K> findJoinedType(Root<T> root, Class<T> rootClass, Class<K> joinClass) {
    Join<T, K> join = null;
    for (Join<T, ?> j : root.getJoins()) {
        if (j.getJavaType().equals(joinClass)) {
            join = (Join<T, K>) j;
        }
    }
    return join;
}