List of usage examples for javax.persistence.criteria Fetch getAttribute
Attribute<? super Z, ?> getAttribute();
From source file:org.querybyexample.jpa.JpaUtil.java
/** * Convert the passed propertyPath into a JPA path. * <p>//from w ww . j a va 2 s .c o 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.jdal.dao.jpa.JpaUtils.java
/** * Copy Fetches/*from w ww .ja v a2s . co m*/ * @param from source Fetch * @param to dest Fetch */ public static void copyFetches(Fetch<?, ?> from, Fetch<?, ?> to) { for (Fetch<?, ?> f : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName()); // recursively copy fetches copyFetches(f, toFetch); } }
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Copy Joins/*from w w w .j a v a2 s. c o m*/ * @param from source Join * @param to destination Join */ public static void copyJoins(From<?, ?> from, From<?, ?> to) { for (Join<?, ?> j : from.getJoins()) { Join<?, ?> toJoin = to.join(j.getAttribute().getName(), j.getJoinType()); toJoin.alias(getOrCreateAlias(j)); copyJoins(j, toJoin); } for (Fetch<?, ?> f : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName()); copyFetches(f, toFetch); } }
From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java
private static boolean isCollectionFetch(FetchParent<?, ?> parent) { boolean result = false; for (Fetch<?, ?> fetch : parent.getFetches()) { Attribute<?, ?> attribute = fetch.getAttribute(); boolean nested = isCollectionFetch(fetch); result = result || attribute.isCollection() || nested; }//from w w w . j av a 2 s . co m return result; }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
@SuppressWarnings("unchecked") public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) { Path<?> path = root;/*ww w . j a v a2s. c o m*/ for (Attribute<?, ?> attribute : attributes) { boolean found = false; if (path instanceof FetchParent) { for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) { if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) { path = (Join<E, ?>) fetch; found = true; break; } } } if (!found) { if (attribute instanceof PluralAttribute) { path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT); } else { path = path.get(attribute.getName()); } } } return (Path<F>) path; }
From source file:com.zero.dao.impl.BaseDaoImpl.java
private void copyFetches(Fetch<?, ?> from, Fetch<?, ?> to) { for (Fetch<?, ?> fetch : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(fetch.getAttribute().getName()); copyFetches(fetch, toFetch);//w w w.j a va2s . c om } }
From source file:com.zero.dao.impl.BaseDaoImpl.java
private void copyJoins(From<?, ?> from, From<?, ?> to) { for (Join<?, ?> join : from.getJoins()) { Join<?, ?> toJoin = to.join(join.getAttribute().getName(), join.getJoinType()); toJoin.alias(getAlias(join));/* w w w. j av a2 s. c o m*/ copyJoins(join, toJoin); } for (Fetch<?, ?> fetch : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(fetch.getAttribute().getName()); copyFetches(fetch, toFetch); } }