public class Restrictions
extends java.lang.Object
Constructor and Description |
---|
Restrictions() |
Modifier and Type | Method and Description |
---|---|
static Restriction |
and(Restriction... r)
Combine one or more restrictions with AND:
new restriction = r[0] AND r[1] AND ...
|
static Restriction |
between(Expression e,
Expression low,
Expression high)
Compare if one expression falls between two other expressions:
new expression = low <= e AND e < high.
|
static Restriction |
betweenInclusive(Expression e,
Expression low,
Expression high)
Compare if one expression falls between two other expressions (inclusive):
new expression = low <= e AND e <= high.
|
static Restriction |
conditionalRestriction(Filter<? extends Query> filter,
Restriction ifTrue,
Restriction ifFalse,
boolean nullMatchNone)
Create a restriction that falls back to one of two restrictions
depending on if the query passes a filter or not.
|
private static <T> T[] |
copyNotNulls(java.util.Collection<? extends T> source,
T[] dest) |
private static <T> T[] |
copyNotNulls(T[] source,
T[] dest) |
private static int |
countNotNulls(java.util.Collection<?> array) |
private static int |
countNotNulls(java.lang.Object[] array) |
static Restriction |
eq(Expression e1,
Expression e2)
Compare if two expressions are equal: new restriction = e1 == e2.
|
private static int |
getFirstNull(java.lang.Object[] array)
Test if there is null in the array.
|
static Restriction |
gt(Expression e1,
Expression e2)
Compare if one expression is greater than another: new restriction = e1 > e2.
|
static Restriction |
gteq(Expression e1,
Expression e2)
Compare if one expression is greater than or equal
to another: new restriction = e1 >= e2.
|
static Restriction |
in(Expression e1,
Expression... e2)
Check if an expression is contained in a set of other expressions:
e1 IN (e2[0], e2[1], ...)
|
static Restriction |
in(Expression e1,
Query subquery)
Create a subquery restriction:
e1 IN (subquery) . |
static Restriction |
like_in(Expression e1,
Expression... e2)
Check if one expression matches any expressions in an array:
(e1 LIKE e2.1) OR (e1 LIKE e2.2) OR ....
|
static Restriction |
like(Expression e1,
Expression e2)
Check if one expression matches another: e1 LIKE e2
|
static Restriction |
lt(Expression e1,
Expression e2)
Compare if one expression is less than another: new restriction = e1 < e2.
|
static Restriction |
lteq(Expression e1,
Expression e2)
Compare if one expression is less than or equal
to another: new restriction = e1 <= e2.
|
static Restriction |
neq(Expression e1,
Expression e2)
Compare if two expressions are inequal: new restriction = e1 <> e2.
|
static Restriction |
not(Restriction r)
Negate a restriction: new restriction = NOT r
|
static Restriction |
notLike_in(Expression e1,
Expression... e2)
Check if one expression doesn't matches any of the expressions in an array.
|
static Restriction |
nullSafeAnd(java.util.Collection<? extends Restriction> restrictions)
Combine one or more restrictions with AND:
new restriction = r[0] AND r[1] AND ...
|
static Restriction |
nullSafeAnd(Restriction... r)
Combine one or more restrictions with AND ignoring null elements.
|
static Restriction |
nullSafeOr(java.util.Collection<? extends Restriction> restrictions)
Combine one or more restrictions with OR ignoring null elements.
|
static Restriction |
nullSafeOr(Restriction... r)
Combine one or more restrictions with OR ignoring null elements.
|
static Restriction |
or(Restriction... r)
Combine one or more restrictions with OR: new restriction = r[0] OR r[1] ...
|
static Restriction |
rlike(Expression e,
Expression regexp)
Check if an expression matches a regular expression.
|
public static Restriction and(Restriction... r) throws InvalidDataException
r
- The restrictions to combineInvalidDataException
- If any of the elements is null or
the array doesn't contain at least one elementpublic static Restriction nullSafeAnd(Restriction... r) throws InvalidDataException
r
- The restrictions to combineInvalidDataException
public static Restriction nullSafeAnd(java.util.Collection<? extends Restriction> restrictions) throws InvalidDataException
restrictions
- The restrictions to combineInvalidDataException
public static Restriction or(Restriction... r) throws InvalidDataException
r
- The restrictions to combineInvalidDataException
- If any of the elements is null or
the array doesn't contain at least one elementpublic static Restriction nullSafeOr(java.util.Collection<? extends Restriction> restrictions) throws InvalidDataException
restrictions
- The restrictions to combineInvalidDataException
public static Restriction nullSafeOr(Restriction... r) throws InvalidDataException
r
- The restrictions to combineInvalidDataException
public static Restriction not(Restriction r) throws InvalidDataException
r
- The restrictions to negateInvalidDataException
- If the restriction is nullpublic static Restriction eq(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If both expressions are nullpublic static Restriction neq(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If both expressions are nullpublic static Restriction gt(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If any of the expressions are nullpublic static Restriction gteq(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If any of the expressions are nullpublic static Restriction lt(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If any of the expressions are nullpublic static Restriction lteq(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If any of the expressions are nullpublic static Restriction between(Expression e, Expression low, Expression high) throws InvalidDataException
e
- The expression to check against the limitslow
- The expression for the low limithigh
- The expression for the high limitInvalidDataException
- If any of the expressions are nullpublic static Restriction betweenInclusive(Expression e, Expression low, Expression high) throws InvalidDataException
e
- The expression to check against the limitslow
- The expression for the low limithigh
- The expression for the high limitInvalidDataException
- If any of the expressions are nullpublic static Restriction in(Expression e1, Expression... e2) throws InvalidDataException
e1
- The expression to checke2
- The set of expression to check againstInvalidDataException
- If the set is null or emptypublic static Restriction in(Expression e1, Query subquery)
e1 IN (subquery)
.
The expression is useful in the WHERE part of a query only.
For example, to find all users that are members of a group
having a name starting with A.
Query groupFilter = User.getQuery(); groupFilter.join(Hql.innerJoin("groups", "grp")); groupFilter.restrict(Restrictions.like(Hql.property("grp", "name"), Expressions.string("A%"))); Query userQuery = User.getQuery(); userQuery.restrict(Restrictions.in(Hql.property("id"), groupFilter));
e1
- The left expressionsubquery
- The subqueryInvalidDataException
- If the subquery is nullpublic static Restriction like(Expression e1, Expression e2) throws InvalidDataException
e1
- The left expressione2
- The right expressionInvalidDataException
- If any of the expressions are nullpublic static Restriction like_in(Expression e1, Expression... e2)
e1
- The left expressione2
- The array with expression to match against, null values are allowed
and compared with IS NULL insteadInvalidDataException
- If any of the expressions are null.public static Restriction notLike_in(Expression e1, Expression... e2)
e1
- The left expression. Null is not allowede2
- The array with expressions that shouldn't match, null values
are allows and compared with NOT IS NULLInvalidDataException
- If any of the required expressions are null.public static Restriction rlike(Expression e, Expression regexp)
e
- The expression to matchregexp
- The regular expression to test againstInvalidDataException
- If any of the values are nullpublic static Restriction conditionalRestriction(Filter<? extends Query> filter, Restriction ifTrue, Restriction ifFalse, boolean nullMatchNone)
filter
- A filter, if null the 'ifTrue' restriction is returnedifTrue
- The restriction to apply if the filter evaluates to TRUE, or null to not apply
any restriction in this caseifFalse
- The restriction to apply if the filter evaluates to FALSE, or null to not apply
any restriction in this casenullMatchNone
- FALSE to match all items if the filter is null, TRUE to
match no items if the filter is nullprivate static int getFirstNull(java.lang.Object[] array)
private static int countNotNulls(java.lang.Object[] array)
private static int countNotNulls(java.util.Collection<?> array)
private static <T> T[] copyNotNulls(T[] source, T[] dest)
private static <T> T[] copyNotNulls(java.util.Collection<? extends T> source, T[] dest)