List of usage examples for javax.persistence.criteria Join getAttribute
Attribute<? super Z, ?> getAttribute();
From source file:org.querybyexample.jpa.JpaUtil.java
/** * Convert the passed propertyPath into a JPA path. * <p>/*from w w w . jav a2s . 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 Joins/*from w ww . j av 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.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));/*from w w w . j a v a 2 s . c o m*/ copyJoins(join, toJoin); } for (Fetch<?, ?> fetch : from.getFetches()) { Fetch<?, ?> toFetch = to.fetch(fetch.getAttribute().getName()); copyFetches(fetch, toFetch); } }
From source file:ru.savvy.jpafilterbuilder.FilterCriteriaBuilder.java
private Join reuseJoin(From<?, ?> path, String fieldName, boolean outer) { for (Join join : path.getJoins()) { if (join.getAttribute().getName().equals(fieldName)) { if ((join.getJoinType() == JoinType.LEFT) == outer) { logger.debug("Reusing existing join for field " + fieldName); return join; }// w w w . ja v a2s .c o m } } return outer ? path.join(fieldName, JoinType.LEFT) : path.join(fieldName); }