Package com.github.mhewedy.expressions
Class Expression
- java.lang.Object
-
- com.github.mhewedy.expressions.Expression
-
public abstract class Expression extends Object
Expression class considered the base for all other expressions as well as contains factory method to build the expressions object.So it represents the java api for the expressions
Example: We can build complex expressions and pass it to the spring data jpa
ExpressionsRepository.findAll(Expressions)using the factory methods in this class as following:var expressions = Expression.of("lastName", Operator.$eq, "ibrahim") .and(Expression.or( Expression.of("age", Operator.$in, 10, 20), Expression.of("birthDate", Operator.$lt, LocalDate.of(1980, 1, 1))) ).build();Then the output could be represented as:where lastName = "ibrahim" and (age in (10 , 20) or birth_date < "1980-01-01")
The Expression API also service as an intermediate representations that resides between the
Expressionsand the spring data JPA specifications implementationExpressionsPredicateBuilder.
-
-
Constructor Summary
Constructors Constructor Description Expression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Expressionand(Expression expression)apply "and" on current expression with the parameter expression.static Expressionand(Expression... expressions)factory method used to create new expression that "and" all input expressions.Expressionsbuild()Convert current object toExpressionsto be used by theExpressionsRepository.static Expressionof(String field, Operator operator, Number value)static Expressionof(String field, Operator operator, Number... values)Used with operators require list of elements, such asOperator.$inandOperator.$ninstatic Expressionof(String field, Operator operator, String value)static Expressionof(String field, Operator operator, String... values)Used with operators require list of elements, such asOperator.$inandOperator.$ninstatic Expressionof(String field, Operator operator, java.time.temporal.Temporal value)static Expressionof(String field, Operator operator, java.time.temporal.Temporal... values)Used with operators require list of elements, such asOperator.$inandOperator.$ninExpressionor(Expression expression)apply "or" on current expression with the parameter expression.static Expressionor(Expression... expressions)factory method used to create new expression that "or" all input expressions.
-
-
-
Method Detail
-
of
public static Expression of(String field, Operator operator, String value)
-
of
public static Expression of(String field, Operator operator, Number value)
-
of
public static Expression of(String field, Operator operator, java.time.temporal.Temporal value)
-
of
public static Expression of(String field, Operator operator, String... values)
Used with operators require list of elements, such asOperator.$inandOperator.$nin
-
of
public static Expression of(String field, Operator operator, Number... values)
Used with operators require list of elements, such asOperator.$inandOperator.$nin
-
of
public static Expression of(String field, Operator operator, java.time.temporal.Temporal... values)
Used with operators require list of elements, such asOperator.$inandOperator.$nin
-
and
public static Expression and(Expression... expressions)
factory method used to create new expression that "and" all input expressions.
-
or
public static Expression or(Expression... expressions)
factory method used to create new expression that "or" all input expressions.
-
and
public Expression and(Expression expression)
apply "and" on current expression with the parameter expression.
-
or
public Expression or(Expression expression)
apply "or" on current expression with the parameter expression.
-
build
public Expressions build()
Convert current object toExpressionsto be used by theExpressionsRepository.
-
-