Example usage for javax.persistence.criteria Root getFetches

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

Introduction

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

Prototype

java.util.Set<Fetch<X, ?>> getFetches();

Source Link

Document

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

Usage

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

/**
 * Convert the passed propertyPath into a JPA path.
 * <p>//from   www.  j a  va  2 s .  co  m
 * 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 ww.  j  a  v  a 2  s.com
    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());
    }
}