List of usage examples for javax.persistence.criteria Fetch fetch
<Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> attribute);
From source file:org.jdal.dao.jpa.JpaUtils.java
/** * Copy Fetches//w w w .j a 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: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 ww . ja v a 2s.co m*/ } }
From source file:org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery.java
/** * Creates the from fragment of the query. * //from w w w. j ava2 s .c o m * @param cb * the criteria builder * @param q * the query * @param from * the from metadata * * @since 2.0.0 */ private void constructFrom(CriteriaBuilderImpl cb, AbstractQuery<?> q, Tree froms) { for (int i = 0; i < froms.getChildCount(); i++) { final Tree from = froms.getChild(i); // root query from if (from.getType() == JpqlParser.ST_FROM) { final Aliased fromDef = new Aliased(from.getChild(0)); final EntityTypeImpl<Object> entity = this.getEntity(fromDef.getQualified().toString()); final RootImpl<Object> r = (RootImpl<Object>) q.from(entity); r.alias(fromDef.getAlias()); this.putAlias((BaseQuery<?>) q, from, fromDef, r); this.constructJoins(cb, q, r, from.getChild(1)); if (from.getChild(from.getChildCount() - 1).getType() == JpqlParser.LALL_PROPERTIES) { for (final AssociationMappingImpl<?, ?, ?> association : entity.getAssociations()) { if (!association.isEager()) { final Iterator<String> pathIterator = Splitter.on(".").split(association.getPath()) .iterator(); // Drop the root part pathIterator.next(); Fetch<?, ?> fetch = null; while (pathIterator.hasNext()) { fetch = fetch == null ? r.fetch(pathIterator.next()) : fetch.fetch(pathIterator.next()); } } } } } // in collection form else if (from.getType() == JpqlParser.ST_COLL) { final Aliased aliased = new Aliased(from.getChild(1)); AbstractFrom<?, ?> parent = this.getAliased(q, from.getChild(0).getText()); int depth = 0; for (final String segment : aliased.getQualified().getSegments()) { if ((depth > 0) && (parent instanceof PluralJoin)) { throw new PersistenceException( "Cannot qualify, only embeddable joins within the path allowed, " + "line " + from.getLine() + ":" + from.getCharPositionInLine()); } parent = parent.join(segment, JoinType.LEFT); depth++; } parent.alias(aliased.getAlias()); this.putAlias((BaseQueryImpl<?>) q, from.getChild(1), aliased, parent); } // sub query from else { final Aliased fromDef = new Aliased(from); final EntityTypeImpl<Object> entity = this.getEntity(fromDef.getQualified().toString()); final RootImpl<Object> r = (RootImpl<Object>) q.from(entity); r.alias(fromDef.getAlias()); this.putAlias((BaseQuery<?>) q, from, fromDef, r); } } }