List of usage examples for javax.persistence.criteria CriteriaQuery getRestriction
Predicate getRestriction();
From source file:org.jboss.pressgang.ccms.filter.utils.JPAUtils.java
/** * Copy Criteria without Selection/*from w ww .jav a 2 s . c o m*/ * * @param from source Criteria * @param to destination Criteria */ public static void copyCriteriaNoSelection(CriteriaQuery<?> from, CriteriaQuery<?> to) { // Copy Roots for (Root<?> root : from.getRoots()) { Root<?> dest = to.from(root.getJavaType()); dest.alias(getOrCreateAlias(root)); copyJoins(root, dest); } if (from.getGroupList() != null) to.groupBy(from.getGroupList()); to.distinct(from.isDistinct()); if (from.getGroupRestriction() != null) to.having(from.getGroupRestriction()); if (from.getRestriction() != null) to.where(from.getRestriction()); if (from.getOrderList() != null) to.orderBy(from.getOrderList()); }
From source file:ru.savvy.jpafilterbuilder.FilterCriteriaBuilder.java
/** * @param rootPath//from ww w . ja v a2 s .c o m * @param query */ private void applyFilters(Root<T> rootPath, CriteriaQuery<?> query) { List<Predicate> predicates = new ArrayList<>(); for (FieldFilter filter : filters) { Path<?> path; if (filter.getOptions().contains(FieldFilter.Option.OR_NULL)) { path = getCompoundJoinedPath(rootPath, filter.getField(), true); } else { path = getCompoundJoinedPath(rootPath, filter.getField(), false); } Predicate p = pb.getPredicate(path, filter); if (p != null) { predicates.add(p); } } // this does not work for Hibernate!!! if (query.getRestriction() != null) { predicates.add(query.getRestriction()); } if (options.contains(Option.OR_FILTERS)) { query.where(cb.or(predicates.toArray(new Predicate[0]))); } else { query.where(cb.and(predicates.toArray(new Predicate[0]))); } }