@Override public List<Order> getOrderList() { return new ArrayList<>(criteriaQuery.getOrderList()); }
List<Order> orderings = criteriaQuery.getOrderList();
/** * {@inheritDoc} */ @Override protected void addOrderBy(TranslationContext criteria, String propertyPath, boolean sortAscending) { List<Order> orderList = criteria.query.getOrderList(); if (orderList == null) { orderList = new ArrayList<Order>(); } if (propertyPath.contains(".")) { String propertyPathStart = StringUtils.substringBefore( propertyPath, "." ); String propertyPathEnd = StringUtils.substringAfter( propertyPath, "." ); if (sortAscending) { orderList.add(criteria.builder.asc(criteria.root.get(propertyPathStart).get(propertyPathEnd))); } else { orderList.add(criteria.builder.desc(criteria.root.get(propertyPathStart).get(propertyPathEnd))); } } else { if (sortAscending) { orderList.add(criteria.builder.asc(criteria.root.get(propertyPath))); } else { orderList.add(criteria.builder.desc(criteria.root.get(propertyPath))); } } criteria.query.orderBy(orderList); }
@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); } }
if (query.getOrderList() == null || query.getOrderList().isEmpty()) { EntityType<T> entityType = from.getModel(); try {
/** 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; } }
/** * if query orders are empty, then apply default ascending ordering * by root id attribute to prevent paging inconsistencies * * @param query * @param from * @param cb */ protected void mayBeAddDefaultOrderBy(CriteriaQuery<?> query, From<?,?> from, CriteriaBuilder cb) { if (query.getOrderList() == null || query.getOrderList().isEmpty()) { EntityType<?> fromEntityType = entityType; try { java.lang.reflect.Field sortField = getSortAnnotation(fromEntityType.getBindableJavaType()); if (sortField == null) query.orderBy(cb.asc(from.get(fromEntityType.getId(fromEntityType.getIdType().getJavaType()).getName()))); else { GraphQLDefaultOrderBy order = sortField.getAnnotation(GraphQLDefaultOrderBy.class); if (order.asc()) { query.orderBy(cb.asc(from.get(sortField.getName()))); } else { query.orderBy(cb.desc(from.get(sortField.getName()))); } } } catch (Exception ex) { //log.warn("In" + this.getClass().getName(), ex); } } }
/** * Copy Criteria without Selection * * @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()); }
for(Order order : criteriaQuery.getOrderList()) { VExpression<?> x = ((OrderImpl)order).getExpression(); Expr e = x.accept(orderCompiler);
for(Order order : criteriaQuery.getOrderList()) { VExpression<?> x = ((OrderImpl)order).getExpression(); Expr e = x.accept(orderCompiler);