Example usage for org.springframework.data.mongodb.core.query Criteria exists

List of usage examples for org.springframework.data.mongodb.core.query Criteria exists

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Criteria exists.

Prototype

public Criteria exists(boolean b) 

Source Link

Document

Creates a criterion using the $exists operator.

Usage

From source file:org.springframework.data.mongodb.repository.query.MongoQueryCreator.java

/**
 * Populates the given {@link CriteriaDefinition} depending on the {@link Type} given.
 * //from  ww  w .jav  a  2 s.  c  om
 * @param type
 * @param criteria
 * @param parameters
 * @return
 */
private Criteria from(Type type, Criteria criteria, PotentiallyConvertingIterator parameters) {

    switch (type) {
    case GREATER_THAN:
        return criteria.gt(parameters.nextConverted());
    case GREATER_THAN_EQUAL:
        return criteria.gte(parameters.nextConverted());
    case LESS_THAN:
        return criteria.lt(parameters.nextConverted());
    case LESS_THAN_EQUAL:
        return criteria.lte(parameters.nextConverted());
    case BETWEEN:
        return criteria.gt(parameters.nextConverted()).lt(parameters.nextConverted());
    case IS_NOT_NULL:
        return criteria.ne(null);
    case IS_NULL:
        return criteria.is(null);
    case NOT_IN:
        return criteria.nin(nextAsArray(parameters));
    case IN:
        return criteria.in(nextAsArray(parameters));
    case LIKE:
        String value = parameters.next().toString();
        return criteria.regex(toLikeRegex(value));
    case REGEX:
        return criteria.regex(parameters.next().toString());
    case EXISTS:
        return criteria.exists((Boolean) parameters.next());
    case TRUE:
        return criteria.is(true);
    case FALSE:
        return criteria.is(false);
    case NEAR:

        Distance distance = accessor.getMaxDistance();
        Point point = accessor.getGeoNearLocation();
        point = point == null ? nextAs(parameters, Point.class) : point;

        if (distance == null) {
            return criteria.near(point);
        } else {
            if (distance.getMetric() != null) {
                criteria.nearSphere(point);
            } else {
                criteria.near(point);
            }
            criteria.maxDistance(distance.getNormalizedValue());
        }
        return criteria;

    case WITHIN:
        Object parameter = parameters.next();
        return criteria.within((Shape) parameter);
    case SIMPLE_PROPERTY:
        return criteria.is(parameters.nextConverted());
    case NEGATING_SIMPLE_PROPERTY:
        return criteria.not().is(parameters.nextConverted());
    }

    throw new IllegalArgumentException("Unsupported keyword!");
}