List of usage examples for javax.persistence TypedQuery setHint
TypedQuery<X> setHint(String hintName, Object value);
From source file:org.broadleafcommerce.openadmin.server.security.dao.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);// w ww . ja va 2 s . co m 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); } }
From source file:org.broadleafcommerce.profile.core.dao.CustomerDaoImpl.java
@Override public List<Customer> readCustomersByUsername(String username, Boolean cacheable) { TypedQuery<Customer> query = em.createNamedQuery("BC_READ_CUSTOMER_BY_USER_NAME", Customer.class); query.setParameter("username", username); query.setHint(QueryHints.HINT_CACHEABLE, cacheable); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order"); return query.getResultList(); }
From source file:org.broadleafcommerce.profile.core.dao.CustomerDaoImpl.java
@Override public List<Customer> readCustomersByEmail(String emailAddress) { TypedQuery<Customer> query = em.createNamedQuery("BC_READ_CUSTOMER_BY_EMAIL", Customer.class); query.setParameter("email", emailAddress); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByIds(List<Long> productIds) { if (productIds == null || productIds.size() == 0) { return null; }/*w w w . j a v a 2 s. co m*/ if (productIds.size() > 100) { logger.warn("Not recommended to use the readProductsByIds method for long lists of productIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "product ids was (" + productIds.size() + ") in length."); } // Set up the criteria query that specifies we want to return Products CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Product> criteria = builder.createQuery(Product.class); Root<ProductImpl> product = criteria.from(ProductImpl.class); FetchParent fetchParent = product.fetch("defaultSku", JoinType.LEFT); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { fetchParent.fetch("skuMedia", JoinType.LEFT); } criteria.select(product); // We only want results that match the product IDs criteria.where(product.get("id").as(Long.class).in(sandBoxHelper.mergeCloneIds(em, ProductImpl.class, productIds.toArray(new Long[productIds.size()])))); if (!dialectHelper.isOracle() && !dialectHelper.isSqlServer()) { criteria.distinct(true); } TypedQuery<Product> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
protected List<Product> readActiveProductsByCategoryInternal(Long categoryId, Date currentDate) { TypedQuery<Product> query = em.createNamedQuery("BC_READ_ACTIVE_PRODUCTS_BY_CATEGORY", Product.class); query.setParameter("categoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, categoryId)); query.setParameter("currentDate", currentDate); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
public List<Product> readActiveProductsByCategoryInternal(Long categoryId, Date currentDate, int limit, int offset) { TypedQuery<Product> query = em.createNamedQuery("BC_READ_ACTIVE_PRODUCTS_BY_CATEGORY", Product.class); query.setParameter("categoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, categoryId)); query.setParameter("currentDate", currentDate); query.setFirstResult(offset);/*from ww w .j av a 2s . c o m*/ query.setMaxResults(limit); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByCategory(Long categoryId) { TypedQuery<Product> query = em.createNamedQuery("BC_READ_PRODUCTS_BY_CATEGORY", Product.class); query.setParameter("categoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, categoryId)); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<Product> readProductsByCategory(Long categoryId, int limit, int offset) { TypedQuery<Product> query = em.createNamedQuery("BC_READ_PRODUCTS_BY_CATEGORY", Product.class); query.setParameter("categoryId", sandBoxHelper.mergeCloneIds(em, CategoryImpl.class, categoryId)); query.setFirstResult(offset);/*from w w w.ja va 2 s . c o m*/ query.setMaxResults(limit); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.sparkcommerce.core.catalog.dao.ProductDaoImpl.java
@Override public List<ProductBundle> readAutomaticProductBundles() { Date currentDate = getCurrentDateAfterFactoringInDateResolution(); TypedQuery<ProductBundle> query = em.createNamedQuery("BC_READ_AUTOMATIC_PRODUCT_BUNDLES", ProductBundle.class); query.setParameter("currentDate", currentDate); query.setParameter("autoBundle", Boolean.TRUE); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
From source file:org.springframework.data.jpa.repository.support.SimpleJpaRepository.java
private TypedQuery<T> applyRepositoryMethodMetadata(TypedQuery<T> query) { if (crudMethodMetadata == null) { return query; }//www . jav a 2s .c o m LockModeType type = crudMethodMetadata.getLockModeType(); TypedQuery<T> toReturn = type == null ? query : query.setLockMode(type); for (Entry<String, Object> hint : crudMethodMetadata.getQueryHints().entrySet()) { query.setHint(hint.getKey(), hint.getValue()); } return toReturn; }