Java 类org.hibernate.ejb.QueryHints 实例源码

项目:metaworks_framework    文件:StructuredContentDaoImpl.java   
@Override
public List<StructuredContent> findAllContentItems() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StructuredContent> criteria = builder.createQuery(StructuredContent.class);
    Root<StructuredContentImpl> sc = criteria.from(StructuredContentImpl.class);

    criteria.select(sc);

    try {
        TypedQuery<StructuredContent> query = em.createQuery(criteria);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        return query.getResultList();
    } catch (NoResultException e) {
        return new ArrayList<StructuredContent>();
    }
}
项目:blcdemo    文件:TranslationDaoImpl.java   
@Override
public Long countTranslationEntries(TranslatedEntity entityType, ResultType stage) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
    Root<TranslationImpl> root = criteria.from(TranslationImpl.class);
    criteria.select(builder.count(root));
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(root.get("entityType"), entityType.getFriendlyType()));
    try {
        if (extensionManager != null) {
            extensionManager.getProxy().setup(TranslationImpl.class, stage);
            extensionManager.getProxy().refineRetrieve(TranslationImpl.class, stage, builder, criteria, root, restrictions);
        }
        criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));

        TypedQuery<Long> query = em.createQuery(criteria);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        return query.getSingleResult();
    } finally {
        if (extensionManager != null) {
            extensionManager.getProxy().breakdown(TranslationImpl.class, stage);
        }
    }
}
项目:blcdemo    文件:OrderDaoImpl.java   
@Override
public List<Order> readOrdersByIds(List<Long> orderIds) {
    if (orderIds == null || orderIds.size() == 0) {
        return null;
    }
    if (orderIds.size() > 100) {
        LOG.warn("Not recommended to use the readOrdersByIds method for long lists of orderIds, since " +
                "Hibernate is required to transform the distinct results. The list of requested" +
                "order ids was (" + orderIds.size() + ") in length.");
    }
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    criteria.select(order);

    // We only want results that match the order IDs
    criteria.where(order.get("id").as(Long.class).in(orderIds));

    TypedQuery<Order> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");

    return query.getResultList();
}
项目:blcdemo    文件:FieldDaoImpl.java   
@Override
public List<Field> readAllSkuFields() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Field> criteria = builder.createQuery(Field.class);

    Root<FieldImpl> root = criteria.from(FieldImpl.class);

    criteria.select(root);
    criteria.where(
            builder.equal(root.get("entityType").as(String.class), FieldEntity.SKU.getType())
            );

    TypedQuery<Field> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    return query.getResultList();
}
项目:SparkCore    文件:CategoryDaoImpl.java   
@Override
public Category findCategoryByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Category) holder.getResult();
        }
    }
    Query query;
    query = em.createNamedQuery("BC_READ_CATEGORY_OUTGOING_URL");
    query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
    query.setParameter("url", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    @SuppressWarnings("unchecked")
    List<Category> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);

    } else {
        return null;
    }
}
项目:metaworks_framework    文件:SystemPropertiesDaoImpl.java   
@Override
public SystemProperty readSystemPropertyByName(final String name) {
    return getCachedObject(SystemProperty.class, "blSystemPropertyNullCheckCache", "SYSTEM_PROPERTY_MISSING_CACHE_HIT_RATE", new PersistentRetrieval<SystemProperty>() {
        @Override
        public SystemProperty retrievePersistentObject() {
            TypedQuery<SystemProperty> query = em.createNamedQuery("BC_READ_SYSTEM_PROPERTIES_BY_NAME", SystemProperty.class);
            query.setParameter("propertyName", name);
            query.setHint(QueryHints.HINT_CACHEABLE, true);
            List<SystemProperty> props = query.getResultList();
            if (props != null && ! props.isEmpty()) {
                return props.get(0);
            }
            return null;
        }
    }, name, getSite());
}
项目:blcdemo    文件:CategoryDaoImpl.java   
@Override
public List<Category> readAllParentCategories() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Category> criteria = builder.createQuery(Category.class);
    Root<CategoryImpl> category = criteria.from(CategoryImpl.class);

    criteria.select(category);
    criteria.where(builder.isNull(category.get("defaultParentCategory")));
    TypedQuery<Category> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
