Example usage for com.mongodb QueryBuilder lessThanEquals

List of usage examples for com.mongodb QueryBuilder lessThanEquals

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder lessThanEquals.

Prototype

public QueryBuilder lessThanEquals(final Object object) 

Source Link

Document

Equivalent to the $lte operand

Usage

From source file:com.ikanow.aleph2.shared.crud.mongodb.utils.MongoDbUtils.java

License:Apache License

/** Creates the MongoDB clause from the QueryComponent inner object
 * @param field - the field used in the clause
 * @param operator_args - an operator enum and a pair of objects whose context depends on the operator
 * @return the MongoDB clause//w  ww . jav  a 2 s  .  co  m
 */
protected static BasicDBObject operatorToMongoKey(final String field,
        final Tuple2<Operator, Tuple2<Object, Object>> operator_args) {
    return Patterns.match(operator_args).<BasicDBObject>andReturn()
            .when(op_args -> Operator.exists == op_args._1(),
                    op_args -> new BasicDBObject(field, new BasicDBObject("$exists", op_args._2()._1())))

            .when(op_args -> (Operator.any_of == op_args._1()),
                    op_args -> new BasicDBObject(field, new BasicDBObject("$in", op_args._2()._1())))
            .when(op_args -> (Operator.all_of == op_args._1()),
                    op_args -> new BasicDBObject(field, new BasicDBObject("$all", op_args._2()._1())))

            .when(op_args -> (Operator.equals == op_args._1()) && (null != op_args._2()._2()),
                    op_args -> new BasicDBObject(field, new BasicDBObject("$ne", op_args._2()._2())))
            .when(op_args -> (Operator.equals == op_args._1()),
                    op_args -> new BasicDBObject(field, op_args._2()._1()))

            .when(op_args -> Operator.range_open_open == op_args._1(), op_args -> {
                QueryBuilder qb = QueryBuilder.start(field);
                if (null != op_args._2()._1())
                    qb = qb.greaterThan(op_args._2()._1());
                if (null != op_args._2()._2())
                    qb = qb.lessThan(op_args._2()._2());
                return (BasicDBObject) qb.get();
            }).when(op_args -> Operator.range_open_closed == op_args._1(), op_args -> {
                QueryBuilder qb = QueryBuilder.start(field);
                if (null != op_args._2()._1())
                    qb = qb.greaterThan(op_args._2()._1());
                if (null != op_args._2()._2())
                    qb = qb.lessThanEquals(op_args._2()._2());
                return (BasicDBObject) qb.get();
            }).when(op_args -> Operator.range_closed_closed == op_args._1(), op_args -> {
                QueryBuilder qb = QueryBuilder.start(field);
                if (null != op_args._2()._1())
                    qb = qb.greaterThanEquals(op_args._2()._1());
                if (null != op_args._2()._2())
                    qb = qb.lessThanEquals(op_args._2()._2());
                return (BasicDBObject) qb.get();
            }).when(op_args -> Operator.range_closed_open == op_args._1(), op_args -> {
                QueryBuilder qb = QueryBuilder.start(field);
                if (null != op_args._2()._1())
                    qb = qb.greaterThanEquals(op_args._2()._1());
                if (null != op_args._2()._2())
                    qb = qb.lessThan(op_args._2()._2());
                return (BasicDBObject) qb.get();
            }).otherwise(op_args -> new BasicDBObject());
}

From source file:org.apache.gora.mongodb.filters.DefaultFactory.java

License:Apache License

protected QueryBuilder appendToBuilder(final QueryBuilder builder, final FilterOp filterOp,
        final List<Object> rawOperands) {
    List<String> operands = convertOperandsToString(rawOperands);
    switch (filterOp) {
    case EQUALS:/*from   ww  w.  j a va 2 s.c  om*/
        if (operands.size() == 1) {
            builder.is(operands.iterator().next());
        } else {
            builder.in(operands);
        }
        break;
    case NOT_EQUALS:
        if (operands.size() == 1) {
            builder.notEquals(operands.iterator().next());
        } else {
            builder.notIn(operands);
        }
        break;
    case LESS:
        builder.lessThan(operands);
        break;
    case LESS_OR_EQUAL:
        builder.lessThanEquals(operands);
        break;
    case GREATER:
        builder.greaterThan(operands);
        break;
    case GREATER_OR_EQUAL:
        builder.greaterThanEquals(operands);
        break;
    default:
        throw new IllegalArgumentException(filterOp + " no MongoDB equivalent yet");
    }
    return builder;
}

From source file:org.teiid.translator.mongodb.MongoDBSelectVisitor.java

License:Open Source License

protected void buildComparisionQuery(Comparison obj, Object rightExpr, QueryBuilder query) {
    switch (obj.getOperator()) {
    case EQ:/*from   w w w .java  2 s.c  o m*/
        query.is(rightExpr);
        break;
    case NE:
        query.notEquals(rightExpr);
        break;
    case LT:
        query.lessThan(rightExpr);
        break;
    case LE:
        query.lessThanEquals(rightExpr);
        break;
    case GT:
        query.greaterThan(rightExpr);
        break;
    case GE:
        query.greaterThanEquals(rightExpr);
        break;
    }
}

From source file:org.wrml.contrib.runtime.service.mongo.MongoService.java

License:Apache License

private void addQueryCriterion(final SearchCriterion searchCriterion, final QueryBuilder queryBuilder) {

    final ComparisonOperator comparisonOperator = searchCriterion.getComparisonOperator();
    final Object comparisonValue = searchCriterion.getComparisonValue();
    switch (comparisonOperator) {

    case containsAll: {
        queryBuilder.all(comparisonValue);
        break;/*from  w  w  w . j ava 2  s  .c  o  m*/
    }

    case equalTo: {
        queryBuilder.equals(comparisonValue);
        break;
    }

    case equalToAny: {
        queryBuilder.in(comparisonValue);
        break;
    }

    case exists: {
        queryBuilder.exists(true);
        break;
    }

    case greaterThan: {
        queryBuilder.greaterThan(comparisonValue);
        break;
    }

    case greaterThanOrEqualTo: {
        queryBuilder.greaterThanEquals(comparisonValue);
        break;
    }

    case lessThan: {
        queryBuilder.lessThan(comparisonValue);
        break;
    }

    case lessThanOrEqualTo: {
        queryBuilder.lessThanEquals(comparisonValue);
        break;
    }

    case notEqualTo: {
        queryBuilder.notEquals(comparisonValue);
        break;
    }

    case notEqualToAny: {
        queryBuilder.notIn(comparisonValue);
        break;
    }

    case notExists: {
        queryBuilder.exists(false);
        break;
    }

    case regex: {
        final Pattern regexPattern = searchCriterion.getRegexPattern();
        if (regexPattern != null) {
            queryBuilder.regex(regexPattern);
        }

        break;
    }

    }
}