private <P extends Path<?>> P assertRoot(P p) { if (!p.getRoot().equals(p)) { throw new IllegalArgumentException(p + " is not a root path"); } return p; }
public PathMetadata(@Nullable Path<?> parent, Object element, PathType type) { this.parent = parent; this.element = element; this.pathType = type; this.root = parent != null ? parent.getRoot() : null; this.hashCode = 31 * element.hashCode() + pathType.name().hashCode(); }
/** * Wrap a Querydsl predicate into a Guava predicate * * @param predicate * @return */ public static <T> com.google.common.base.Predicate<T> wrap(Predicate predicate) { Path<?> path = (Path<?>)predicate.accept(PathExtractor.DEFAULT, null); if (path != null) { final Evaluator<Boolean> ev = createEvaluator(path.getRoot(), predicate); return new com.google.common.base.Predicate<T>() { @Override public boolean apply(T input) { return ev.evaluate(input); } }; } else { throw new IllegalArgumentException("No path in " + predicate); } }
/** * Wrap a Querydsl expression into a Guava function * * @param projection * @return */ public static <F,T> Function<F,T> wrap(Expression<T> projection) { Path<?> path = (Path<?>)projection.accept(PathExtractor.DEFAULT, null); if (path != null) { final Evaluator<T> ev = createEvaluator(path.getRoot(), projection); return new Function<F,T>() { @Override public T apply(F input) { return ev.evaluate(input); } }; } else { throw new IllegalArgumentException("No path in " + projection); } }
public static StringProperty string( Path<?> entityPath ) { return identifier(entityPath.getRoot().toString()).string( entityPath.getMetadata().getExpression().toString() ); }
public static NumberProperty number( Path<?> entityPath ) { return identifier(entityPath.getRoot().toString()).number( entityPath.getMetadata().getExpression().toString() ); }
public static Property property( Path<?> entityPath ) { return identifier(entityPath.getRoot().toString()).property( entityPath.getMetadata().getExpression().toString() ); }
@Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { Multimap<Expression<?>, Predicate> predicates = HashMultimap.<Expression<?>, Predicate>create(); List<JoinExpression> joins = metadata.getJoins(); for (int i = joins.size() - 1; i >= 0; i--) { JoinExpression join = joins.get(i); Path source = (Path)((Operation<?>)join.getTarget()).getArg(0); Path target = (Path)((Operation<?>)join.getTarget()).getArg(1); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { throw new NoResults(); } Path path = new PathImpl<String>(String.class, source, "$id"); predicates.put(source.getRoot(), ExpressionUtils.in(path, ids)); } Path source = (Path)((Operation)joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
public Object arg(com.mysema.query.types.Expression expression) { if (expression instanceof Constant) return ((Constant)expression).getConstant(); else if (expression instanceof ParamExpression) return param( ( (ParamExpression) expression ).getName() ); else if (expression instanceof Path) { Path path = (Path) expression; return identifier( path.getRoot()).string( path.getMetadata().getExpression().toString() ); } else throw new IllegalArgumentException("Unknown argument type:"+expression); } }, null ));