|
PAJES 2.3.9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.pajes.db.entity.Scope
Creates a WHERE clause suitable for use with a SQL select, update or delete
java.sql.PreparedStatement. The resulting WHERE clause is
NOT checked for syntactical accuracy.
The clause is built up by applying the and() and or() methods, followed by the appropriate comparison methods (compare(), between() and isNull()). For example:
Scope clause = new Scope()
.leftBrace()
.compare("colA",Scope.EQ,"XYZ")
.and()
.between("colB",new Integer(1),new Integer(10))
.rightBrace()
.or()
.compare("colC",Scope.GT,new Long(9999))
.or()
.isNull("colC")
System.out.println(clause.getWhereClause());
The above example would result in the following WHERE clause:
WHERE ( colA = ? AND colB BETWEEN ? AND ? ) OR colC > ? or colC IS NULL
and a call to clauses.getParameters() would return an Object
array with 4 elements, representing the values passed into the
compare and between methods.
| Field Summary | |
static java.lang.String |
AND
Constant representing the AND conjunction operator. |
static java.lang.String |
BETWEEN
Constant representing the BETWEEN conjunction operator. |
static java.lang.String |
EQ
Constant representing the equals operator. |
static java.lang.String |
GE
Constant representing the greater than or equal to operator. |
static java.lang.String |
GT
Constant representing the greater than operator. |
static java.lang.String |
IN
Constant representing the IN conjunction operator. |
static java.lang.String |
LE
Constant representing the less than or equal to operator. |
static java.lang.String |
LIKE
Constant representing the LIKE operator. |
static java.lang.String |
LT
Constant representing the less than operator. |
static java.lang.String |
NE
Constant representing the inequality operator. |
static java.lang.String |
NOT
Constant representing the "not" modifier. |
static java.lang.String |
OR
Constant representing the or conjunction operator. |
| Constructor Summary | |
Scope()
Creates a WHERE clause suitable for use with a SQL select, update or delete statement. |
|
Scope(Entity entity)
Creates a scope consisting of the primary key values of the specified Entity. |
|
Scope(Entity entity,
boolean initial)
Creates a scope consisting of all the values assigned to an Entity, except those flagged as not participating in the optimistic lock key. |
|
Scope(Manager manager,
javax.servlet.http.HttpServletRequest request)
Creates a WHERE clause suitable for use with a SQL select, update or delete statement for the primary keys defined for Entity objects managed by the specified Manager. |
|
Scope(Manager manager,
javax.servlet.http.HttpServletRequest request,
java.lang.String operator,
boolean keys)
Creates a WHERE clause suitable for use with a SQL select, update or delete statement for the column names defined for Entity objects managed by the specified Manager. |
|
Scope(Scope scope)
Creates a Scope from another Scope. |
|
Scope(java.lang.String where,
java.lang.Object[] values)
Creates a Scope from a supplied WHERE clause suitable for use with a SQL select, update or delete statement. |
|
Scope(java.lang.String columnName,
java.lang.String operator,
java.lang.Object value)
Creates a WHERE clause suitable for use with a SQL select, update or delete statement, with a default comparison clause. |
|
| Method Summary | |
Scope |
and()
Appends an AND statement. |
Scope |
between(java.lang.String columnName,
java.lang.Object lowerValue,
java.lang.Object upperValue)
Appends a BETWEEN comparison. |
Scope |
compare(Entity entity)
Appends equalitycomparisons, joined by and operators, consisting of
the primary key values of the specified Entity and the current value. |
Scope |
compare(Entity entity,
boolean initial)
Appends equalitycomparisons, joined by and operators, consisting of
all the values assigned of the specified Entity, except those
flagged as not participating in the optimistic lock key. |
Scope |
compare(Entity entity,
boolean initial,
boolean keys)
Appends equalitycomparisons, joined by and operators, consisting of
all the values assigned of the specified Entity, except those
flagged as not participating in the optimistic lock key. |
Scope |
compare(javax.servlet.http.HttpServletRequest request,
Manager manager,
java.lang.String operator,
boolean keys)
Appends comparisons created by
checking the parameter names supplied on the HttpServletRequest with
the column names determined from the specified Entity Manager. |
Scope |
compare(javax.servlet.http.HttpServletRequest request,
Manager manager,
java.lang.String operator,
boolean keys,
boolean qualifyColumnName)
Appends comparisons created by
checking the parameter names supplied on the HttpServletRequest with
the column names determined from the specified Entity Manager. |
Scope |
compare(java.lang.String columnName,
java.lang.String operator,
java.lang.Object value)
Appends the specified comparison. |
Scope |
compareColumns(java.lang.String leftColumnName,
java.lang.String operator,
java.lang.String rightColumnName)
Appends the specified comparison between two columns. |
java.util.Set |
getColumnNames()
Returns the set of column names that have been defined on this scope. |
java.lang.String |
getJoinClause()
Returns the join clause. |
java.lang.Object[] |
getJoinParameters()
Returns the join parameters that can be substituted into the join clause. |
java.lang.String |
getOrderByClause()
Returns the ORDER BY clause to sort the result set. |
java.lang.String |
getOrderByColumns()
Returns the ORDER BY columns defined by setOrderByColumns(java.lang.String). |
java.lang.Object[] |
getParameters()
Returns the parameters that can be substituted into the where clause. |
java.lang.String |
getSelectColumns()
Returns the columns to be returned in the result set. |
java.lang.String |
getSelectTable()
Returns the table to which the WHERE clause will apply. |
java.lang.String |
getTableAlias()
Returns the table alias. |
java.lang.String |
getWhereClause()
Returns the where clause as a string, with placeholders where values are to be substituted. |
boolean |
hasConditions()
Determines if any conditions have been set on this scope. |
boolean |
hasJoins()
Determines if any joins have been set on this scope. |
boolean |
hasOrderBy()
Determines if an ORDER BY clause has been set on this scope. |
Scope |
in(java.lang.String columnName,
java.lang.Object[] values)
Appends an IN comparison to the where clause. |
Scope |
in(java.lang.String columnName,
java.lang.String subSelect,
Scope subSelectScope)
Appends a sub query to the where clause. |
Scope |
innerJoin(java.lang.String table,
JoinScope scope)
Creates an INNER JOIN clause. |
Scope |
isNotNull(java.lang.String columnName)
Appends an IS NOT NULL comparison to the where clause. |
Scope |
isNull(java.lang.String columnName)
Appends an IS NULL comparison to the where clause. |
Scope |
isNull(java.lang.String columnName,
boolean notNull)
Appends a NULL comparison to the where clause. |
Scope |
leftBrace()
Appends a left Brace to begin logical statement grouping. |
Scope |
leftOuterJoin(java.lang.String table,
JoinScope scope)
Creates a LEFT OUTER JOIN clause. |
java.util.List |
lookup(java.lang.String columnName)
Returns the list of values that have been provided in the Scope for the specified column name. |
Scope |
merge(Scope scope)
Merges another Scope into this Scope. |
Scope |
merge(java.lang.String where,
java.lang.Object[] values)
Merges a supplied WHERE clause into this Scope. |
Scope |
not()
Appends a NOT statement. |
Scope |
or()
Appends an OR statement. |
Scope |
rightBrace()
Appends a right Brace to end logical statement grouping. |
Scope |
setOrderByColumns(java.lang.String columns)
Sets the sort order of the result set. |
Scope |
setOrderByColumns(java.lang.String[] columns)
Sets the sort order of the result set. |
Scope |
setSelectColumns(java.lang.String columns)
Sets the columns returned in the result set. |
Scope |
setSelectColumns(java.lang.String[] columns)
Sets the columns returned in the result set. |
void |
setSelectTable(java.lang.String tableString)
Sets the table to which the WHERE clause will apply. |
Scope |
setTableAlias(java.lang.String alias)
Sets the table alias. |
Scope |
subQuery(java.lang.String columnName,
java.lang.String operator,
java.lang.String subSelect,
Scope subSelectScope)
Appends a sub query to the where clause. |
java.lang.String |
toString()
Returns a string representation of the scope. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String AND
public static final java.lang.String BETWEEN
public static final java.lang.String EQ
public static final java.lang.String GE
public static final java.lang.String GT
public static final java.lang.String IN
public static final java.lang.String LE
public static final java.lang.String LIKE
public static final java.lang.String LT
public static final java.lang.String NE
public static final java.lang.String NOT
public static final java.lang.String OR
| Constructor Detail |
public Scope()
public Scope(Entity entity)
entity - the Entity for which a scope is required.
public Scope(Entity entity,
boolean initial)
optimistic lock key.
entity - the Entity for which a scope is required.initial - true if the values provided are the initial values of the
attributes.
public Scope(Manager manager,
javax.servlet.http.HttpServletRequest request)
The Scope will be created by checking the parameter names supplied on
the HttpServletRequest, and, where the name matches a primary key
column name, creating a compare(java.lang.String, java.lang.String, java.lang.Object) for each parameter value,
using the EQ operator. Multiple values will be joined with
or() statements within appropriately placed left and right brackets. Multiple column names
will be joined with and() statements.
manager - the Manager object from which the primary column names
will be determined.request - the request object from which the comparison values will
be determined.
public Scope(Manager manager,
javax.servlet.http.HttpServletRequest request,
java.lang.String operator,
boolean keys)
The Scope will be created by checking the parameter names supplied on
the HttpServletRequest, and, where the name matches a column name,
creating a compare(java.lang.String, java.lang.String, java.lang.Object) for each parameter value, using the
specified operator. Multiple values will be joined with or()
statements within appropriately placed left and
right brackets. Multiple column names will be
joined with and() statements.
manager - the Manager object from which the column names will be
determined.request - the request object from which the comparison values will
be determined.operator - the comparison operator.keys - if true, limit the columns that will be included in the
scope to the primary keys. If false, any column for which a
request parameter is found will be included in the scope.public Scope(Scope scope)
scope - the existing Scope to be the source for this scope.
public Scope(java.lang.String where,
java.lang.Object[] values)
where - the base WHERE clause, including the
WHERE statement. Care should be taken to ensure
that the correct number of place holders appear in this String
to match the number of values supplied the array.values - the array of comparison values. Care should be taken to
ensure that the number of values in the array matches the number
of place holders in the supplied WHERE clause string, and be in
the correct sequence in the array.
public Scope(java.lang.String columnName,
java.lang.String operator,
java.lang.Object value)
columnName - the name of the column.operator - the comparison operator.value - the comparison value.| Method Detail |
public java.util.Set getColumnNames()
String.
lookup(java.lang.String)public java.lang.String getJoinClause()
innerJoin(java.lang.String, org.pajes.db.entity.JoinScope),
leftOuterJoin(java.lang.String, org.pajes.db.entity.JoinScope)public java.lang.Object[] getJoinParameters()
public Scope isNotNull(java.lang.String columnName)
columnName - the name of the column.
public Scope isNull(java.lang.String columnName)
columnName - the name of the column.
public Scope isNull(java.lang.String columnName,
boolean notNull)
columnName - the name of the column.notNull - if false, append "IS NULL", else if true append "IS NOT
NULL".
public java.lang.String getOrderByClause()
setOrderByColumns(java.lang.String),
getOrderByColumns()public Scope setOrderByColumns(java.lang.String columns)
columns - the comma separated list of columns that will be used in
the ORDER BY clause.
public Scope setOrderByColumns(java.lang.String[] columns)
columns - the array of column names that will be used in the ORDER
BY clause.
public java.lang.String getOrderByColumns()
setOrderByColumns(java.lang.String).
setOrderByColumns(java.lang.String),
getOrderByClause()public java.lang.Object[] getParameters()
public Scope setSelectColumns(java.lang.String columns)
columns - the comma separated list of columns that will be used in
the SELECT statement.
public Scope setSelectColumns(java.lang.String[] columns)
columns - the array of column names that will be used in the SELECT
statement.
public java.lang.String getSelectColumns()
public void setSelectTable(java.lang.String tableString)
tableString - the string representing the source table.public java.lang.String getSelectTable()
public Scope setTableAlias(java.lang.String alias)
.)).
alias - The table alias. Use null to remove the table alias.
public java.lang.String getTableAlias()
public java.lang.String getWhereClause()
getParameters()public Scope and()
public Scope between(java.lang.String columnName,
java.lang.Object lowerValue,
java.lang.Object upperValue)
columnName - the name of the column.lowerValue - the lower comparison value.upperValue - the upper comparison value.
public Scope compare(java.lang.String columnName,
java.lang.String operator,
java.lang.Object value)
columnName - the name of the column.operator - the comparison operator.value - the comparison value.
public Scope compare(Entity entity)
equalitycomparisons, joined by and operators, consisting of
the primary key values of the specified Entity and the current value.
If the Entity has no primary keys defined, all of the values assigned
to the Entity will be used.
entity - the Entity from which the column names and values will be
determined.
public Scope compare(Entity entity,
boolean initial)
equalitycomparisons, joined by and operators, consisting of
all the values assigned of the specified Entity, except those
flagged as not participating in the optimistic lock key.
entity - the Entity from which the column names and values will be
determined.initial - true if the values provided are the initial values of the
attributes.
public Scope compare(Entity entity,
boolean initial,
boolean keys)
equalitycomparisons, joined by and operators, consisting of
all the values assigned of the specified Entity, except those
flagged as not participating in the optimistic lock key.
entity - the Entity from which the column names and values will be
determined.initial - true if the values provided are the initial values of the
attributes.
public Scope compare(javax.servlet.http.HttpServletRequest request,
Manager manager,
java.lang.String operator,
boolean keys)
comparisons created by
checking the parameter names supplied on the HttpServletRequest with
the column names determined from the specified Entity Manager.
Where the name matches a column name, this method will create a compare(java.lang.String, java.lang.String, java.lang.Object) for each parameter value, using the specified operator.
Multiple values will be joined with or() statements within
appropriately placed left and right brackets. Multiple column names will be joined with and()
statements.
request - the request object from which the comparison values will
be determined.manager - the Manager object from which the column names will be
determined.operator - the comparison operator.keys - if true, limit the columns that will be included in the
scope to the primary keys. If false, any column for which a
request parameter is found will be included in the scope.
public Scope compare(javax.servlet.http.HttpServletRequest request,
Manager manager,
java.lang.String operator,
boolean keys,
boolean qualifyColumnName)
comparisons created by
checking the parameter names supplied on the HttpServletRequest with
the column names determined from the specified Entity Manager.
Where the name matches a column name, this method will create a compare(java.lang.String, java.lang.String, java.lang.Object) for each parameter value, using the specified operator.
Multiple values will be joined with or() statements within
appropriately placed left and right brackets. Multiple column names will be joined with and()
statements.
request - the request object from which the comparison values will
be determined.manager - the Manager object from which the column names will be
determined.operator - the comparison operator.keys - if true, limit the columns that will be included in the
scope to the primary keys. If false, any column for which a
request parameter is found will be included in the scope.qualifyColumnName - true uses the qualified column name, false
leaves off the table qualification.
public Scope compareColumns(java.lang.String leftColumnName,
java.lang.String operator,
java.lang.String rightColumnName)
leftColumnName - the name of the column on the left of the
comparison.operator - the comparison operator.rightColumnName - the name of the column on the right of the
comparison.
public boolean hasConditions()
public boolean hasJoins()
public boolean hasOrderBy()
public Scope in(java.lang.String columnName,
java.lang.Object[] values)
columnName - the name of the column.values - the array of values to be included.
EntityException - if the specified Object array to create the
values for the IN clause is empty.not()
public Scope in(java.lang.String columnName,
java.lang.String subSelect,
Scope subSelectScope)
columnName - the name of the column.subSelect - the "SELECT column FROM table" portion of
the sub-query.subSelectScope - the Scope object to be applied as the WHERE clause
for the sub-query.
not(),
subQuery(java.lang.String, java.lang.String, java.lang.String, org.pajes.db.entity.Scope)
public Scope innerJoin(java.lang.String table,
JoinScope scope)
table - the table on the RIGHT side of the join.scope - the scope describing the join ON clause.
public Scope leftBrace()
public Scope leftOuterJoin(java.lang.String table,
JoinScope scope)
table - the table on the RIGHT side of the join.scope - the scope describing the join ON clause.
public java.util.List lookup(java.lang.String columnName)
columnName - the name of the column.
getColumnNames()public Scope merge(Scope scope)
Note that only the WHERE clause clause is
merged: the ORDER BY clause and the SELECT columns are ignored.
scope - the Scope to be merged with this Scope.
public Scope merge(java.lang.String where,
java.lang.Object[] values)
where - the base WHERE clause. If this String starts with a
WHERE statement, it will be stripped off. Care
should be taken to ensure that the correct number of place
holders appear in this String to match the number of values
supplied the array.values - the array of comparison values. Care should be taken to
ensure that the number of values in the array matches the number
of place holders in the supplied WHERE clause string, and be in
the correct sequence in the array.
public Scope not()
in(java.lang.String, java.lang.Object[])
statement.
public Scope or()
public Scope rightBrace()
public Scope subQuery(java.lang.String columnName,
java.lang.String operator,
java.lang.String subSelect,
Scope subSelectScope)
columnName - the name of the column.operator - the comparison operator.subSelect - the "SELECT column FROM table" portion of
the sub-query.subSelectScope - the Scope object to be applied as the WHERE clause
for the sub-query.
public java.lang.String toString()
|
PAJES 2.3.9 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||