|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hdpagination.dataaccess.support.Restrictions
public final class Restrictions
This class provides static factory methods to produce the Restriction.
Typically, these factory methods are called when calling
JdbcQueryCallbackWrapper.addRestriction(Restriction) or
HBN3QueryCallbackWrapper.addRestriction(Restriction) or
JPAQueryCallbackWrapper.addRestriction(Restriction).
A sample code is as follows:
JdbcQueryCallbackWrapper callback = JdbcQueryCallbackWrapper.newInstance("select productId,prodNo,price,madeIn,description from product p", ProductVO.class)
.addRestriction( Restrictions.eq("prodNo", crit.getProdNo()) )
.addRestriction( Restrictions.in("madeIn", crit.getMadeIn()) );
One generic rule applied to some of its simple static factory methods (eq, gt, ge, lt, le, contains, startsWith, endsWith) is:
param is java.lang.String, it returns null when the param is null or blank.param is of other types, it returns null when the param is null.
If the Restriction object passed to the method
JdbcQueryCallbackWrapper.addRestriction(Restriction) or
HBN3QueryCallbackWrapper.addRestriction(Restriction) or
JPAQueryCallbackWrapper.addRestriction(Restriction)
is null, the restriction will not be added.
The benefit of doing this way is you can avoid IF .. ELSE check in your code. Consequently, the code is much neater.
| Method Summary | |
|---|---|
static Restriction |
contains(java.lang.String column,
java.lang.String param)
Apply "LIKE" constraint ( [column] like ?). |
static Restriction |
endsWith(java.lang.String column,
java.lang.String param)
Apply "LIKE" constraint ( [column] like ?). |
static Restriction |
eq(java.lang.String column,
java.lang.Object param)
Apply equal constraint ( [column] = ?). |
static Restriction |
ge(java.lang.String column,
java.lang.Object param)
Apply "greater than or equal" constraint ( [column] >= ?). |
static Restriction |
gt(java.lang.String column,
java.lang.Object param)
Apply "greater than" constraint ( [column] > ?). |
static Restriction |
in(java.lang.String column,
java.util.List params)
Apply "IN" constraint ( [column] IN (?, ?...)). |
static Restriction |
in(java.lang.String column,
java.lang.Object[] params)
Apply "IN" constraint ( [column] IN (?, ?...)). |
static Restriction |
le(java.lang.String column,
java.lang.Object param)
Apply "less than or equal" constraint ( [column] <= ?). |
static Restriction |
lt(java.lang.String column,
java.lang.Object param)
Apply "less than" constraint ( [column] < ?). |
static Restriction |
range(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
Apply range constraint ( [column] >= ? AND [column] <= ? ). |
static Restriction |
rangeBothExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
Apply range constraint ( [column] > ? AND [column] < ? ). |
static Restriction |
rangeLeftExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
Apply range constraint ( [column] > ? AND [column] <= ? ). |
static Restriction |
rangeRightExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
Apply range constraint ( [column] >= ? AND [column] < ? ). |
static Restriction |
startsWith(java.lang.String column,
java.lang.String param)
Apply "LIKE" constraint ( [column] like ?). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Restriction eq(java.lang.String column,
java.lang.Object param)
[column] = ?).
If the value of parameter (argument param) is null, then return null. It also returns null if the value of parameter
(with the type of java.lang.String) is blank.
column - The column (before =) in the clause fragment. It can not be null or empty.param - the value of parameter
public static Restriction gt(java.lang.String column,
java.lang.Object param)
[column] > ?).
If the value of parameter (argument param) is null, then return null. It also returns null if the value of parameter
(with the type of java.lang.String) is blank.
column - The column (before >) in the clause fragment.It can not be null or empty.param - the value of parameter
public static Restriction ge(java.lang.String column,
java.lang.Object param)
[column] >= ?).
If the value of parameter (argument param) is null, then return null. It also returns null if the value of parameter
(with the type of java.lang.String) is blank.
column - The column (before >=) in the clause fragment.It can not be null or empty.param - the value of parameter
public static Restriction lt(java.lang.String column,
java.lang.Object param)
[column] < ?).
If the value of parameter (argument param) is null, then return null. It also returns null if the value of parameter
(with the type of java.lang.String) is blank.
column - The column (before <) in the clause fragment.It can not be null or empty.param - the value of parameter
public static Restriction le(java.lang.String column,
java.lang.Object param)
[column] <= ?).
If the value of parameter (argument param) is null, then return null. It also returns null if the value of parameter
(with the type of java.lang.String) is blank.
column - The column (before <=) in the clause fragment.It can not be null or empty.param - the value of parameter
public static Restriction in(java.lang.String column,
java.lang.Object[] params)
[column] IN (?, ?...)).
If the parameters (argument params) is null or has zero size, then return null.
column - The column (before IN) in the clause fragment.It can not be null or empty.params - the array of parameters
public static Restriction in(java.lang.String column,
java.util.List params)
[column] IN (?, ?...)).
If the parameters (argument params) is null or has zero size, then return null.
column - The column (before IN) in the clause fragment.It can not be null or empty.params - the list of parameters
public static Restriction range(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
[column] >= ? AND [column] <= ? ).
The rule is:
'fromParam' and 'toParam' are null or blank (with type of java.lang.String), then return null; 'fromParam' is null or blank, then ([column] <= ? ) applies, and only argument'toParam' is for parameter binding; 'toParam' is null or blank, then ([column] >= ? ) applies, and only argument'fromParam' is for parameter binding; 'fromParam' and 'toParam' are not null and blank , then ( [column] >= ? AND [column] <= ? ) applies;
column - It can not be null or empty.fromParam - toParam -
public static Restriction rangeRightExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
[column] >= ? AND [column] < ? ).
The rule is:
'fromParam' and 'toParam' are null or blank (with type of java.lang.String), then return null; 'fromParam' is null or blank, then ([column] < ? ) applies, and only argument'toParam' is for parameter binding; 'toParam' is null or blank, then ([column] >= ? ) applies, and only argument'fromParam' is for parameter binding; 'fromParam' and 'toParam' are not null and blank , then ( [column] >= ? AND [column] < ? ) applies;
column - It can not be null or empty.fromParam - toParam -
public static Restriction rangeLeftExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
[column] > ? AND [column] <= ? ).
The rule is:
'fromParam' and 'toParam' are null or blank (with type of java.lang.String), then return null; 'fromParam' is null or blank, then ([column] <= ? ) applies, and only argument'toParam' is for parameter binding; 'toParam' is null or blank, then ([column] > ? ) applies, and only argument'fromParam' is for parameter binding; 'fromParam' and 'toParam' are not null and blank , then ( [column] > ? AND [column] <= ? ) applies;
column - It can not be null or empty.fromParam - toParam -
public static Restriction rangeBothExclusive(java.lang.String column,
java.lang.Object fromParam,
java.lang.Object toParam)
[column] > ? AND [column] < ? ).
The rule is:
'fromParam' and 'toParam' are null or blank (with type of java.lang.String), then return null; 'fromParam' is null or blank, then ([column] < ? ) applies, and only argument'toParam' is for parameter binding;'toParam' is null or blank, then ([column] > ? ) applies, and only argument'fromParam' is for parameter binding; 'fromParam' and 'toParam' are not null and blank , then ( [column] > ? AND [column] < ? ) applies;
column - It can not be null or empty.fromParam - toParam -
public static Restriction contains(java.lang.String column,
java.lang.String param)
[column] like ?). The actual binding parameter value is %param%.
If the parameter (argument param) is null or blank, then return null.
column - The column (before LIKE) in the clause fragment. It can not be null or empty.param - The actual binding parameter value is %param%.
public static Restriction startsWith(java.lang.String column,
java.lang.String param)
[column] like ?). The actual binding parameter value is param%.
If the parameter (argument param) is null or blank, then return null.
column - The column (before LIKE) in the clause fragment. It can not be null or empty.param - The actual binding parameter value is param%.
public static Restriction endsWith(java.lang.String column,
java.lang.String param)
[column] like ?). The actual binding parameter value is %param.
If the parameter (argument param) is null or blank, then return null.
column - The column (before LIKE) in the clause fragment. It can not be null or empty.param - The actual binding parameter value is param%.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||