List of usage examples for javax.persistence.criteria JoinType LEFT
JoinType LEFT
To view the source code for javax.persistence.criteria JoinType LEFT.
Click Source Link
From source file:org.batoo.jpa.core.impl.criteria.join.FetchParentImpl.java
/** * {@inheritDoc}// ww w. j a v a 2s. co m * */ @Override public final <Y> FetchImpl<X, Y> fetch(SingularAttribute<? super X, Y> attribute) { return this.fetch(attribute, JoinType.LEFT); }
From source file:org.batoo.jpa.core.impl.criteria.join.FetchParentImpl.java
/** * {@inheritDoc}/*from ww w . j ava 2s .co m*/ * */ @Override @SuppressWarnings("unchecked") public final <Y> FetchImpl<X, Y> fetch(String attributeName) { return (FetchImpl<X, Y>) this.fetch(attributeName, JoinType.LEFT); }
From source file:org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery.java
/** * Creates the from fragment of the query. * /*ww w . j ava2 s . c om*/ * @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); } } }
From source file:org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery.java
/** * Creates the from fragment of the query. * /* w w w . java2s . c om*/ * @param cb * the criteria builder * @param q * the query join * @param r * the root * @param joins * the joins metadata * * @since 2.0.0 */ private void constructJoins(CriteriaBuilderImpl cb, AbstractQuery<?> q, RootImpl<Object> r, Tree joins) { for (int i = 0; i < joins.getChildCount(); i++) { final Tree join = joins.getChild(i); JoinType joinType = JoinType.INNER; final int joinSpecification = join.getChild(0).getType(); int offset = 0; if (joinSpecification == JpqlParser.INNER) { offset = 1; joinType = JoinType.INNER; } else if (joinSpecification == JpqlParser.LEFT) { offset = 1; joinType = JoinType.LEFT; } if (join.getChildCount() == (offset + 3)) { FetchParent<?, ?> parent = this.getAliased(q, join.getChild(offset).getText()); final Qualified qualified = new Qualified(join.getChild(offset + 1).getChild(0)); for (final String segment : qualified.getSegments()) { parent = parent.fetch(segment, joinType); } } else { AbstractFrom<?, ?> parent = this.getAliased(q, join.getChild(offset).getText()); final Aliased aliased = new Aliased(join.getChild(offset + 1)); 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 " + join.getLine() + ":" + join.getCharPositionInLine()); } parent = parent.join(segment, joinType); depth++; } parent.alias(aliased.getAlias()); this.putAlias((BaseQuery<?>) q, join.getChild(1), aliased, parent); } } }
From source file:org.batoo.jpa.core.impl.criteria.path.EntityPath.java
/** * @param parent//from w w w.jav a 2 s . c o m * the parent path * @param mapping * the path name * @param entity * the entity * * @since 2.0.0 */ @SuppressWarnings("unchecked") public EntityPath(ParentPath<?, Z> parent, SingularAssociationMappingImpl<?, Z> mapping, EntityTypeImpl<X> entity) { super(parent, entity.getJavaType()); this.mapping = mapping; this.pathName = mapping.getAttribute().getName(); this.entity = entity; if (!this.mapping.isOwner() || (this.mapping.getForeignKey() == null)) { this.fetchRoot = (FetchImpl<Z, X>) this.getParentPath().getFetchRoot().join(this.pathName, JoinType.LEFT); } }
From source file:org.batoo.jpa.core.impl.criteria.path.EntityPath.java
/** * {@inheritDoc}// ww w.j a v a 2 s .co m * */ @Override @SuppressWarnings("unchecked") public FetchParentImpl<?, X> getFetchRoot() { if (this.fetchRoot == null) { this.fetchRoot = (FetchImpl<Z, X>) this.getParentPath().getFetchRoot().join(this.pathName, JoinType.LEFT); } return this.fetchRoot; }
From source file:org.batoo.jpa.core.impl.model.EntityTypeImpl.java
private void prepareEagerJoins(FetchParent<?, ?> r, int depth, AssociationMappingImpl<?, ?, ?> parent, JoinedMapping<?, ?, ?>[] mappings) { for (final JoinedMapping<?, ?, ?> mapping : mappings) { // Element collection if (mapping.getMappingType() == MappingType.ELEMENT_COLLECTION) { r.fetch(mapping.getAttribute().getName(), JoinType.LEFT); continue; }/*from ww w. ja v a 2 s. c o m*/ // embeddable else if (mapping.getMappingType() == MappingType.EMBEDDABLE) { final Fetch<?, Object> r2 = r.fetch(mapping.getAttribute().getName(), JoinType.LEFT); this.prepareEagerJoins(r2, depth, parent, ((EmbeddedMappingImpl<?, ?>) mapping).getEagerMappings()); continue; } // association else { final AssociationMappingImpl<?, ?, ?> association = (AssociationMappingImpl<?, ?, ?>) mapping; // if we are coming from the inverse side and inverse side is not many-to-one then skip if ((parent != null) && // (association.getInverse() == parent) && // (parent.getAttribute() .getPersistentAttributeType() != PersistentAttributeType.MANY_TO_ONE)) { continue; } // check association's fetch strategy and max depth if ((association.getMaxFetchJoinDepth() < depth) || (association.getFetchStrategy() == FetchStrategyType.SELECT)) { continue; } final Fetch<?, Object> r2 = r.fetch(((AbstractMapping<?, ?, ?>) mapping).getAttribute().getName(), JoinType.LEFT); final EntityTypeImpl<?> type = association.getType(); type.prepareEagerJoins(r2, depth + 1, association); } } }
From source file:org.batoo.jpa.core.impl.model.type.EntityTypeImpl.java
private void prepareEagerJoins(FetchParent<?, ?> r, int depth, AssociationMapping<?, ?, ?> parent, JoinedMapping<?, ?, ?>[] mappings) { for (final JoinedMapping<?, ?, ?> mapping : mappings) { // Element collection if (mapping.getMappingType() == MappingType.ELEMENT_COLLECTION) { r.fetch(mapping.getAttribute().getName(), JoinType.LEFT); continue; }/*from w w w . j av a 2 s .c om*/ // embeddable else if (mapping.getMappingType() == MappingType.EMBEDDABLE) { final Fetch<?, Object> r2 = r.fetch(mapping.getAttribute().getName(), JoinType.LEFT); this.prepareEagerJoins(r2, depth, parent, ((EmbeddedMapping<?, ?>) mapping).getEagerMappings()); continue; } // association else { final AssociationMapping<?, ?, ?> association = (AssociationMapping<?, ?, ?>) mapping; // if we are coming from the inverse side and inverse side is not many-to-one then skip if ((parent != null) && // (association.getInverse() == parent) && // (parent.getAttribute() .getPersistentAttributeType() != PersistentAttributeType.MANY_TO_ONE)) { continue; } final Fetch<?, Object> r2 = r.fetch(mapping.getAttribute().getName(), JoinType.LEFT); final EntityTypeImpl<?> type = association.getType(); type.prepareEagerJoins(r2, depth + 1, association); } } }
From source file:org.broadleafcommerce.admin.server.service.handler.ProductCustomPersistenceHandler.java
@Override public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { cto.getNonCountAdditionalFilterMappings() .add(new FilterMapping().withDirectFilterValues(new EmptyFilterValues()) .withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() { public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { root.fetch("defaultSku", JoinType.LEFT); root.fetch("defaultCategory", JoinType.LEFT); return null; }//from w ww . ja va 2s . c om }))); return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto); }
From source file:org.broadleafcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByIds(List<Long> productIds) { if (productIds == null || productIds.size() == 0) { return null; }/* ww w . j av a 2s . c o m*/ if (productIds.size() > 100) { logger.warn("Not recommended to use the readProductsByIds method for long lists of productIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "product ids was (" + productIds.size() + ") in length."); } // Set up the criteria query that specifies we want to return Products CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = builder.createQuery(Product.class); Root<ProductImpl> product = criteria.from(ProductImpl.class); FetchParent fetchParent = product.fetch("defaultSku", JoinType.LEFT); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { fetchParent.fetch("skuMedia", JoinType.LEFT); } criteria.select(product); // We only want results that match the product IDs criteria.where(product.get("id").as(Long.class).in( sandBoxHelper.mergeCloneIds(ProductImpl.class, productIds.toArray(new Long[productIds.size()])))); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { criteria.distinct(true); } TypedQuery<Product> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }