List of usage examples for com.mongodb QueryOperators NOT
String NOT
To view the source code for com.mongodb QueryOperators NOT.
Click Source Link
From source file:org.nuxeo.ecm.core.storage.mongodb.MongoDBQueryBuilder.java
License:Apache License
protected Object pushDownNot(Object object) { if (!(object instanceof DBObject)) { throw new QueryParseException("Cannot do NOT on: " + object); }/*from www.j a v a 2s .c om*/ DBObject ob = (DBObject) object; Set<String> keySet = ob.keySet(); if (keySet.size() != 1) { throw new QueryParseException("Cannot do NOT on: " + ob); } String key = keySet.iterator().next(); Object value = ob.get(key); if (!key.startsWith("$")) { if (value instanceof DBObject) { // push down inside dbobject return new BasicDBObject(key, pushDownNot(value)); } else { // k = v -> k != v return new BasicDBObject(key, new BasicDBObject(QueryOperators.NE, value)); } } if (QueryOperators.NE.equals(key)) { // NOT k != v -> k = v return value; } if (QueryOperators.NOT.equals(key)) { // NOT NOT v -> v return value; } if (QueryOperators.AND.equals(key) || QueryOperators.OR.equals(key)) { // boolean algebra // NOT (v1 AND v2) -> NOT v1 OR NOT v2 // NOT (v1 OR v2) -> NOT v1 AND NOT v2 String op = QueryOperators.AND.equals(key) ? QueryOperators.OR : QueryOperators.AND; List<Object> list = (List<Object>) value; for (int i = 0; i < list.size(); i++) { list.set(i, pushDownNot(list.get(i))); } return new BasicDBObject(op, list); } if (QueryOperators.IN.equals(key) || QueryOperators.NIN.equals(key)) { // boolean algebra // IN <-> NIN String op = QueryOperators.IN.equals(key) ? QueryOperators.NIN : QueryOperators.IN; return new BasicDBObject(op, value); } if (QueryOperators.LT.equals(key) || QueryOperators.GT.equals(key) || QueryOperators.LTE.equals(key) || QueryOperators.GTE.equals(key)) { // TODO use inverse operators? return new BasicDBObject(QueryOperators.NOT, ob); } throw new QueryParseException("Unknown operator for NOT: " + key); }
From source file:org.nuxeo.ecm.core.storage.mongodb.MongoDBQueryBuilder.java
License:Apache License
public DBObject walkLike(Operand lvalue, Operand rvalue, boolean positive, boolean caseInsensitive) { FieldInfo fieldInfo = walkReference(lvalue); if (!(rvalue instanceof StringLiteral)) { throw new QueryParseException("Invalid LIKE/ILIKE, right hand side must be a string: " + rvalue); }/* www . j a va2 s . c o m*/ // TODO check list fields String like = walkStringLiteral((StringLiteral) rvalue); String regex = ExpressionEvaluator.likeToRegex(like); int flags = caseInsensitive ? Pattern.CASE_INSENSITIVE : 0; Pattern pattern = Pattern.compile(regex, flags); Object value; if (positive) { value = pattern; } else { value = new BasicDBObject(QueryOperators.NOT, pattern); } return new FieldInfoDBObject(fieldInfo, value); }
From source file:org.tinygroup.mongodb.engine.comparemode.impl.IsNotEmptyCompareMode.java
License:GNU General Public License
public BSONObject generateBSONObject(String propertyName, Object value, Context context) { BSONObject bsonObject = new BasicDBObject(); bsonObject.put(QueryOperators.NOT, ""); return new BasicDBObject(propertyName, bsonObject); }