public final class HQLBundle
extends java.lang.Object
Each bundle contains a list of one or more HQL statements which are
executed in sequence by a RandomAccessQuery
instance to obtain
a result for a specific record retrieval (e.g., first, last, next, etc.)
request. These statements include as their restriction criteria (i.e.,
where clause), the query's original, base where clause (if any), augmented
with sequentially less-specific restriction criteria composed using the
query's sort criteria. If any parameterized substitutions are necessary
to supply these statements with data extracted from the current record,
the appropriate list of "getter" methods is supplied by the bundle as
well.
To satisfy the random access query's single-record retrieval semantic, each statement is executed in turn, until a non-null result is returned. For each statement, as many of the getter methods are executed against the current record DMO, as are necessary to provided the substitutions required for that statement (for the augmented portion only). These values are added to the existing parameter array (if any) for the base where clause, at the time the statement is executed.
For example, given the following query criteria and a request to retrieve the "next" record...
DMO: Customer alias: customer where: customer.number = ? and customer.creditLimit = ? order by: customer.name asc
...the HQL bundle might contain the following list of HQL statements...
1) from Customer as customer where (customer.number = ? and customer.creditLimit = ?) and (customer.name = ? and customer.id > ?) 2) from Customer as customer where (customer.number = ? and customer.creditLimit = ?) and (customer.name > ?)
...and the following list of DMO "getter" methods...
1) Customer.getName() 2) Customer.getId()
The methods are only used to satisfy the customer.name
and
customer.id
substitutions; the customer.number
and customer.creditLimit
parameter substitution values must
be provided by the client code which creates the query.
A bundle is unaware of the navigation/retrieval mode with which it has been tasked (e.g., first, last, next, etc.); it is simply a container for the information described above.
HQLHelper
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
dirtyStatements
Parallel set of HQL statements for dirty database use
|
private java.util.List<java.lang.reflect.Method> |
getters
DMO getter methods used to get sort criteria parameter values
|
private ParameterIndices |
paramIndices
Mapping of indices in the array of query substitution parameters
|
private java.util.List<java.lang.String> |
statements
HQL statements to be executed to satisfy a record retrieval request
|
Constructor and Description |
---|
HQLBundle()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addGetter(java.lang.reflect.Method getter)
Add a DMO getter method to the end of the list of methods stored in
this bundle.
|
(package private) void |
addStatement(java.lang.String statement,
boolean dirty)
Add an HQL statement to the end of the list of primary or dirty
statements stored in this bundle.
|
(package private) void |
freeze()
Freeze this bundle so that its internal data structures can no longer be
modified.
|
java.util.List<java.lang.String> |
getDirtyStatements()
Get an unmodifiable view on the list of HQL statements in this bundle,
which are for dirty database use.
|
(package private) ParameterIndices |
getParameterIndices()
Get the
ParameterIndices object associated with this
bundle. |
(package private) java.lang.String |
getStatement(int index,
boolean dirty)
Retrieve the HQL statement at a particular index in the list.
|
(package private) java.util.Iterator<java.lang.reflect.Method> |
getters()
Get an iterator on the DMO getter methods, if any, stored in this
bundle.
|
(package private) int |
gettersSize()
Return the number of DMO getter methods stored in this bundle.
|
(package private) void |
setParameterIndices(ParameterIndices paramIndices)
Set the
ParameterIndices object associated with this
bundle. |
(package private) void |
setStatement(int index,
java.lang.String statement,
boolean dirty)
Replace the HQL statement at the specified index with a new statement.
|
(package private) java.util.Iterator<java.lang.String> |
statements()
Get an iterator on the list of HQL statements in this bundle.
|
(package private) int |
statementsSize()
Get the number of HQL statements stored in this bundle.
|
java.lang.String |
toString()
Get a string representation of the internal state of this object,
primarily for debugging purposes.
|
private java.util.List<java.lang.reflect.Method> getters
private java.util.List<java.lang.String> statements
private java.util.List<java.lang.String> dirtyStatements
private ParameterIndices paramIndices
public java.util.List<java.lang.String> getDirtyStatements()
public java.lang.String toString()
toString
in class java.lang.Object
java.util.Iterator<java.lang.String> statements()
int statementsSize()
java.lang.String getStatement(int index, boolean dirty)
index
- Index of the required statement.dirty
- true
to retrieve statement for dirty database
dialect; false
to get primary statement.java.lang.ArrayIndexOutOfBoundsException
- if index
is invalid.void setStatement(int index, java.lang.String statement, boolean dirty)
index
- Index at which to replace statement.statement
- New HQL statement.dirty
- true
to set statement for dirty database dialect;
false
to set primary statement.java.lang.ArrayIndexOutOfBoundsException
- if index
is invalid.void addStatement(java.lang.String statement, boolean dirty)
statement
- HQL statement to add.dirty
- true
to add statement for dirty database dialect;
false
to add primary statement.int gettersSize()
java.util.Iterator<java.lang.reflect.Method> getters()
void addGetter(java.lang.reflect.Method getter)
getter
- Accessor method.ParameterIndices getParameterIndices()
ParameterIndices
object associated with this
bundle. This object maintains an array of zero-based indices into the
array of query substitution arguments for the base (i.e., unaugmented)
where clause, as it exists after preprocessing is complete. This
additional level of indirection is necessary because the query
substitution placeholders may have been reordered within the HQL where
clause expression during the HQL preprocessing rewrite step, and some
parameters may have been inlined into the where clause.void setParameterIndices(ParameterIndices paramIndices)
ParameterIndices
object associated with this
bundle. This object maintains an array of zero-based indices into the
array of query substitution arguments for the base (i.e., unaugmented)
where clause, as it exists after preprocessing is complete. This
additional level of indirection is necessary because the query
substitution placeholders may have been reordered within the HQL where
clause expression during the HQL preprocessing rewrite step, and some
parameters may have been inlined into the where clause.paramIndices
- An object which provides a mapping of indices into the query
substitution parameter list.void freeze()