Package com.github.mhewedy.expressions
Class Expressions
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
Object>
Represents Group of expression using mongodb query api.
Example:
{ "status": "A", "$or": [{ "qty": { "$lt": 30 } }, { "item": { "$in": ["A", "D"] } }] }
Support a list of Operators defined in Operator
.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionand
(Expression expression) Add the parameter expression to the list of expression in the expressions object.<T> org.springframework.data.jpa.domain.Specification<T>
or
(Expression expression) Create a new $or expression on the root, then adds to it the current expressions attached at the root and the expression passes as parameter.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
Expressions
public Expressions()
-
-
Method Details
-
or
Create a new $or expression on the root, then adds to it the current expressions attached at the root and the expression passes as parameter.Example: Suppose we have the following expression as json:
{"firstName": "ali"}
Then we added the following:
expressions.or(Expression.and( Expression.of("lastName", Operator.$eq, "ibrahim"), Expression.of("age", Operator.$gte, 10) ));
Then the output could be represented as:{ "$or": [ {"firstName": "ali"}, { "$and": [ {"lastName": "ibrahim"}, {"age": {"$gte": 10}}, ] } ] }
Or in sql as:where firstName = "ali" or lastName = "ibrahim" and age >= 10
-
and
Add the parameter expression to the list of expression in the expressions object.Example: Suppose we have the following expression as json:
{"firstName": "ali"}
Then we added the following:
expressions.and(Expression.of("birthDate", Operator.$gt, "1980-10-10")); expressions.and(Expression.or( Expression.of("lastName", Operator.$eq, "ibrahim"), Expression.of("age", Operator.$in, 10, 30) ));
Then the output could be represented as:{ "firstName": "ali", "birthDate": {"$gt": "1980-10-10"}, "$or": [ {"lastName": "ibrahim"}, {"age": {"$in": [10, 30]}} ] }
Or in sql as:where firstName = "ali" and birthDate > "1980-10-10" and (lastName = "ibrahim" or age in (10, 30) )
-
getSpecification
public <T> org.springframework.data.jpa.domain.Specification<T> getSpecification()
-