Search in sources :

Example 1 with SearchFacetRangeImpl

use of org.broadleafcommerce.core.search.domain.SearchFacetRangeImpl in project BroadleafCommerce by BroadleafCommerce.

the class SearchFacetDaoImpl method readSearchFacetRangesForSearchFacet.

@Override
public List<SearchFacetRange> readSearchFacetRangesForSearchFacet(SearchFacet searchFacet) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<SearchFacetRange> criteria = builder.createQuery(SearchFacetRange.class);
    Root<SearchFacetRangeImpl> ranges = criteria.from(SearchFacetRangeImpl.class);
    criteria.select(ranges);
    Predicate facetRestriction = builder.equal(ranges.get("searchFacet"), searchFacet);
    // if it hadn't
    if (ArchiveStatus.class.isAssignableFrom(SearchFacetRangeImpl.class)) {
        criteria.where(builder.and(facetRestriction, builder.or(builder.isNull(ranges.get("archiveStatus").get("archived").as(String.class)), builder.notEqual(ranges.get("archiveStatus").get("archived").as(Character.class), 'Y'))));
    } else {
        criteria.where(facetRestriction);
    }
    TypedQuery<SearchFacetRange> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return new ArrayList<>();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchFacetRangeImpl(org.broadleafcommerce.core.search.domain.SearchFacetRangeImpl) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) NoResultException(javax.persistence.NoResultException) Predicate(javax.persistence.criteria.Predicate)

Aggregations

NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 SearchFacetRange (org.broadleafcommerce.core.search.domain.SearchFacetRange)1 SearchFacetRangeImpl (org.broadleafcommerce.core.search.domain.SearchFacetRangeImpl)1