@Override protected <T,R> Expression getOrderByExpression(CriteriaQuery<R> query, Class<T> queryType, String orderByListId) { List<Selection<?>> selections = query.getSelection().getCompoundSelectionItems(); Selection orderBySelection = null; if( orderByListId.equals(QueryParameterIdentifiers.TASK_ID_LIST) ) { orderBySelection = selections.get(0); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_NAME_LIST) ) { orderBySelection = selections.get(1); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_STATUS_LIST) ) { orderBySelection = selections.get(4); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_BY_LIST) ) { orderBySelection = selections.get(8); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_ON_LIST) ) { orderBySelection = selections.get(9); } else if( orderByListId.equals(QueryParameterIdentifiers.PROCESS_INSTANCE_ID_LIST) ) { orderBySelection = selections.get(14); } return (Expression<?>) orderBySelection; }
Selection<S> select = criteriaQuery.getSelection();
public static <T> void copyCriteria(CriteriaQuery<T> from, CriteriaQuery<T> to) { copyCriteriaNoSelection(from, to); to.select(from.getSelection()); }
@Override protected boolean isCompoundSelection() { return query.getSelection().isCompoundSelection(); }
@Override protected <T,R> Expression getOrderByExpression(CriteriaQuery<R> query, Class<T> queryType, String orderByListId) { List<Selection<?>> selections = query.getSelection().getCompoundSelectionItems(); Selection orderBySelection = null; if( orderByListId.equals(QueryParameterIdentifiers.TASK_ID_LIST) ) { orderBySelection = selections.get(0); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_NAME_LIST) ) { orderBySelection = selections.get(1); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_STATUS_LIST) ) { orderBySelection = selections.get(4); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_BY_LIST) ) { orderBySelection = selections.get(8); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_ON_LIST) ) { orderBySelection = selections.get(9); } else if( orderByListId.equals(QueryParameterIdentifiers.PROCESS_INSTANCE_ID_LIST) ) { orderBySelection = selections.get(14); } return (Expression<?>) orderBySelection; }
@Override public void addSelection(Expression<?> expression, String name) { Selection<?> selection = criteriaQuery.getSelection(); List<Selection<?>> newSelection = new ArrayList<>(); if (selection != null) { if (selection.isCompoundSelection()) { newSelection.addAll(selection.getCompoundSelectionItems()); } else { newSelection.add(selection); } } newSelection.add(expression); criteriaQuery.multiselect(newSelection); }
@Override @SuppressWarnings({ "rawtypes" }) public long getTotalRowCount() { Selection<T> selection = query.getSelection(); List<Order> orderList = query.getOrderList(); try { CriteriaBuilder builder = em.getCriteriaBuilder(); Expression<Long> countExpr; Set<Root<?>> roots = query.getRoots(); if (roots.size() != 1) { throw new IllegalStateException("cannot compute totalRowCount in case of multiple query roots"); } if (!query.getGroupList().isEmpty()) { throw new IllegalStateException("cannot compute totalRowCount for grouped queries"); } // transform query to a count query Root root = roots.iterator().next(); countExpr = builder.count(root); query.multiselect(countExpr); query.orderBy(new ArrayList<Order>()); TypedQuery countQuery = em.createQuery(query); return (Long) countQuery.getSingleResult(); } finally { // transform count query back to regular query query.multiselect(selection); query.orderBy(orderList); } }
@Override public <S, T, ID extends Serializable> Specification<S> augment(Specification<S> spec, Class<S> domainClass, JpaEntityInformation<T, ID> entityInformation) { LOG.debug("QueryAugmentor.augment"); return (root, query, criteriaBuilder) -> { Root<JpaFeedOpsAclEntry> fromAcl = query.from(JpaFeedOpsAclEntry.class); query.distinct(true); if (query.getSelection() == null) { query.select((Selection) root); } Path<Object> feedId = getFeedId(entityInformation, root); javax.persistence.criteria.Predicate rootFeedIdEqualToAclFeedId = criteriaBuilder.equal(feedId, fromAcl.get("feedId")); RoleSetExposingSecurityExpressionRoot userCxt = getUserContext(); javax.persistence.criteria.Predicate aclPrincipalInGroups = fromAcl.get("principalName").in(userCxt.getGroups()); javax.persistence.criteria.Predicate aclPrincipalTypeIsGroup = criteriaBuilder.equal(fromAcl.get("principalType"), FeedOpsAclEntry.PrincipalType.GROUP); javax.persistence.criteria.Predicate acePrincipalGroupMatch = criteriaBuilder.and(aclPrincipalInGroups, aclPrincipalTypeIsGroup); javax.persistence.criteria.Predicate aclPrincipalEqUser = criteriaBuilder.equal(fromAcl.get("principalName"), userCxt.getName()); javax.persistence.criteria.Predicate aclPrincipalTypeIsUser = criteriaBuilder.equal(fromAcl.get("principalType"), FeedOpsAclEntry.PrincipalType.USER); javax.persistence.criteria.Predicate acePrincipalUserMatch = criteriaBuilder.and(aclPrincipalEqUser, aclPrincipalTypeIsUser); javax.persistence.criteria.Predicate acePrincipalMatch = criteriaBuilder.or(acePrincipalGroupMatch, acePrincipalUserMatch); javax.persistence.criteria.Predicate feedIdEqualsAndPrincipalMatch = criteriaBuilder.and(rootFeedIdEqualToAclFeedId, acePrincipalMatch); if (spec != null) { javax.persistence.criteria.Predicate predicate = spec.toPredicate(root, query, criteriaBuilder); return criteriaBuilder.and(predicate, feedIdEqualsAndPrincipalMatch); } else { return feedIdEqualsAndPrincipalMatch; } }; }
/** Use ES here, it would be more efficient. */ public void search() { // criteriaBuilder.equal() CriteriaQuery<Long> criteriaQuery = null; criteriaQuery.getParameters(); criteriaQuery.getGroupList(); criteriaQuery.getOrderList(); criteriaQuery.getGroupRestriction(); criteriaQuery.getRestriction(); criteriaQuery.getSelection(); final Predicate predicate = null; } }
renderedCriteriaQuery.getQueryString(), criteriaQuery.getResultType(), criteriaQuery.getSelection(), new HibernateEntityManagerImplementor.Options() { public List<ValueHandlerFactory.ValueHandler> getValueHandlers() {
Selection<X> selection = criteriaQuery.getSelection();
Selection<X> selection = criteriaQuery.getSelection();