Search in sources :

Example 1 with ProductOptionXrefImpl

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductOption(org.broadleafcommerce.core.catalog.domain.ProductOption) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Predicate(javax.persistence.criteria.Predicate) ProductOptionXrefImpl(org.broadleafcommerce.core.catalog.domain.ProductOptionXrefImpl)

Aggregations

ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductOption (org.broadleafcommerce.core.catalog.domain.ProductOption)1 ProductOptionXref (org.broadleafcommerce.core.catalog.domain.ProductOptionXref)1 ProductOptionXrefImpl (org.broadleafcommerce.core.catalog.domain.ProductOptionXrefImpl)1