protected void applyPredicateToCriteria(AbstractQuery<?> query) { Predicate predicate = parsePredicate(junction); if (predicate != null) { query.where(predicate); } predicate = parsePredicate(having); if (predicate != null) { query.having(predicate); } if (query instanceof CriteriaQuery) { if (!CollectionUtils.isEmpty(orders)) { ((CriteriaQuery<?>) query).orderBy(orders); } } }
/** * {@inheritDoc} */ public boolean visit(JpqlWhere node, CriteriaHolder query) { AbstractQuery<?> criteriaQuery = query.getCurrentQuery(); Predicate restriction = criteriaQuery.getRestriction(); node.jjtGetChild(0).visit(this, query); if (query.isValueOfType(Predicate.class)) { if (restriction == null) { criteriaQuery.where(query.<Predicate>getCurrentValue()); } else { criteriaQuery.where(restriction, query.<Predicate>getCurrentValue()); } } else { if (restriction == null) { criteriaQuery.where(query.<Expression<Boolean>>getCurrentValue()); } else { criteriaQuery.where(restriction, builder.isTrue(query.<Expression<Boolean>>getCurrentValue())); } } return false; }
/** * {@inheritDoc} */ public boolean visit(JpqlFromItem node, CriteriaHolder criteriaHolder) { AbstractQuery<?> query = criteriaHolder.getCurrentQuery(); String entityName = node.jjtGetChild(0).toString(); Alias alias = getAlias(node); Class<?> entityType = ManagedTypeFilter.forModel(metamodel).filter(entityName.trim()).getJavaType(); query.from(entityType).alias(alias.getName()); return false; }
private From<?, ?> getFrom(CommonAbstractCriteria query, Alias alias) { if (query instanceof CriteriaUpdate) { return ((CriteriaUpdate<?>)query).getRoot(); } else if (query instanceof CriteriaDelete) { return ((CriteriaUpdate<?>)query).getRoot(); } else { return getFrom((AbstractQuery<?>)query, alias); } }
private From<?, ?> getFrom(AbstractQuery<?> query, Alias alias) { for (Root<?> root: query.getRoots()) { From<?, ?> from = getFrom(root, alias); if (from != null) { return from; } } return null; }
private Set<Alias> getAliases(AbstractQuery<?> query) { Set<Alias> aliases = new HashSet<Alias>(); for (Root<?> root: query.getRoots()) { if (root.getAlias() != null) { aliases.add(new Alias(root.getAlias())); } } return aliases; }
public <R> AbstractQuery<R> getCurrentQuery() { if (subqueries.isEmpty()) { return (CriteriaQuery<R>)criteriaQuery; } return (Subquery<R>)subqueries.peek(); }
@Override public AbstractQuery<T> where(Expression<Boolean> restriction) { return null; }
@Override public AbstractQuery<T> where(Predicate... restrictions) { return null; }
@Override public AbstractQuery<T> groupBy(Expression<?>... grouping) { return null; }
@Override public AbstractQuery<T> groupBy(List<Expression<?>> grouping) { return null; }
@Override public AbstractQuery<T> having(Expression<Boolean> restriction) { return null; }
@Override public AbstractQuery<T> having(Predicate... restrictions) { return null; }
public JpaQuerySpecImpl(AbstractQuery<T> owner, CriteriaBuilderImpl criteriaBuilder) { this.owner = owner; this.criteriaBuilder = criteriaBuilder; this.isSubQuery = Subquery.class.isInstance( owner ); }