Class ExpressionFactory
- java.lang.Object
-
- org.apache.cayenne.exp.ExpressionFactory
-
public class ExpressionFactory extends Object
Helper class to build expressions.
-
-
Field Summary
Fields Modifier and Type Field Description static charSPLIT_SEPARATORA "split" character, "|", that is understood by some of the ExpressionFactory methods that require splitting joins in the middle of the path.
-
Constructor Summary
Constructors Constructor Description ExpressionFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Expressionand(Collection<Expression> expressions)static Expressionand(Expression... expressions)static ExpressionbetweenDbExp(String pathSpec, Object value1, Object value2)A convenience shortcut for building BETWEEN expressions.static ExpressionbetweenExp(String pathSpec, Object value1, Object value2)A convenience shortcut for building BETWEEN expressions.static ExpressioncontainsExp(String pathSpec, String value)static ExpressioncontainsIgnoreCaseExp(String pathSpec, String value)Same ascontainsExp(String, String)only using case-insensitive comparison.static ExpressiondbPathExp(String pathSpec)static ExpressionendsWithExp(String pathSpec, String value)static ExpressionendsWithIgnoreCaseExp(String pathSpec, String value)Same asendsWithExp(String, String)only using case-insensitive comparison.static Expressionexp(String expressionString, Object... parameters)Parses string, converting it to Expression and optionally binding positional parameters.static ExpressionexpFalse()A convenience shortcut for boolean false expression.static ExpressionexpressionOfType(int type)Creates a new expression for the type requested.static ExpressionexpTrue()A convenience shortcut for boolean true expression.static ExpressionfullObjectExp()static ExpressionfullObjectExp(Expression exp)static ExpressiongreaterDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "greater than" expression.static ExpressiongreaterExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "greater than" expression.static ExpressiongreaterOrEqualDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "greater than or equal to" expression.static ExpressiongreaterOrEqualExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "greater than or equal to" expression.static ExpressioninDbExp(String pathSpec, Object... values)A convenience shortcut for building IN DB expression.static ExpressioninDbExp(String pathSpec, Collection<?> values)A convenience shortcut for building IN DB expression.static ExpressioninExp(String pathSpec, Object... values)A convenience shortcut for building IN expression.static ExpressioninExp(String pathSpec, Collection<?> values)A convenience shortcut for building IN expression.static ExpressionjoinExp(int type, Collection<Expression> expressions)Joins all expressions, making a single expression.static ExpressionjoinExp(int type, Expression... expressions)Joins all expressions, making a single expression.static ExpressionlessDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "less than" expression.static ExpressionlessExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "less than" expression.static ExpressionlessOrEqualDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "less than or equal to" expression.static ExpressionlessOrEqualExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "less than or equal to" expression.static ExpressionlikeDbExp(String pathSpec, Object value)A convenience shortcut for building LIKE DB_PATH expression.static ExpressionlikeDbExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building LIKE DB_PATH expression.static ExpressionlikeExp(String pathSpec, Object value)A convenience shortcut for building LIKE expression.static ExpressionlikeExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building LIKE expression.static ExpressionlikeIgnoreCaseDbExp(String pathSpec, Object value)A convenience shortcut for building LIKE_IGNORE_CASE expression.static ExpressionlikeIgnoreCaseDbExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building LIKE_IGNORE_CASE expression.static ExpressionlikeIgnoreCaseExp(String pathSpec, Object value)A convenience shortcut for building LIKE_IGNORE_CASE expression.static ExpressionlikeIgnoreCaseExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building LIKE_IGNORE_CASE expression.static ExpressionmatchAllDbExp(Map<String,?> map, int pairType)Creates an expression that matches all key-values pairs inmap.static ExpressionmatchAllExp(String path, Object... values)static ExpressionmatchAllExp(String path, Collection<?> values)Creates an expression to match a collection of values against a single path expression.static ExpressionmatchAllExp(Map<String,?> map, int pairType)Creates an expression that matches all key-values pairs inmap.static ExpressionmatchAnyDbExp(Map<String,?> map, int pairType)Creates an expression that matches any of the key-values pairs inmap.static ExpressionmatchAnyExp(List<? extends Persistent> objects)Creates an expression that matches any of the objects contained in the listobjectsstatic ExpressionmatchAnyExp(Map<String,?> map, int pairType)Creates an expression that matches any of the key-values pairs in themap.static ExpressionmatchAnyExp(Persistent... objects)Creates an expression that matches any of the objects contained in theobjectsarraystatic ExpressionmatchDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "equal to" expression.static ExpressionmatchExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "equal to" expression.static ExpressionmatchExp(Persistent object)Creates an expression that matches the primary key of object inObjectId'sIdSnapshotfor the argumentobject.static ExpressionnoMatchDbExp(String pathSpec, Object value)A convenience method to create an DB_PATH "not equal to" expression.static ExpressionnoMatchExp(String pathSpec, Object value)A convenience method to create an OBJ_PATH "not equal to" expression.static ExpressionnotBetweenDbExp(String pathSpec, Object value1, Object value2)A convenience shortcut for building NOT_BETWEEN expressions.static ExpressionnotBetweenExp(String pathSpec, Object value1, Object value2)A convenience shortcut for building NOT_BETWEEN expressions.static ExpressionnotInDbExp(String pathSpec, Object... values)A convenience shortcut for building NOT_IN expression.static ExpressionnotInDbExp(String pathSpec, Collection<?> values)A convenience shortcut for building NOT_IN expression.static ExpressionnotInExp(String pathSpec, Object... values)A convenience shortcut for building NOT_IN expression.static ExpressionnotInExp(String pathSpec, Collection<?> values)A convenience shortcut for building NOT_IN expression.static ExpressionnotLikeDbExp(String pathSpec, Object value)A convenience shortcut for building NOT_LIKE expression.static ExpressionnotLikeDbExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building NOT_LIKE expression.static ExpressionnotLikeExp(String pathSpec, Object value)A convenience shortcut for building NOT_LIKE expression.static ExpressionnotLikeExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building NOT_LIKE expression.static ExpressionnotLikeIgnoreCaseDbExp(String pathSpec, Object value)A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.static ExpressionnotLikeIgnoreCaseDbExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.static ExpressionnotLikeIgnoreCaseExp(String pathSpec, Object value)A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.static ExpressionnotLikeIgnoreCaseExp(String pathSpec, Object value, char escapeChar)A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.static Expressionor(Collection<Expression> expressions)static Expressionor(Expression... expressions)static ExpressionpathExp(String pathSpec)static ExpressionstartsWithExp(String pathSpec, String value)static ExpressionstartsWithIgnoreCaseExp(String pathSpec, String value)Same asstartsWithExp(String, String)only using case-insensitive comparison.protected static ObjectwrapPathOperand(Object op)Applies a few default rules for adding operands to expressions.
-
-
-
Field Detail
-
SPLIT_SEPARATOR
public static final char SPLIT_SEPARATOR
A "split" character, "|", that is understood by some of the ExpressionFactory methods that require splitting joins in the middle of the path.- Since:
- 3.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
expressionOfType
public static Expression expressionOfType(int type)
Creates a new expression for the type requested. If type is unknown, ExpressionException is thrown.
-
wrapPathOperand
protected static Object wrapPathOperand(Object op)
Applies a few default rules for adding operands to expressions. In particular wraps all lists into LIST expressions. Applied only in path expressions.
-
matchAnyDbExp
public static Expression matchAnyDbExp(Map<String,?> map, int pairType)
Creates an expression that matches any of the key-values pairs inmap.For each pair
pairTypeoperator is used to build a binary expression. Key is considered to be a DB_PATH expression. OR is used to join pair binary expressions.
-
matchAllDbExp
public static Expression matchAllDbExp(Map<String,?> map, int pairType)
Creates an expression that matches all key-values pairs inmap.For each pair
pairTypeoperator is used to build a binary expression. Key is considered to be a DB_PATH expression. AND is used to join pair binary expressions.
-
matchAnyExp
public static Expression matchAnyExp(Map<String,?> map, int pairType)
Creates an expression that matches any of the key-values pairs in themap.For each pair
pairTypeoperator is used to build a binary expression. Key is considered to be a OBJ_PATH expression. OR is used to join pair binary expressions.
-
matchAllExp
public static Expression matchAllExp(Map<String,?> map, int pairType)
Creates an expression that matches all key-values pairs inmap.For each pair
pairTypeoperator is used to build a binary expression. Key is considered to be a OBJ_PATH expression. AND is used to join pair binary expressions.
-
matchAllExp
public static Expression matchAllExp(String path, Collection<?> values)
Creates an expression to match a collection of values against a single path expression.Splits
Note that "path" argument here can use a split character (a pipe symbol - '|') instead of dot to indicate that relationship following a path should be split into a separate set of joins. There can only be one split at most. Split must always precede a relationship. E.g. "|exhibits.paintings", "exhibits|paintings", etc.
- Parameters:
path- expressionvalues- collection to match- Since:
- 3.0
-
matchAllExp
public static Expression matchAllExp(String path, Object... values)
- Since:
- 3.0
-
matchDbExp
public static Expression matchDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "equal to" expression.
-
noMatchDbExp
public static Expression noMatchDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "not equal to" expression.
-
matchExp
public static Expression matchExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "equal to" expression.
-
noMatchExp
public static Expression noMatchExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "not equal to" expression.
-
lessExp
public static Expression lessExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "less than" expression.
-
lessDbExp
public static Expression lessDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "less than" expression.- Since:
- 3.0
-
lessOrEqualExp
public static Expression lessOrEqualExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "less than or equal to" expression.
-
lessOrEqualDbExp
public static Expression lessOrEqualDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "less than or equal to" expression.- Since:
- 3.0
-
greaterExp
public static Expression greaterExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "greater than" expression.
-
greaterDbExp
public static Expression greaterDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "greater than" expression.- Since:
- 3.0
-
greaterOrEqualExp
public static Expression greaterOrEqualExp(String pathSpec, Object value)
A convenience method to create an OBJ_PATH "greater than or equal to" expression.
-
greaterOrEqualDbExp
public static Expression greaterOrEqualDbExp(String pathSpec, Object value)
A convenience method to create an DB_PATH "greater than or equal to" expression.- Since:
- 3.0
-
inExp
public static Expression inExp(String pathSpec, Object... values)
A convenience shortcut for building IN expression. Return ASTFalse for empty collection.
-
inDbExp
public static Expression inDbExp(String pathSpec, Object... values)
A convenience shortcut for building IN DB expression. Return ASTFalse for empty collection.
-
inExp
public static Expression inExp(String pathSpec, Collection<?> values)
A convenience shortcut for building IN expression. Return ASTFalse for empty collection.
-
inDbExp
public static Expression inDbExp(String pathSpec, Collection<?> values)
A convenience shortcut for building IN DB expression. Return ASTFalse for empty collection.
-
notInExp
public static Expression notInExp(String pathSpec, Collection<?> values)
A convenience shortcut for building NOT_IN expression. Return ASTTrue for empty collection.
-
notInDbExp
public static Expression notInDbExp(String pathSpec, Collection<?> values)
A convenience shortcut for building NOT_IN expression. Return ASTTrue for empty collection.- Since:
- 3.0
-
notInExp
public static Expression notInExp(String pathSpec, Object... values)
A convenience shortcut for building NOT_IN expression. Return ASTTrue for empty collection.- Since:
- 1.0.6
-
notInDbExp
public static Expression notInDbExp(String pathSpec, Object... values)
A convenience shortcut for building NOT_IN expression. Return ASTTrue for empty collection.- Since:
- 3.0
-
betweenExp
public static Expression betweenExp(String pathSpec, Object value1, Object value2)
A convenience shortcut for building BETWEEN expressions.
-
betweenDbExp
public static Expression betweenDbExp(String pathSpec, Object value1, Object value2)
A convenience shortcut for building BETWEEN expressions.- Since:
- 3.0
-
notBetweenExp
public static Expression notBetweenExp(String pathSpec, Object value1, Object value2)
A convenience shortcut for building NOT_BETWEEN expressions.
-
notBetweenDbExp
public static Expression notBetweenDbExp(String pathSpec, Object value1, Object value2)
A convenience shortcut for building NOT_BETWEEN expressions.- Since:
- 3.0
-
likeExp
public static Expression likeExp(String pathSpec, Object value)
A convenience shortcut for building LIKE expression.
-
likeExp
public static Expression likeExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building LIKE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
likeDbExp
public static Expression likeDbExp(String pathSpec, Object value)
A convenience shortcut for building LIKE DB_PATH expression.- Since:
- 3.0
-
likeDbExp
public static Expression likeDbExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building LIKE DB_PATH expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
notLikeExp
public static Expression notLikeExp(String pathSpec, Object value)
A convenience shortcut for building NOT_LIKE expression.
-
notLikeExp
public static Expression notLikeExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building NOT_LIKE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
notLikeDbExp
public static Expression notLikeDbExp(String pathSpec, Object value)
A convenience shortcut for building NOT_LIKE expression.- Since:
- 3.0
-
notLikeDbExp
public static Expression notLikeDbExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building NOT_LIKE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
likeIgnoreCaseExp
public static Expression likeIgnoreCaseExp(String pathSpec, Object value)
A convenience shortcut for building LIKE_IGNORE_CASE expression.
-
likeIgnoreCaseExp
public static Expression likeIgnoreCaseExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building LIKE_IGNORE_CASE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
likeIgnoreCaseDbExp
public static Expression likeIgnoreCaseDbExp(String pathSpec, Object value)
A convenience shortcut for building LIKE_IGNORE_CASE expression.- Since:
- 3.0
-
likeIgnoreCaseDbExp
public static Expression likeIgnoreCaseDbExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building LIKE_IGNORE_CASE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
notLikeIgnoreCaseExp
public static Expression notLikeIgnoreCaseExp(String pathSpec, Object value)
A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.
-
notLikeIgnoreCaseExp
public static Expression notLikeIgnoreCaseExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
notLikeIgnoreCaseDbExp
public static Expression notLikeIgnoreCaseDbExp(String pathSpec, Object value)
A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.- Since:
- 3.0
-
notLikeIgnoreCaseDbExp
public static Expression notLikeIgnoreCaseDbExp(String pathSpec, Object value, char escapeChar)
A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.
The escape character allows for escaping meta-characters in the LIKE clause. Note that the escape character cannot be '?'. To specify no escape character, supply 0 as the escape character.
- Since:
- 3.0.1
-
containsExp
public static Expression containsExp(String pathSpec, String value)
- Returns:
- An expression for a database "LIKE" query with the value converted to a pattern matching anywhere in the String.
- Since:
- 4.0
-
startsWithExp
public static Expression startsWithExp(String pathSpec, String value)
- Returns:
- An expression for a database "LIKE" query with the value converted to a pattern matching the beginning of the String.
- Since:
- 4.0
-
endsWithExp
public static Expression endsWithExp(String pathSpec, String value)
- Returns:
- An expression for a database "LIKE" query with the value converted to a pattern matching the beginning of the String.
- Since:
- 4.0
-
containsIgnoreCaseExp
public static Expression containsIgnoreCaseExp(String pathSpec, String value)
Same ascontainsExp(String, String)only using case-insensitive comparison.- Since:
- 4.0
-
startsWithIgnoreCaseExp
public static Expression startsWithIgnoreCaseExp(String pathSpec, String value)
Same asstartsWithExp(String, String)only using case-insensitive comparison.- Since:
- 4.0
-
endsWithIgnoreCaseExp
public static Expression endsWithIgnoreCaseExp(String pathSpec, String value)
Same asendsWithExp(String, String)only using case-insensitive comparison.- Since:
- 4.0
-
pathExp
public static Expression pathExp(String pathSpec)
- Parameters:
pathSpec- a String "obj:" path.- Returns:
- a new "obj:" path expression for the specified String path.
- Since:
- 4.0
-
dbPathExp
public static Expression dbPathExp(String pathSpec)
- Parameters:
pathSpec- a String db: path.- Returns:
- a new "db:" path expression for the specified String path.
- Since:
- 4.0
-
expTrue
public static Expression expTrue()
A convenience shortcut for boolean true expression.- Since:
- 3.0
-
expFalse
public static Expression expFalse()
A convenience shortcut for boolean false expression.- Since:
- 3.0
-
joinExp
public static Expression joinExp(int type, Collection<Expression> expressions)
Joins all expressions, making a single expression.typeis used as an expression type for expressions joining each one of the items on the list.typemust be binary expression type.For example, if type is Expression.AND, resulting expression would match all expressions in the list. If type is Expression.OR, resulting expression would match any of the expressions.
-
joinExp
public static Expression joinExp(int type, Expression... expressions)
Joins all expressions, making a single expression.typeis used as an expression type for expressions joining each one of the items in the array.typemust be binary expression type.For example, if type is Expression.AND, resulting expression would match all expressions in the list. If type is Expression.OR, resulting expression would match any of the expressions.
- Since:
- 4.1
-
matchExp
public static Expression matchExp(Persistent object)
Creates an expression that matches the primary key of object inObjectId'sIdSnapshotfor the argumentobject.
-
matchAnyExp
public static Expression matchAnyExp(List<? extends Persistent> objects)
Creates an expression that matches any of the objects contained in the listobjects
-
matchAnyExp
public static Expression matchAnyExp(Persistent... objects)
Creates an expression that matches any of the objects contained in theobjectsarray
-
fullObjectExp
public static Expression fullObjectExp()
-
fullObjectExp
public static Expression fullObjectExp(Expression exp)
-
and
public static Expression and(Collection<Expression> expressions)
- Since:
- 4.0
-
and
public static Expression and(Expression... expressions)
- Since:
- 4.0
-
or
public static Expression or(Collection<Expression> expressions)
- Since:
- 4.0
-
or
public static Expression or(Expression... expressions)
- Since:
- 4.0
-
exp
public static Expression exp(String expressionString, Object... parameters)
Parses string, converting it to Expression and optionally binding positional parameters. If a string does not represent a semantically correct expression, an ExpressionException is thrown.Binding of parameters by name (as opposed to binding by position) can be achieved by chaining this call with
Expression.params(Map).- Since:
- 4.0
-
-