项目:blcdemo    文件:AdminPermissionDaoImpl.java   
@Override
public AdminPermission readAdminPermissionByNameAndType(String name, String type) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
    Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
    criteria.select(adminPerm);

    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(adminPerm.get("name"), name));
    restrictions.add(builder.equal(adminPerm.get("type"), type));

    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<AdminPermission> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    List<AdminPermission> results = query.getResultList();
    if (results == null || results.size() == 0) {
        return null;
    } else {
        return results.get(0);
    }
}
项目:metaworks_framework    文件:CategoryDaoImpl.java   
@Override
public List<Category> readAllParentCategories() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Category> criteria = builder.createQuery(Category.class);
    Root<CategoryImpl> category = criteria.from(CategoryImpl.class);

    criteria.select(category);
    criteria.where(builder.isNull(category.get("defaultParentCategory")));
    TypedQuery<Category> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
项目:SparkCore    文件:OfferCodeDaoImpl.java   
@Override
@SuppressWarnings("unchecked")
public OfferCode readOfferCodeByCode(String code) {
    OfferCode offerCode = null;
    Query query = null;

    ExtensionResultHolder<Query> resultHolder = new ExtensionResultHolder<Query>();
    ExtensionResultStatusType extensionResult =
            extensionManager.getProxy().createReadOfferCodeByCodeQuery(em, resultHolder, code, true, "query.Offer");

    if (extensionResult != null && ExtensionResultStatusType.HANDLED.equals(extensionResult)) {
        query = resultHolder.getResult();
    } else {
        query = em.createNamedQuery("BC_READ_OFFER_CODE_BY_CODE");
        query.setParameter("code", code);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        query.setHint(QueryHints.HINT_CACHE_REGION, "query.Offer");
    }

    List<OfferCode> result = query.getResultList();
    if (result.size() > 0) {
        offerCode = result.get(0);
    }

    return offerCode;
}
项目:blcdemo    文件:StructuredContentDaoImpl.java   
@Override
public List<StructuredContent> findAllContentItems() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<StructuredContent> criteria = builder.createQuery(StructuredContent.class);
    Root<StructuredContentImpl> sc = criteria.from(StructuredContentImpl.class);

    criteria.select(sc);

    try {
        TypedQuery<StructuredContent> query = em.createQuery(criteria);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        return query.getResultList();
    } catch (NoResultException e) {
        return new ArrayList<StructuredContent>();
    }
}
项目:metaworks_framework    文件:CategoryDaoImpl.java   
@Override
public Category findCategoryByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Category) holder.getResult();
        }
    }
    Query query;
    query = em.createNamedQuery("BC_READ_CATEGORY_OUTGOING_URL");
    query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
    query.setParameter("url", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    @SuppressWarnings("unchecked")
    List<Category> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);

    } else {
        return null;
    }
}
项目:blcdemo    文件:CategoryDaoImpl.java   
@Override
public Category findCategoryByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Category) holder.getResult();
        }
    }
    Query query;
    query = em.createNamedQuery("BC_READ_CATEGORY_OUTGOING_URL");
    query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
    query.setParameter("url", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    @SuppressWarnings("unchecked")
    List<Category> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);

    } else {
        return null;
    }
}
项目:SparkCore    文件:FieldDaoImpl.java   
@Override
public Field readFieldByAbbreviation(String abbreviation) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Field> criteria = builder.createQuery(Field.class);

    Root<FieldImpl> root = criteria.from(FieldImpl.class);

    criteria.select(root);
    criteria.where(
        builder.equal(root.get("abbreviation").as(String.class), abbreviation)
    );

    TypedQuery<Field> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    try {
        return query.getSingleResult();
    } catch (javax.persistence.NoResultException e) {
        //must not be an abbreviation
        return null;
    }
}
项目:metaworks_framework    文件:RatingSummaryDaoImpl.java   
@Override
public RatingSummary readRatingSummary(final String itemId, final RatingType type) {
    final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARY_BY_ITEM_ID_AND_TYPE");
    query.setParameter("itemId", itemId);
    query.setParameter("ratingType", type.getType());
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    RatingSummary ratingSummary = null;

    try {
        ratingSummary = (RatingSummary) query.getSingleResult();
    } catch (NoResultException e) {
        // ignore
    }

    return ratingSummary;
}
项目:metaworks_framework    文件:SearchRedirectDaoImpl.java   
@Override
public SearchRedirect findSearchRedirectBySearchTerm(String searchTerm) {
    Query query;
    query = em.createNamedQuery("BC_READ_SEARCH_URL");
    query.setParameter("searchTerm", searchTerm);
    query.setParameter("now", getCurrentDateAfterFactoringInDateResolution());
    query.setMaxResults(1);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    List<SearchRedirect> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    } else {
        return null;
    }
}
项目:SparkCore    文件:SearchFacetDaoImpl.java   
@Override
public List<SearchFacet> readAllSearchFacets() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class);

    Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class);

    criteria.select(facet);
    criteria.where(
        builder.equal(facet.get("showOnSearch").as(Boolean.class), true)
    );
    TypedQuery<SearchFacet> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    return query.getResultList();
}
项目:blcdemo    文件:AdminPermissionDaoImpl.java   
public boolean isUserQualifiedForOperationOnCeilingEntityViaDefaultPermissions(String ceilingEntityFullyQualifiedName) {
    //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface
    //try the passed in ceiling first, but also try an interfaces implemented
    List<String> testClasses = new ArrayList<String>();
    testClasses.add(ceilingEntityFullyQualifiedName);
    try {
        for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) {
            testClasses.add(((Class<?>) interfaze).getName());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (String testClass : testClasses) {
        Query query = em.createNamedQuery("BC_COUNT_BY_PERMISSION_AND_CEILING_ENTITY");
        query.setParameter("permissionNames", Arrays.asList(AdminSecurityService.DEFAULT_PERMISSIONS));
        query.setParameter("ceilingEntity", testClass);
        query.setHint(QueryHints.HINT_CACHEABLE, true);

        Long count = (Long) query.getSingleResult();
        if (count > 0) {
            return true;
        }
    }
    return false;
}
项目:blcdemo    文件:SkuDaoImpl.java   
@Override
public List<Sku> findSkuByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findSkuByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (List<Sku>) holder.getResult();
        }
    }
    String skuUrlKey = uri.substring(uri.lastIndexOf('/'));
    String productUrl = uri.substring(0, uri.lastIndexOf('/'));
    Query query;

    query = em.createNamedQuery("BC_READ_SKU_BY_OUTGOING_URL");
    query.setParameter("url", uri);
    query.setParameter("productUrl", productUrl);
    query.setParameter("skuUrlKey", skuUrlKey);
    query.setParameter("currentDate", DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution));
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    @SuppressWarnings("unchecked")
    List<Sku> results = query.getResultList();
    return results;
}
项目:blcdemo    文件:FieldDaoImpl.java   
@Override
public List<Field> readAllProductFields() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Field> criteria = builder.createQuery(Field.class);

    Root<FieldImpl> root = criteria.from(FieldImpl.class);

    criteria.select(root);
    criteria.where(
        builder.equal(root.get("entityType").as(String.class), FieldEntity.PRODUCT.getType())
    );

    TypedQuery<Field> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    return query.getResultList();
}
项目:SparkCore    文件:CategoryDaoImpl.java   
@Override
public List<Category> readAllParentCategories() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Category> criteria = builder.createQuery(Category.class);
    Root<CategoryImpl> category = criteria.from(CategoryImpl.class);

    criteria.select(category);
    criteria.where(builder.isNull(category.get("defaultParentCategory")));
    TypedQuery<Category> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
