@Override public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { return explicitPath.as(Long.class).in(directValues); } })
@Override public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) { return explicitPath.as(String.class).in(directValues); } })
@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(); }
@Override public List<Field> readFieldsByEntityType(FieldEntity entityType) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Field> criteria = builder.createQuery(Field.class); Root<FieldImpl> root = criteria.from(FieldImpl.class); criteria.select(root); criteria.where( root.get("entityType").as(String.class).in(entityType.getAllLookupTypes()) ); TypedQuery<Field> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
@Override public List<Customer> readCustomersByIds(List<Long> ids){ if (ids == null || ids.size() == 0) { return null; } if (ids.size() > 100) { LOG.warn("Not recommended to use the readCustomersByIds method for long lists of customerIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "customer ids was (" + ids.size() + ") in length."); } CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class); Root<CustomerImpl> customer = criteria.from(CustomerImpl.class); criteria.select(customer); // We only want results that match the customer IDs criteria.where(customer.get("id").as(Long.class).in(ids)); TypedQuery<Customer> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order"); return query.getResultList(); }
@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(); }
@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(); }
@Override public List<Order> readBatchOrders(int start, int pageSize, List<OrderStatus> statuses) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Order> criteria = builder.createQuery(Order.class); Root<OrderImpl> order = criteria.from(OrderImpl.class); criteria.select(order); if (CollectionUtils.isNotEmpty(statuses)) { // We only want results that match the orders with the correct status ArrayList<String> statusStrings = new ArrayList<String>(); for (OrderStatus status : statuses) { statusStrings.add(status.getType()); } criteria.where(order.get("status").as(String.class).in(statusStrings)); } TypedQuery<Order> query = em.createQuery(criteria); query.setFirstResult(start); query.setMaxResults(pageSize); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order"); return query.getResultList(); }
@Override public List<Sku> readSkusByIds(List<Long> skuIds) { if (skuIds == null || skuIds.size() == 0) { return null; } if (skuIds.size() > 100) { logger.warn("Not recommended to use the readSkusByIds method for long lists of skuIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "sku ids was (" + skuIds.size() + ") in length."); } // Set up the criteria query that specifies we want to return Products CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Sku> criteria = builder.createQuery(Sku.class); Root<SkuImpl> sku = criteria.from(SkuImpl.class); criteria.select(sku); // We only want results that match the sku IDs criteria.where(sku.get("id").as(Long.class).in( sandBoxHelper.mergeCloneIds(SkuImpl.class, skuIds.toArray(new Long[skuIds.size()])))); TypedQuery<Sku> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
@Override public List<OrderItem> readBatchOrderItems(int start, int count, List<OrderStatus> statuses) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class); Root<OrderImpl> order = criteria.from(OrderImpl.class); Join<Order, OrderItem> orderItems = order.join("orderItems"); criteria.select(orderItems); List<Predicate> restrictions = new ArrayList<>(); criteria.where(restrictions.toArray(new Predicate[restrictions.size()])); if (CollectionUtils.isNotEmpty(statuses)) { // We only want results that match the orders with the correct status ArrayList<String> statusStrings = new ArrayList<String>(); for (OrderStatus status : statuses) { statusStrings.add(status.getType()); } criteria.where(order.get("status").as(String.class).in(statusStrings)); } TypedQuery<OrderItem> query = em.createQuery(criteria); query.setFirstResult(start); query.setMaxResults(count); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order"); return query.getResultList(); } }
@Override public List<Product> readProductsByIds(List<Long> productIds) { if (productIds == null || productIds.size() == 0) { return null; } 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); product.fetch("defaultSku", 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(ProductImpl.class, productIds.toArray(new Long[productIds.size()])))); TypedQuery<Product> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog"); return query.getResultList(); }
public List<Site> retrieveSitesByPotentialIdentifiers(String... potentialIdentifiers) { 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(site.get("siteIdentifierValue").as(String.class).in(potentialIdentifiers), 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); query.setHint(QueryHints.HINT_CACHE_REGION, "blSiteElementsQuery"); return query.getResultList(); }
@Override public List<SearchFacet> readAllSearchFacets(FieldEntity entityType) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class); Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class); criteria.select(facet); Path<Character> archived = facet.get("archiveStatus").get("archived"); criteria.where( builder.equal(facet.get("showOnSearch").as(Boolean.class), true), builder.or(builder.isNull(archived.as(String.class)), builder.notEqual(archived.as(Character.class), 'Y')), facet.join("fieldType") .join("indexField") .join("field") .get("entityType") .as(String.class) .in(entityType.getAllLookupTypes()) ); TypedQuery<SearchFacet> query = em.createQuery(criteria); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search"); return query.getResultList(); }
assert parameters.get(0) != null : "Null 1rst parameter for criteria [" + criteria.toString() + "]"; assert parameters.get(parameters.size()-1) != null : "Null last parameter for criteria [" + criteria.toString() + "]"; predicate = entityField.in(parameters);
private static List<Long> filterResourceIdsByLastUpdated(EntityManager theEntityManager, final DateRangeParam theLastUpdated, Collection<Long> thePids) { if (thePids.isEmpty()) { return Collections.emptyList(); } CriteriaBuilder builder = theEntityManager.getCriteriaBuilder(); CriteriaQuery<Long> cq = builder.createQuery(Long.class); Root<ResourceTable> from = cq.from(ResourceTable.class); cq.select(from.get("myId").as(Long.class)); List<Predicate> lastUpdatedPredicates = createLastUpdatedPredicates(theLastUpdated, builder, from); lastUpdatedPredicates.add(from.get("myId").as(Long.class).in(thePids)); cq.where(SearchBuilder.toArray(lastUpdatedPredicates)); TypedQuery<Long> query = theEntityManager.createQuery(cq); return query.getResultList(); }
private void addPredicateLanguage(List<List<? extends IQueryParameterType>> theList) { for (List<? extends IQueryParameterType> nextList : theList) { Set<String> values = new HashSet<>(); for (IQueryParameterType next : nextList) { if (next instanceof StringParam) { String nextValue = ((StringParam) next).getValue(); if (isBlank(nextValue)) { continue; } values.add(nextValue); } else { throw new InternalErrorException("Lanugage parameter must be of type " + StringParam.class.getCanonicalName() + " - Got " + next.getClass().getCanonicalName()); } } if (values.isEmpty()) { continue; } Predicate predicate = myResourceTableRoot.get("myLanguage").as(String.class).in(values); myPredicates.add(predicate); } }
Predicate nextPredicate = myResourceTableRoot.get("myId").as(Long.class).in(orPids); myPredicates.add(nextPredicate); } else {
Predicate uriPredicate = join.get("myUri").as(String.class).in(toFind); Predicate hashAndUriPredicate = combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, join, uriPredicate); codePredicates.add(hashAndUriPredicate);
thePredicates.add(join.get("mySourcePath").as(String.class).in(param.getPathsSplit())); } else { if (myDontUseHashesForSearch) {