Search in sources :

Example 1 with OptionalOperators

use of org.immutables.criteria.expression.OptionalOperators in project immutables by immutables.

the class GeodeQueryVisitor method unaryOperator.

/**
 * Operator with single operator: {@code NOT}, {@code IS_PRESENT}
 */
private Oql unaryOperator(Call call) {
    final Operator op = call.operator();
    final List<Expression> args = call.arguments();
    Preconditions.checkArgument(args.size() == 1, "Size should be == 1 for unary operator %s but was %s", op, args.size());
    Expression arg0 = args.get(0);
    String path = arg0.accept(this).oql();
    if (op instanceof OptionalOperators) {
        // use IS_DEFINED / IS_UNDEFINED functions
        String expr;
        if (op == OptionalOperators.IS_PRESENT) {
            expr = String.format("is_defined(%s) AND %s != null", path, path);
        } else {
            expr = String.format("is_undefined(%s) OR %s = null", path, path);
        }
        return oql(expr);
    } else if (op == Operators.NOT) {
        return oql(String.format("NOT (%s)", path));
    } else if (op == IterableOperators.IS_EMPTY || op == StringOperators.TO_LOWER_CASE || op == StringOperators.TO_UPPER_CASE) {
        return oql(String.format("%s.%s()", path, toMethodName(op)));
    }
    throw new UnsupportedOperationException("Unknown unary operator " + call);
}
Also used : Operator(org.immutables.criteria.expression.Operator) Expression(org.immutables.criteria.expression.Expression) OptionalOperators(org.immutables.criteria.expression.OptionalOperators)

Aggregations

Expression (org.immutables.criteria.expression.Expression)1 Operator (org.immutables.criteria.expression.Operator)1 OptionalOperators (org.immutables.criteria.expression.OptionalOperators)1