Search in sources :

Example 1 with IndexFieldImpl

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

the class IndexFieldDaoImpl method readIndexFieldByAbbreviationAndEntityType.

@Override
public IndexField readIndexFieldByAbbreviationAndEntityType(String abbreviation, FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
    Root<IndexFieldImpl> root = criteria.from(IndexFieldImpl.class);
    criteria.select(root);
    if (entityType == null) {
        criteria.where(builder.equal(root.get("field").get("abbreviation").as(String.class), abbreviation));
    } else {
        criteria.where(builder.and(builder.equal(root.get("field").get("abbreviation").as(String.class), abbreviation), builder.equal(root.get("field").get("entityType").as(String.class), entityType.getType())));
    }
    TypedQuery<IndexField> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    List<IndexField> resultList = query.getResultList();
    return CollectionUtils.isNotEmpty(resultList) ? resultList.get(0) : null;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldImpl(org.broadleafcommerce.core.search.domain.IndexFieldImpl) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Example 2 with IndexFieldImpl

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

the class IndexFieldDaoImpl method readFieldsByEntityType.

@Override
public List<IndexField> readFieldsByEntityType(FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
    Root<IndexFieldImpl> root = criteria.from(IndexFieldImpl.class);
    criteria.select(root);
    criteria.where(root.get("field").get("entityType").as(String.class).in(entityType.getAllLookupTypes()));
    TypedQuery<IndexField> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldImpl(org.broadleafcommerce.core.search.domain.IndexFieldImpl) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Example 3 with IndexFieldImpl

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

the class IndexFieldDaoImpl method readSearchableFieldsByEntityType.

@Override
public List<IndexField> readSearchableFieldsByEntityType(FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
    Root<IndexFieldImpl> root = criteria.from(IndexFieldImpl.class);
    criteria.select(root);
    criteria.where(builder.equal(root.get("searchable").as(Boolean.class), Boolean.TRUE), root.get("field").get("entityType").as(String.class).in(entityType.getAllLookupTypes()));
    TypedQuery<IndexField> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldImpl(org.broadleafcommerce.core.search.domain.IndexFieldImpl) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Example 4 with IndexFieldImpl

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

the class IndexFieldDaoImpl method readIndexFieldByFieldId.

@Override
public IndexField readIndexFieldByFieldId(Long fieldId) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexField> criteria = builder.createQuery(IndexField.class);
    Root<IndexFieldImpl> search = criteria.from(IndexFieldImpl.class);
    criteria.select(search);
    criteria.where(builder.equal(search.join("field").get("id").as(Long.class), fieldId));
    TypedQuery<IndexField> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    try {
        return query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldImpl(org.broadleafcommerce.core.search.domain.IndexFieldImpl) NoResultException(javax.persistence.NoResultException) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Aggregations

CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 IndexField (org.broadleafcommerce.core.search.domain.IndexField)4 IndexFieldImpl (org.broadleafcommerce.core.search.domain.IndexFieldImpl)4 NoResultException (javax.persistence.NoResultException)1