List of usage examples for org.springframework.data.mongodb.core.query Criteria regex
public Criteria regex(BsonRegularExpression regex)
From source file:com.comcast.video.dawg.controller.house.filter.FieldCondition.java
/** * {@inheritDoc}/*from w w w.j a v a 2 s .c o m*/ */ @Override public Criteria toCriteria(boolean negate) { boolean notToUse = negate ? !not : not; Criteria crit = Criteria.where("data." + field); switch (this.op) { case equals: return notToUse ? crit.ne(value) : crit.is(value); case contains: crit = notToUse ? crit.not() : crit; if (array) { return crit.in(value); } else { return crit.regex(".*" + value + ".*"); } case matches: crit = notToUse ? crit.not() : crit; return crit.regex(value); default: return null; } }
From source file:org.springframework.data.mongodb.repository.query.MongoQueryCreator.java
/** * Populates the given {@link CriteriaDefinition} depending on the {@link Type} given. * //from w w w. j a v a2s .c o m * @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!"); }