项目:SparkCommerce    文件:AdminPermissionDaoImpl.java   
@Override
public AdminPermission readAdminPermissionByName(String name) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
    Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
    criteria.select(adminPerm);

    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(adminPerm.get("name"), name));

    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<AdminPermission> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    List<AdminPermission> results = query.getResultList();
    if (results == null || results.size() == 0) {
        return null;
    } else {
        return results.get(0);
    }
}
项目:blcdemo    文件:SearchRedirectDaoImpl.java   
@Override
public SearchRedirect findSearchRedirectBySearchTerm(String searchTerm) {
    Query query;
    query = em.createNamedQuery("BC_READ_SEARCH_URL");
    query.setParameter("searchTerm", searchTerm);
    query.setParameter("now", getCurrentDateAfterFactoringInDateResolution());
    query.setMaxResults(1);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    List<SearchRedirect> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    } else {
        return null;
    }
}
项目:SparkCommerce    文件:AdminPermissionDaoImpl.java   
public boolean isUserQualifiedForOperationOnCeilingEntityViaDefaultPermissions(String ceilingEntityFullyQualifiedName) {
    //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface
    //try the passed in ceiling first, but also try an interfaces implemented
    List<String> testClasses = new ArrayList<String>();
    testClasses.add(ceilingEntityFullyQualifiedName);
    try {
        for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) {
            testClasses.add(((Class<?>) interfaze).getName());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (String testClass : testClasses) {
        Query query = em.createNamedQuery("BC_COUNT_BY_PERMISSION_AND_CEILING_ENTITY");
        query.setParameter("permissionNames", Arrays.asList(AdminSecurityService.DEFAULT_PERMISSIONS));
        query.setParameter("ceilingEntity", testClass);
        query.setHint(QueryHints.HINT_CACHEABLE, true);

        Long count = (Long) query.getSingleResult();
        if (count > 0) {
            return true;
        }
    }
    return false;
}
项目:SparkCommerce    文件:AdminPermissionDaoImpl.java   
public boolean doesOperationExistForCeilingEntity(PermissionType permissionType, String ceilingEntityFullyQualifiedName) {
    //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface
    //try the passed in ceiling first, but also try an interfaces implemented
    List<String> testClasses = new ArrayList<String>();
    testClasses.add(ceilingEntityFullyQualifiedName);
    try {
        for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) {
            testClasses.add(((Class<?>) interfaze).getName());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (String testClass : testClasses) {
        Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_BY_TYPE_AND_CEILING_ENTITY");
        query.setParameter("type", permissionType.getType());
        query.setParameter("ceilingEntity", testClass);
        query.setHint(QueryHints.HINT_CACHEABLE, true);

        Long count = (Long) query.getSingleResult();
        if (count > 0) {
            return true;
        }
    }
    return false;
}
项目:blcdemo    文件:SystemPropertiesDaoImpl.java   
@Override
public SystemProperty readSystemPropertyByName(final String name) {
    return getCachedObject(SystemProperty.class, "blSystemPropertyNullCheckCache", "SYSTEM_PROPERTY_MISSING_CACHE_HIT_RATE", new PersistentRetrieval<SystemProperty>() {
        @Override
        public SystemProperty retrievePersistentObject() {
            TypedQuery<SystemProperty> query = em.createNamedQuery("BC_READ_SYSTEM_PROPERTIES_BY_NAME", SystemProperty.class);
            query.setParameter("propertyName", name);
            query.setHint(QueryHints.HINT_CACHEABLE, true);
            List<SystemProperty> props = query.getResultList();
            if (props != null && ! props.isEmpty()) {
                return props.get(0);
            }
            return null;
        }
    }, name, getSite());
}
项目:SparkCommerce    文件:SiteDaoImpl.java   
@Override
public List<Site> readAllActiveSites() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Site> criteria = builder.createQuery(Site.class);
    Root<SiteImpl> site = criteria.from(SiteImpl.class);
    criteria.select(site);
    criteria.where(
        builder.and(
            builder.or(builder.isNull(site.get("archiveStatus").get("archived").as(String.class)),
                builder.notEqual(site.get("archiveStatus").get("archived").as(Character.class), 'Y')),
            builder.or(builder.isNull(site.get("deactivated").as(Boolean.class)),
                builder.notEqual(site.get("deactivated").as(Boolean.class), true))
        )
    );

    TypedQuery<Site> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    return query.getResultList();
}
项目:SparkCommerce    文件:TranslationDaoImpl.java   
@Override
public List<Translation> readTranslations(TranslatedEntity entity, String entityId, String fieldName) {
    entityId = getUpdatedEntityId(entity, entityId);

    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Translation> criteria = builder.createQuery(Translation.class);
    Root<TranslationImpl> translation = criteria.from(TranslationImpl.class);

    criteria.select(translation);
    criteria.where(builder.equal(translation.get("entityType"), entity.getFriendlyType()),
        builder.equal(translation.get("entityId"), entityId),
        builder.equal(translation.get("fieldName"), fieldName)
    );

    TypedQuery<Translation> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    return query.getResultList();
}
项目:SparkCore    文件:RatingSummaryDaoImpl.java   
@Override
public ReviewDetail readReview(final Long customerId, final Long ratingSummaryId) {
    final Query query = em.createNamedQuery("BC_READ_REVIEW_DETAIL_BY_CUSTOMER_ID_AND_RATING_SUMMARY_ID");
    query.setParameter("customerId", customerId);
    query.setParameter("ratingSummaryId", ratingSummaryId);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    ReviewDetail reviewDetail = null;

    try {
        reviewDetail = (ReviewDetail) query.getSingleResult();
    } catch (NoResultException e) {
        // ignore
    }

    return reviewDetail;
}
项目:blcdemo    文件:StateDaoImpl.java   
@SuppressWarnings("unchecked")
public List<State> findStates(String countryAbbreviation) {
    Query query = em.createNamedQuery("BC_FIND_STATES_BY_COUNTRY_ABBREVIATION");
    query.setParameter("countryAbbreviation", countryAbbreviation);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    return query.getResultList();
}
项目:metaworks_framework    文件:URlHandlerDaoImpl.java   
@Override
public URLHandler findURLHandlerByURI(String uri) {
    TypedQuery<URLHandler> query = em.createNamedQuery("BC_READ_OUTGOING_URL", URLHandler.class);
    query.setParameter("incomingURL", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    List<URLHandler> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    } else {
        return null;
    }
}
项目:SparkCore    文件:CategoryDaoImpl.java   
@Override
public List<Category> readAllSubCategories(Category category) {
    TypedQuery<Category> query = em.createNamedQuery("BC_READ_ALL_SUBCATEGORIES", Category.class);
    query.setParameter("parentCategoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, category.getId()));
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");

    return query.getResultList();
}
项目:blcdemo    文件:URlHandlerDaoImpl.java   
@Override
public List<URLHandler> findAllURLHandlers() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<URLHandler> criteria = builder.createQuery(URLHandler.class);
    Root<URLHandlerImpl> handler = criteria.from(URLHandlerImpl.class);
    criteria.select(handler);
    TypedQuery<URLHandler> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return new ArrayList<URLHandler>();
    }
}
项目:blcdemo    文件:URlHandlerDaoImpl.java   
@Override
public URLHandler findURLHandlerByURI(String uri) {
    TypedQuery<URLHandler> query = em.createNamedQuery("BC_READ_OUTGOING_URL", URLHandler.class);
    query.setParameter("incomingURL", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    List<URLHandler> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    } else {
        return null;
    }
}
项目:metaworks_framework    文件:AdminPermissionDaoImpl.java   
public boolean isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName) {
    //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface
    //try the passed in ceiling first, but also try an interfaces implemented
    List<String> testClasses = new ArrayList<String>();
    testClasses.add(ceilingEntityFullyQualifiedName);
    try {
        for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) {
            testClasses.add(((Class<?>) interfaze).getName());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (String testClass : testClasses) {
        Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_FOR_USER_BY_TYPE_AND_CEILING_ENTITY");
        query.setParameter("adminUser", adminUser);
        query.setParameter("type", permissionType.getType());
        query.setParameter("ceilingEntity", testClass);
        query.setHint(QueryHints.HINT_CACHEABLE, true);

        Long count = (Long) query.getSingleResult();
        if (count > 0) {
            return true;
        }
    }
    return false;
}
项目:blcdemo    文件:SearchFacetDaoImpl.java   
@Override
public <T> List<T> readDistinctValuesForField(String fieldName, Class<T> fieldValueClass) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<T> criteria = builder.createQuery(fieldValueClass);

    Root<ProductImpl> product = criteria.from(ProductImpl.class);
    Path<Sku> sku = product.get("defaultSku");

    Path<?> pathToUse;
    if (fieldName.contains("defaultSku.")) {
        pathToUse = sku;
        fieldName = fieldName.substring("defaultSku.".length());
    } else if (fieldName.contains("productAttributes.")) {
        pathToUse = product.join("productAttributes");

        fieldName = fieldName.substring("productAttributes.".length());
        criteria.where(builder.equal(
            builder.lower(pathToUse.get("name").as(String.class)), fieldName.toLowerCase()));

        fieldName = "value";
    } else if (fieldName.contains("product.")) {
        pathToUse = product;
        fieldName = fieldName.substring("product.".length());
    } else {
        throw new IllegalArgumentException("Invalid facet fieldName specified: " + fieldName);
    }

    criteria.where(pathToUse.get(fieldName).as(fieldValueClass).isNotNull());
    criteria.distinct(true).select(pathToUse.get(fieldName).as(fieldValueClass));

    TypedQuery<T> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);

    return query.getResultList();
}
项目:SparkCore    文件:CategoryDaoImpl.java   
@Override
public List<Category> readActiveSubCategoriesByCategory(Category category, int limit, int offset) {
    TypedQuery<Category> query = em.createNamedQuery("BC_READ_ACTIVE_SUBCATEGORIES_BY_CATEGORY", Category.class);
    query.setParameter("parentCategoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, category.getId()));
    query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    query.setFirstResult(offset);
    query.setMaxResults(limit);

    return query.getResultList();
}
项目:blcdemo    文件:PageDaoImpl.java   
@Override
public List<PageField> readPageFieldsByPageId(Long pageId) {
    CriteriaBuilder builder = em.getCriteriaBuilder();

    CriteriaQuery<PageField> criteria = builder.createQuery(PageField.class);
    Root<PageFieldImpl> pageField = criteria.from(PageFieldImpl.class);
    criteria.select(pageField);

    Path<Object> path = pageField.get("page").get("id");
    criteria.where(builder.equal(pageField.get("page").get("id"), pageId));

    TypedQuery<PageField> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    return query.getResultList();
}
项目:SparkCore    文件:CategoryDaoImpl.java   
@Override
public List<Category> readAllCategories() {
    TypedQuery<Category> query = em.createNamedQuery("BC_READ_ALL_CATEGORIES", Category.class);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    return query.getResultList();
}
项目:metaworks_framework    文件:ModuleConfigurationDaoImpl.java   
@SuppressWarnings("unchecked")
@Override
public List<ModuleConfiguration> readAllByType(ModuleConfigurationType type) {
    Query query = em.createNamedQuery("BC_READ_MODULE_CONFIG_BY_TYPE");
    query.setParameter("configType", type.getType());
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "blConfigurationModuleElements");
    return query.getResultList();
}