/** * Create a BooleanBuilder with the given initial value * * @param initial initial value */ public BooleanBuilder(Predicate initial) { predicate = (Predicate) ExpressionUtils.extract(initial); }
/** * Create a new JTSGeometryExpression * * @param expr Expression of type Geometry * @return new JTSGeometryExpression */ public static <T extends Geometry> JTSGeometryExpression<T> asJTSGeometry( Expression<T> expr) { Expression<T> underlyingMixin = ExpressionUtils.extract(expr); return new JTSGeometryExpression<T>(underlyingMixin) { private static final long serialVersionUID = -6714044005570420009L; @Override public <R, C> R accept(Visitor<R, C> v, C context) { return this.mixin.accept(v, context); } }; }
@Override public Object convert(final List<?> args) { final Object arg = args.get(index); if (arg instanceof Expression) { return ExpressionUtils.extract((Expression<?>) arg); } else { return arg; } }
/** * Create the intersection of the given arguments * * @param left lhs of expression * @param right rhs of expression * @return left and right */ public static Predicate and(Predicate left, Predicate right) { left = (Predicate) extract(left); right = (Predicate) extract(right); if (left == null) { return right; } else if (right == null) { return left; } else { return predicate(Ops.AND, left, right); } }
/** * Create a {@code left or right} expression * * @param left lhs of expression * @param right rhs of expression * @return left or right */ public static Predicate or(Predicate left, Predicate right) { left = (Predicate) extract(left); right = (Predicate) extract(right); if (left == null) { return right; } else if (right == null) { return left; } else { return predicate(Ops.OR, left, right); } }
@Override public void addHaving(Predicate e) { if (e == null) { return; } e = (Predicate) ExpressionUtils.extract(e); if (e != null) { // having elements can't be validated, since they can refer to projection elements // that are declared later having = and(having, e); } }
private static Expression<?> asExpression(Object arg) { if (arg instanceof Expression) { return ExpressionUtils.extract((Expression<?>) arg); } else { return Expressions.constant(arg); } }
/** * Create a {@code this && right} expression * * <p>Returns an intersection of this and the given expression</p> * * @param right right hand side of the union * @return {@code this && right} */ public BooleanExpression and(@Nullable Predicate right) { right = (Predicate) ExpressionUtils.extract(right); if (right != null) { return Expressions.booleanOperation(Ops.AND, mixin, right); } else { return this; } }
/** * Create a {@code this || right} expression * * <p>Returns a union of this and the given expression</p> * * @param right right hand side of the union * @return this || right */ public BooleanExpression or(@Nullable Predicate right) { right = (Predicate) ExpressionUtils.extract(right); if (right != null) { return Expressions.booleanOperation(Ops.OR, mixin, right); } else { return this; } }
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; }
public Query toQuery(Expression<?> expr, QueryMetadata metadata) { if (expr instanceof Operation<?>) { return toQuery((Operation<?>) expr, metadata); } else { return toQuery(ExpressionUtils.extract(expr), metadata); } }
public Query toQuery(Expression<?> expr, QueryMetadata metadata) { if (expr instanceof Operation<?>) { return toQuery((Operation<?>) expr, metadata); } else { return toQuery(ExpressionUtils.extract(expr), metadata); } }
public Query toQuery(Expression<?> expr, QueryMetadata metadata) { if (expr instanceof Operation<?>) { return toQuery((Operation<?>) expr, metadata); } else { return toQuery(ExpressionUtils.extract(expr), metadata); } }
@Override public void addWhere(Predicate e) { if (e == null) { return; } e = (Predicate) ExpressionUtils.extract(e); if (e != null) { validate(e); where = and(where, e); } }
/** * Create a new GeometryExpression * * @param expr Expression of type Geometry * @return new GeometryExpression */ public static <T extends Geometry> GeometryExpression<T> asGeometry(Expression<T> expr) { Expression<T> underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new GeometryPath<T>((PathImpl<T>) underlyingMixin); } else if (underlyingMixin instanceof OperationImpl) { return new GeometryOperation<T>((OperationImpl<T>) underlyingMixin); } else { return new GeometryExpression<T>(underlyingMixin) { private static final long serialVersionUID = -6714044005570420009L; @Override public <R, C> R accept(Visitor<R, C> v, C context) { return this.mixin.accept(v, context); } }; } }
@Override protected Predicate convert(Predicate predicate, Role role) { predicate = (Predicate) ExpressionUtils.extract(predicate); if (predicate != null) { Context context = new Context(); Predicate transformed = (Predicate) predicate.accept(collectionAnyVisitor, context); for (int i = 0; i < context.paths.size(); i++) { leftJoin( (Path) context.paths.get(i).getMetadata().getParent(), (Path) context.replacements.get(i)); on(ANY); } return transformed; } else { return predicate; } } }
/** * Create a new NumberExpression * * @param expr Expression of type Number * @return new NumberExpression */ public static <T extends Number & Comparable<?>> NumberExpression<T> asNumber(Expression<T> expr) { Expression<T> underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new NumberPath<T>((PathImpl<T>) underlyingMixin); } else if (underlyingMixin instanceof OperationImpl) { return new NumberOperation<T>((OperationImpl<T>) underlyingMixin); } else if (underlyingMixin instanceof TemplateExpressionImpl) { return new NumberTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin); } else { return new NumberExpression<T>(underlyingMixin) { private static final long serialVersionUID = -8712299418891960222L; @Override public <R, C> R accept(Visitor<R, C> v, C context) { return this.mixin.accept(v, context); } }; } }
/** * Create a new BooleanExpression * * @param expr Expression of type Boolean * @return new BooleanExpression */ public static BooleanExpression asBoolean(Expression<Boolean> expr) { Expression<Boolean> underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new BooleanPath((PathImpl<Boolean>) underlyingMixin); } else if (underlyingMixin instanceof PredicateOperation) { return new BooleanOperation((PredicateOperation) underlyingMixin); } else if (underlyingMixin instanceof PredicateTemplate) { return new BooleanTemplate((PredicateTemplate) underlyingMixin); } else { return new BooleanExpression(underlyingMixin) { private static final long serialVersionUID = -8712299418891960222L; @Override public <R, C> R accept(Visitor<R, C> v, C context) { return this.mixin.accept(v, context); } }; } }
/** * Create a new EnumExpression * * @param expr Expression of type Enum * @return new EnumExpression */ public static <T extends Enum<T>> EnumExpression<T> asEnum(Expression<T> expr) { Expression<T> underlyingMixin = ExpressionUtils.extract(expr); if (underlyingMixin instanceof PathImpl) { return new EnumPath<T>((PathImpl<T>) underlyingMixin); } else if (underlyingMixin instanceof OperationImpl) { return new EnumOperation<T>((OperationImpl<T>) underlyingMixin); } else if (underlyingMixin instanceof TemplateExpressionImpl) { return new EnumTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin); } else { return new EnumExpression<T>(underlyingMixin) { private static final long serialVersionUID = 949681836002045152L; @Override public <R, C> R accept(Visitor<R, C> v, C context) { return this.mixin.accept(v, context); } }; } }
@Test public void and_empty() { BooleanBuilder builder = new BooleanBuilder(); builder.and(new BooleanBuilder()); assertNull(ExpressionUtils.extract(builder)); }