use of org.broadleafcommerce.core.catalog.domain.ProductOptionXrefImpl in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionDaoImpl method getProductIdsUsingProductOptionByIdQuery.
private TypedQuery<Long> getProductIdsUsingProductOptionByIdQuery(Long productOptionId, boolean count) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The root of our search is ProductOptionXref
Root<ProductOptionXrefImpl> productOptionXref = criteria.from(ProductOptionXrefImpl.class);
Join<ProductOptionXref, Product> product = productOptionXref.join("product");
Join<ProductOptionXref, ProductOption> productOption = productOptionXref.join("productOption");
if (count) {
criteria.select(builder.count(product));
} else {
// Product IDs are what we want back
criteria.select(product.get("id").as(Long.class));
}
criteria.distinct(true);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(productOption.get("id").in(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, productOptionId)));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return em.createQuery(criteria);
}
Aggregations