public static <T> FactoryExpression<T> wrap(FactoryExpression<T> expr) { for (Expression<?> arg : expr.getArgs()) { if (arg instanceof ProjectionRole) { arg = ((ProjectionRole) arg).getProjection(); } if (arg instanceof FactoryExpression<?>) { return new FactoryExpressionAdapter<T>(expr); } } return expr; }
public static PathInits getFor(PathMetadata metadata, PathInits root) { if (metadata.isRoot()) { return root; } else if (metadata.getParent().getMetadata().isRoot()) { return DIRECT; } else { return DEFAULT; } }
/** * Create a Bean populating projection for the given type and expressions * * @param <T> type of projection * @param type type of the projection * @param exprs arguments for the projection * @return factory expression */ public static <T> QBean<T> bean(Path<? extends T> type, Expression<?>... exprs) { return new QBean<T>(type.getType(), exprs); }
@SuppressWarnings("rawtypes") private static <T> Path<T> replaceParent(Path<T> path, Path<?> parent) { PathMetadata metadata = new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()); if (path instanceof CollectionExpression) { CollectionExpression<?,?> col = (CollectionExpression<?,?>) path; return (Path<T>) Expressions.listPath(col.getParameter(0), SimplePath.class, metadata); } else { return ExpressionUtils.path(path.getType(), metadata); } }
@Override public final boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof Path<?>) { return ((Path<?>) o).getMetadata().equals(metadata); } else { return false; } }
private static Expression<?> unwrap(Expression<?> expr) { expr = ExpressionUtils.extract(expr); if (expr instanceof Operation && ((Operation<?>) expr).getOperator() == Ops.ALIAS) { return ((Operation<?>) expr).getArg(0); } return expr; }
/** * Create a {@code left != constant} expression * * @param <D> type of expression * @param left lhs of expression * @param constant rhs of expression * @return left != constant */ public static <D> Predicate neConst(Expression<D> left, D constant) { return ne(left, ConstantImpl.create(constant)); }
/** * Create a new Template expression * * @param cl type of expression * @param template template * @param args template parameters * @return template expression */ public static <T> TemplateExpression<T> template(Class<? extends T> cl, String template, List<?> args) { return template(cl, TemplateFactory.DEFAULT.create(template), args); }
/** * Create a new Template expression * * @param template template * @param args template parameters * @return template expression */ public static PredicateTemplate predicateTemplate(String template, List<?> args) { return predicateTemplate(TemplateFactory.DEFAULT.create(template), args); }
/** * Create a new MappingProjection instance * * @param type * @param args */ @SuppressWarnings("unchecked") public MappingProjection(Class<? super T> type, Expression<?>... args) { super((Class) type); qTuple = new QTuple(ExpressionUtils.distinctList(args)); }
/** * Create a field access based Bean populating projection for the given type and expressions * * @param <T> type of projection * @param type type of the projection * @param exprs arguments for the projection * @return factory expression */ public static <T> QBean<T> fields(Path<? extends T> type, Expression<?>... exprs) { return new QBean<T>(type.getType(), true, exprs); }