2.17.2: 2011-06-17

net.sf.basedb.core.query
Class Restrictions

java.lang.Object
  extended by net.sf.basedb.core.query.Restrictions

public class Restrictions
extends Object

A factory class to create restrictions.

Version:
2.0
Author:
Samuel, Nicklas
Last modified
$Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Constructor Summary
Restrictions()
           
 
Method Summary
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.
private static
<T> T[]
copyNotNulls(T[] source, T[] dest)
           
private static int countNotNulls(Object[] array)
           
static Restriction eq(Expression e1, Expression e2)
          Compare if two expressions are equal: new restriction = e1 == e2.
private static int getFirstNull(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 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(Restriction... r)
          Combine one or more restrictions with AND 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Restrictions

public Restrictions()
Method Detail

and

public static Restriction and(Restriction... r)
                       throws InvalidDataException
Combine one or more restrictions with AND: new restriction = r[0] AND r[1] AND ...

Parameters:
r - The restrictions to combine
Returns:
The new restriction
Throws:
InvalidDataException - If any of the elements is null or the array doesn't contain at least one element

nullSafeAnd

public static Restriction nullSafeAnd(Restriction... r)
                               throws InvalidDataException
Combine one or more restrictions with AND ignoring null elements.

Parameters:
r - The restrictions to combine
Returns:
The new restriction, or null if the array was null or didn't contain any not-null elements
Throws:
InvalidDataException
Since:
2.15

or

public static Restriction or(Restriction... r)
                      throws InvalidDataException
Combine one or more restrictions with OR: new restriction = r[0] OR r[1] ...

Parameters:
r - The restrictions to combine
Returns:
The new restriction
Throws:
InvalidDataException - If any of the elements is null or the array doesn't contain at least one element

nullSafeOr

public static Restriction nullSafeOr(Restriction... r)
                              throws InvalidDataException
Combine one or more restrictions with OR ignoring null elements.

Parameters:
r - The restrictions to combine
Returns:
The new restriction, or null if the array was null or didn't contain any not-null elements
Throws:
InvalidDataException
Since:
2.15

not

public static Restriction not(Restriction r)
                       throws InvalidDataException
Negate a restriction: new restriction = NOT r

Parameters:
r - The restrictions to negate
Returns:
The new restriction
Throws:
InvalidDataException - If the restriction is null

eq

public static Restriction eq(Expression e1,
                             Expression e2)
                      throws InvalidDataException
Compare if two expressions are equal: new restriction = e1 == e2. If one of the expressions are null, the IS NULL operation is used: new restriction = e1 IS NULL (or e2 IS NULL).

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If both expressions are null

neq

public static Restriction neq(Expression e1,
                              Expression e2)
                       throws InvalidDataException
Compare if two expressions are inequal: new restriction = e1 <> e2. If one of the expressions are null, the NOT IS NULL operation is used: new restriction = NOT e1 IS NULL (or NOT e2 IS NULL).

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If both expressions are null

gt

public static Restriction gt(Expression e1,
                             Expression e2)
                      throws InvalidDataException
Compare if one expression is greater than another: new restriction = e1 > e2.

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

gteq

public static Restriction gteq(Expression e1,
                               Expression e2)
                        throws InvalidDataException
Compare if one expression is greater than or equal to another: new restriction = e1 >= e2.

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

lt

public static Restriction lt(Expression e1,
                             Expression e2)
                      throws InvalidDataException
Compare if one expression is less than another: new restriction = e1 < e2.

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

lteq

public static Restriction lteq(Expression e1,
                               Expression e2)
                        throws InvalidDataException
Compare if one expression is less than or equal to another: new restriction = e1 <= e2.

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

between

public static Restriction between(Expression e,
                                  Expression low,
                                  Expression high)
                           throws InvalidDataException
Compare if one expression falls between two other expressions: new expression = low <= e AND e < high. Since the inclusion/exclusion of the low and high limits are dependent of the database BASE hase defined the between this way to make sure that BASE will treat BETWEEN the same way regardless of database.

Parameters:
e - The expression to check against the limits
low - The expression for the low limit
high - The expression for the high limit
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

in

public static Restriction in(Expression e1,
                             Expression... e2)
                      throws InvalidDataException
Check if an expression is contained in a set of other expressions: e1 IN (e2[0], e2[1], ...)

Parameters:
e1 - The expression to check
e2 - The set of expression to check against
Returns:
The new restriction
Throws:
InvalidDataException - If the set is null or empty

like

public static Restriction like(Expression e1,
                               Expression e2)
                        throws InvalidDataException
Check if one expression matches another: e1 LIKE e2

Parameters:
e1 - The left expression
e2 - The right expression
Returns:
The new restriction
Throws:
InvalidDataException - If any of the expressions are null

like_in

public 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 ....

Parameters:
e1 - The left expression
e2 - The array with expression to match against, null values are allowed and compared with IS NULL instead
Returns:
The new restriction.
Throws:
InvalidDataException - If any of the expressions are null.
Since:
2.6

notLike_in

public static Restriction notLike_in(Expression e1,
                                     Expression... e2)
Check if one expression doesn't matches any of the expressions in an array. (e1 NOT LIKE e2.1) AND (e1 NOT LIKE e2.2) AND...

Parameters:
e1 - The left expression. Null is not allowed
e2 - The array with expressions that shouldn't match, null values are allows and compared with NOT IS NULL
Returns:
The new restriction
Throws:
InvalidDataException - If any of the required expressions are null.
Since:
2.6

rlike

public static Restriction rlike(Expression e,
                                Expression regexp)
Check if an expression matches a regular expression. The support for this is database dependent, but both MySQL and Postgres supports it. If the database doesn't support regular expression, this method will create a restriction for an exact match.

Parameters:
e - The expression to match
regexp - The regular expression to test against
Returns:
A restriction
Throws:
InvalidDataException - If any of the values are null
Since:
2.8

getFirstNull

private static int getFirstNull(Object[] array)
Test if there is null in the array.

Returns:
The index of the first null element, or -1 if no null elements are found, or 0 if the array itself is null

countNotNulls

private static int countNotNulls(Object[] array)

copyNotNulls

private static <T> T[] copyNotNulls(T[] source,
                                    T[] dest)

2.17.2: 2011-06-17