public class Restrictions extends Object
The <tt>criterion</tt> package may be used by applications as a framework for building new kinds of <tt>Criterion</tt>. However, it is intended that most applications will simply use the built-in criterion types via the static factory methods of this class.
See also the Projections
factory methods for generating Projection
instances
Criteria
Modifier | Constructor and Description |
---|---|
protected |
Restrictions() |
Modifier and Type | Method and Description |
---|---|
static Criterion |
allEq(Map<String,?> propertyNameValues)
Apply an "equals" constraint to each property in the key set of a <tt>Map</tt>
|
static Conjunction |
and(Criterion... predicates)
Return the conjuction of multiple expressions
|
static LogicalExpression |
and(Criterion lhs,
Criterion rhs)
Return the conjuction of two expressions
|
static Criterion |
between(String propertyName,
Object low,
Object high)
Apply a "between" constraint to the named property
|
static Conjunction |
conjunction()
Group expressions together in a single conjunction (A and B and C…).
|
static Conjunction |
conjunction(Criterion... conditions)
Group expressions together in a single conjunction (A and B and C…).
|
static Disjunction |
disjunction()
Group expressions together in a single disjunction (A or B or C…).
|
static Disjunction |
disjunction(Criterion... conditions)
Group expressions together in a single disjunction (A or B or C…).
|
static SimpleExpression |
eq(String propertyName,
Object value)
Apply an "equal" constraint to the named property
|
static Criterion |
eqOrIsNull(String propertyName,
Object value)
Apply an "equal" constraint to the named property.
|
static PropertyExpression |
eqProperty(String propertyName,
String otherPropertyName)
Apply an "equal" constraint to two properties
|
static SimpleExpression |
ge(String propertyName,
Object value)
Apply a "greater than or equal" constraint to the named property
|
static PropertyExpression |
geProperty(String propertyName,
String otherPropertyName)
Apply a "greater than or equal" constraint to two properties
|
static SimpleExpression |
gt(String propertyName,
Object value)
Apply a "greater than" constraint to the named property
|
static PropertyExpression |
gtProperty(String propertyName,
String otherPropertyName)
Apply a "greater than" constraint to two properties
|
static Criterion |
idEq(Object value)
Apply an "equal" constraint to the identifier property
|
static Criterion |
ilike(String propertyName,
Object value)
A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator)
|
static Criterion |
ilike(String propertyName,
String value,
MatchMode matchMode)
A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator) using the provided match mode
|
static Criterion |
in(String propertyName,
Collection values)
Apply an "in" constraint to the named property.
|
static Criterion |
in(String propertyName,
Object... values)
Apply an "in" constraint to the named property.
|
static Criterion |
isEmpty(String propertyName)
Constrain a collection valued property to be empty
|
static Criterion |
isNotEmpty(String propertyName)
Constrain a collection valued property to be non-empty
|
static Criterion |
isNotNull(String propertyName)
Apply an "is not null" constraint to the named property
|
static Criterion |
isNull(String propertyName)
Apply an "is null" constraint to the named property
|
static SimpleExpression |
le(String propertyName,
Object value)
Apply a "less than or equal" constraint to the named property
|
static PropertyExpression |
leProperty(String propertyName,
String otherPropertyName)
Apply a "less than or equal" constraint to two properties
|
static SimpleExpression |
like(String propertyName,
Object value)
Apply a "like" constraint to the named property
|
static SimpleExpression |
like(String propertyName,
String value,
MatchMode matchMode)
Apply a "like" constraint to the named property using the provided match mode
|
static SimpleExpression |
lt(String propertyName,
Object value)
Apply a "less than" constraint to the named property
|
static PropertyExpression |
ltProperty(String propertyName,
String otherPropertyName)
Apply a "less than" constraint to two properties
|
static NaturalIdentifier |
naturalId()
Consider using any of the natural id based loading stuff from session instead, especially in cases
where the restriction is the full set of natural id values.
|
static SimpleExpression |
ne(String propertyName,
Object value)
Apply a "not equal" constraint to the named property
|
static Criterion |
neOrIsNotNull(String propertyName,
Object value)
Apply a "not equal" constraint to the named property.
|
static PropertyExpression |
neProperty(String propertyName,
String otherPropertyName)
Apply a "not equal" constraint to two properties
|
static Criterion |
not(Criterion expression)
Return the negation of an expression
|
static Disjunction |
or(Criterion... predicates)
Return the disjuction of multiple expressions
|
static LogicalExpression |
or(Criterion lhs,
Criterion rhs)
Return the disjuction of two expressions
|
static Criterion |
sizeEq(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sizeGe(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sizeGt(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sizeLe(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sizeLt(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sizeNe(String propertyName,
int size)
Constrain a collection valued property by size
|
static Criterion |
sqlRestriction(String sql)
Apply a constraint expressed in SQL with no JDBC parameters.
|
static Criterion |
sqlRestriction(String sql,
Object[] values,
Type[] types)
Create a restriction expressed in SQL with JDBC parameters.
|
static Criterion |
sqlRestriction(String sql,
Object value,
Type type)
Create a restriction expressed in SQL with one JDBC parameter.
|
public static Criterion idEq(Object value)
Apply an "equal" constraint to the identifier property
value
- The value to use in comparisonIdentifierEqExpression
public static SimpleExpression eq(String propertyName, Object value)
Apply an "equal" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static Criterion eqOrIsNull(String propertyName, Object value)
Apply an "equal" constraint to the named property. If the value is null, instead apply "is null".
propertyName
- The name of the propertyvalue
- The value to use in comparisoneq(java.lang.String, java.lang.Object)
,
isNull(java.lang.String)
public static SimpleExpression ne(String propertyName, Object value)
Apply a "not equal" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static Criterion neOrIsNotNull(String propertyName, Object value)
Apply a "not equal" constraint to the named property. If the value is null, instead apply "is not null".
propertyName
- The name of the propertyvalue
- The value to use in comparisonne(java.lang.String, java.lang.Object)
,
isNotNull(java.lang.String)
public static SimpleExpression like(String propertyName, Object value)
Apply a "like" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static SimpleExpression like(String propertyName, String value, MatchMode matchMode)
Apply a "like" constraint to the named property using the provided match mode
propertyName
- The name of the propertyvalue
- The value to use in comparisonmatchMode
- The match mode to use in comparisonSimpleExpression
public static Criterion ilike(String propertyName, Object value)
A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator)
propertyName
- The name of the propertyvalue
- The value to use in comparisonLikeExpression
public static Criterion ilike(String propertyName, String value, MatchMode matchMode)
A case-insensitive "like" (similar to Postgres <tt>ilike</tt> operator) using the provided match mode
propertyName
- The name of the propertyvalue
- The value to use in comparisonmatchMode
- The match mode to use in comparisonLikeExpression
public static SimpleExpression gt(String propertyName, Object value)
Apply a "greater than" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static SimpleExpression lt(String propertyName, Object value)
Apply a "less than" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static SimpleExpression le(String propertyName, Object value)
Apply a "less than or equal" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static SimpleExpression ge(String propertyName, Object value)
Apply a "greater than or equal" constraint to the named property
propertyName
- The name of the propertyvalue
- The value to use in comparisonSimpleExpression
public static Criterion between(String propertyName, Object low, Object high)
Apply a "between" constraint to the named property
propertyName
- The name of the propertylow
- The low valuehigh
- The high valueBetweenExpression
public static Criterion in(String propertyName, Object... values)
Apply an "in" constraint to the named property.
propertyName
- The name of the propertyvalues
- The literal values to use in the IN restrictionInExpression
public static Criterion in(String propertyName, Collection values)
Apply an "in" constraint to the named property.
propertyName
- The name of the propertyvalues
- The literal values to use in the IN restrictionInExpression
public static Criterion isNull(String propertyName)
Apply an "is null" constraint to the named property
propertyName
- The name of the propertyNullExpression
public static Criterion isNotNull(String propertyName)
Apply an "is not null" constraint to the named property
propertyName
- The property nameNotNullExpression
public static PropertyExpression eqProperty(String propertyName, String otherPropertyName)
Apply an "equal" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static PropertyExpression neProperty(String propertyName, String otherPropertyName)
Apply a "not equal" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static PropertyExpression ltProperty(String propertyName, String otherPropertyName)
Apply a "less than" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static PropertyExpression leProperty(String propertyName, String otherPropertyName)
Apply a "less than or equal" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static PropertyExpression gtProperty(String propertyName, String otherPropertyName)
Apply a "greater than" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static PropertyExpression geProperty(String propertyName, String otherPropertyName)
Apply a "greater than or equal" constraint to two properties
propertyName
- One property nameotherPropertyName
- The other property namePropertyExpression
public static LogicalExpression and(Criterion lhs, Criterion rhs)
Return the conjuction of two expressions
lhs
- One expressionrhs
- The other expressionpublic static Conjunction and(Criterion... predicates)
Return the conjuction of multiple expressions
predicates
- The predicates making up the initial junctionpublic static LogicalExpression or(Criterion lhs, Criterion rhs)
Return the disjuction of two expressions
lhs
- One expressionrhs
- The other expressionpublic static Disjunction or(Criterion... predicates)
Return the disjuction of multiple expressions
predicates
- The predicates making up the initial junctionpublic static Criterion not(Criterion expression)
Return the negation of an expression
expression
- The expression to be negatedNotExpression
public static Criterion sqlRestriction(String sql, Object[] values, Type[] types)
Create a restriction expressed in SQL with JDBC parameters. Any occurrences of <tt>{alias}</tt> will be replaced by the table alias.
sql
- The SQL restrictionvalues
- The parameter valuestypes
- The parameter typesSQLCriterion
public static Criterion sqlRestriction(String sql, Object value, Type type)
Create a restriction expressed in SQL with one JDBC parameter. Any occurrences of <tt>{alias}</tt> will be replaced by the table alias.
sql
- The SQL restrictionvalue
- The parameter valuetype
- The parameter typeSQLCriterion
public static Criterion sqlRestriction(String sql)
Apply a constraint expressed in SQL with no JDBC parameters. Any occurrences of <tt>{alias}</tt> will be replaced by the table alias.
sql
- The SQL restrictionSQLCriterion
public static Conjunction conjunction()
Group expressions together in a single conjunction (A and B and C…).
This form creates an empty conjunction. See Junction.add(Criterion)
public static Conjunction conjunction(Criterion... conditions)
Group expressions together in a single conjunction (A and B and C…).
conditions
- The initial set of conditions to put into the Conjunctionpublic static Disjunction disjunction()
Group expressions together in a single disjunction (A or B or C…).
This form creates an empty disjunction. See Junction.add(Criterion)
public static Disjunction disjunction(Criterion... conditions)
Group expressions together in a single disjunction (A or B or C…).
conditions
- The initial set of conditions to put into the Disjunctionpublic static Criterion allEq(Map<String,?> propertyNameValues)
Apply an "equals" constraint to each property in the key set of a <tt>Map</tt>
propertyNameValues
- a map from property names to valuesConjunction
public static Criterion isEmpty(String propertyName)
Constrain a collection valued property to be empty
propertyName
- The name of the collection propertyEmptyExpression
public static Criterion isNotEmpty(String propertyName)
Constrain a collection valued property to be non-empty
propertyName
- The name of the collection propertyNotEmptyExpression
public static Criterion sizeEq(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static Criterion sizeNe(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static Criterion sizeGt(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static Criterion sizeLt(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static Criterion sizeGe(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static Criterion sizeLe(String propertyName, int size)
Constrain a collection valued property by size
propertyName
- The name of the collection propertysize
- The size to use in comparisonSizeExpression
public static NaturalIdentifier naturalId()
Consider using any of the natural id based loading stuff from session instead, especially in cases where the restriction is the full set of natural id values.
NaturalIdentifier
,
Session.byNaturalId(Class)
,
Session.byNaturalId(String)
,
Session.bySimpleNaturalId(Class)
,
Session.bySimpleNaturalId(String)
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.