Search in sources :

Example 1 with StaticAssetImpl

use of org.broadleafcommerce.cms.file.domain.StaticAssetImpl in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetDaoImpl method readStaticAssetByFullUrl.

@Override
public StaticAsset readStaticAssetByFullUrl(String fullUrl) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StaticAsset> criteria = builder.createQuery(StaticAsset.class);
    Root<StaticAssetImpl> handler = criteria.from(StaticAssetImpl.class);
    criteria.select(handler);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    List<Order> sorts = new ArrayList<Order>();
    restrictions.add(builder.equal(handler.get("fullUrl"), fullUrl));
    try {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().setup(StaticAssetImpl.class, null);
            queryExtensionManager.getProxy().refineRetrieve(StaticAssetImpl.class, null, builder, criteria, handler, restrictions);
            queryExtensionManager.getProxy().refineOrder(StaticAssetImpl.class, null, builder, criteria, handler, sorts);
        }
        criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
        if (!org.apache.commons.collections.CollectionUtils.isEmpty(sorts)) {
            criteria.orderBy(sorts);
        }
        TypedQuery<StaticAsset> query = em.createQuery(criteria);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        List<StaticAsset> response = query.getResultList();
        if (response.size() > 0) {
            return response.get(0);
        }
        return null;
    } finally {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().breakdown(StaticAssetImpl.class, null);
        }
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) StaticAsset(org.broadleafcommerce.cms.file.domain.StaticAsset) StaticAssetImpl(org.broadleafcommerce.cms.file.domain.StaticAssetImpl) Predicate(javax.persistence.criteria.Predicate)

Example 2 with StaticAssetImpl

use of org.broadleafcommerce.cms.file.domain.StaticAssetImpl in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetDaoImpl method readStaticAssetById.

@Override
public StaticAsset readStaticAssetById(Long id) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StaticAsset> criteria = builder.createQuery(StaticAsset.class);
    Root<StaticAssetImpl> handler = criteria.from(StaticAssetImpl.class);
    criteria.select(handler);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(handler.get("id"), id));
    if (queryExtensionManager != null) {
        queryExtensionManager.getProxy().setup(StaticAssetImpl.class, null);
        queryExtensionManager.getProxy().refineRetrieve(StaticAssetImpl.class, null, builder, criteria, handler, restrictions);
    }
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<StaticAsset> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    List<StaticAsset> response = query.getResultList();
    if (response.size() > 0) {
        return response.get(0);
    }
    return null;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArrayList(java.util.ArrayList) StaticAsset(org.broadleafcommerce.cms.file.domain.StaticAsset) StaticAssetImpl(org.broadleafcommerce.cms.file.domain.StaticAssetImpl) Predicate(javax.persistence.criteria.Predicate)

Example 3 with StaticAssetImpl

use of org.broadleafcommerce.cms.file.domain.StaticAssetImpl in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetDaoImpl method readAllStaticAssets.

public List<StaticAsset> readAllStaticAssets() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StaticAsset> criteria = builder.createQuery(StaticAsset.class);
    Root<StaticAssetImpl> handler = criteria.from(StaticAssetImpl.class);
    criteria.select(handler);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    List<Order> sorts = new ArrayList<Order>();
    try {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().setup(StaticAssetImpl.class, null);
            queryExtensionManager.getProxy().refineRetrieve(StaticAssetImpl.class, null, builder, criteria, handler, restrictions);
            queryExtensionManager.getProxy().refineOrder(StaticAssetImpl.class, null, builder, criteria, handler, sorts);
        }
        criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
        return em.createQuery(criteria).getResultList();
    } catch (NoResultException e) {
        return new ArrayList<StaticAsset>();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) StaticAsset(org.broadleafcommerce.cms.file.domain.StaticAsset) NoResultException(javax.persistence.NoResultException) StaticAssetImpl(org.broadleafcommerce.cms.file.domain.StaticAssetImpl) Predicate(javax.persistence.criteria.Predicate)

Aggregations

ArrayList (java.util.ArrayList)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 StaticAsset (org.broadleafcommerce.cms.file.domain.StaticAsset)3 StaticAssetImpl (org.broadleafcommerce.cms.file.domain.StaticAssetImpl)3 Order (javax.persistence.criteria.Order)2 NoResultException (javax.persistence.NoResultException)1