class QueryComponent extends java.lang.Object implements QueryConstants
Modifier and Type | Class and Description |
---|---|
(package private) static class |
QueryComponent.ServerJoinData
Information required to create a server-side join between two tables.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
args
Base substitution arguments for this component
|
private RecordBuffer |
buffer
Record buffer updated by this component of the query
|
private java.lang.Object[] |
currentArgs
Intermediately resolved arguments for this component
|
private java.util.Map<FieldReference,BaseDataType> |
dynamicFilters
The list of dynamic filters.
|
private HQLPreprocessor |
hqlPreprocessor
HQL preprocessor
|
private boolean |
idOnly
Whether query should return primary key ID only, or entire DMO
|
private java.lang.String |
indexInfo
Index information string as it is returned by INDEX-INFORMATION.
|
private int |
iteration
Iteration/retrieval mode (first, last, next, etc.)
|
private AbstractJoin |
join
Helper object for a join via a foreign key relation
|
private LockType |
lockType
Record lock type
|
private boolean[] |
nullArguments
Position of
null elements in argument list with which HQL was preprocessed |
private boolean |
outer
true if component forms outer join with previous component; else false |
private Joinable |
query
Joinable query which contains this query component
|
private java.lang.String[] |
referenceSubs
Array of field reference names and nulls used to replace substitution parameters when
converting a nested looping (client-side) join to a server-side join
|
private java.util.Set<RecordBuffer> |
relatedBuffers
Set of related buffers, if component participates in a server-side join
|
private java.lang.String |
sort
Order by clause for FIRST/LAST iteration components
|
private SortIndex |
sortIndex
Sort index associated with this query component
|
private boolean |
top
Is this component the top/outermost among the query's components?
|
private java.lang.String |
where
Original where clause, before preprocessing
|
CURRENT, FIRST, LAST, NEXT, NONE, PREVIOUS, RETRIEVE_MODES, UNIQUE
Modifier | Constructor and Description |
---|---|
protected |
QueryComponent(Joinable query,
BufferReference proxy,
AbstractJoin join,
java.lang.String where,
java.lang.String indexInfo,
LockType lockType,
java.lang.Object[] args,
int iteration,
boolean outer)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
addDynamicFilter(FieldReference fr,
BaseDataType val)
Adds a new constraint term to the where predicate of this query, effectively filtering out
any rows whose referenced field does not match the requested value.
|
(package private) void |
clearDynamicFilters()
Clears any dynamically filters added at runtime.
|
(package private) java.util.Iterator<java.lang.String> |
compositeJoins()
Get an iterator on the ANSI-style join subexpressions which must be
merged by the enclosing query into the overall HQL query statement
in order to properly join associated composite element lists (if
any).
|
protected java.lang.Object[] |
filterArgs(HQLPreprocessor preproc)
Get the (mostly) resolved query substitution parameters required by
this query component and return them in an array.
|
protected java.lang.Object[] |
getArgs()
Get substitution arguments for this component, resolving them first if necessary.
|
(package private) RecordBuffer |
getBuffer()
Get record buffer for this component of the query.
|
protected Joinable |
getEnclosingQuery()
Get the query which encloses this component.
|
protected HQLPreprocessor |
getHQLPreprocessor()
Get the HQL preprocessor associated with this component.
|
(package private) java.lang.String |
getIndexInfo()
Get the index information string as it is returned by INDEX-INFORMATION.
|
(package private) int |
getIteration()
Get iteration/retrieval mode (first, last, next, etc.).
|
(package private) AbstractJoin |
getJoin()
Get helper object for a join via a foreign key relation, if any.
|
(package private) LockType |
getLockType()
Get lock type for records fetched into this component's buffer.
|
(package private) java.lang.String |
getOriginalWhere()
Get restriction criteria in HQL where clause format for this
component (before the HQL preprocessor has preprocessed it).
|
(package private) java.lang.Object[] |
getRawArgs()
Get unresolved substitution arguments for this component, if any.
|
protected RecordBuffer[] |
getReferencedBuffers()
Get an array of all record buffers referenced by this query, including those directly
involved in the query, as well as those (if any) indirectly referenced by inlined,
converted, CAN-FIND expressions, and those related via a server-side join (if any).
|
(package private) java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
getRestrictionProperties()
Get an unmodifiable map of DMO entity names to sets of the names of
the DMO properties used as restriction criteria in the preprocessed
where clause.
|
(package private) SortIndex |
getSortIndex()
Get sort criteria in HQL order by clause format for this component.
|
(package private) HQLExpression |
getWhere()
Get restriction criteria in HQL where clause format for this component (pre-processed).
|
protected boolean |
isIdOnly()
Indicate whether the query component should return a primary key ID
only, or the entire DMO instance.
|
(package private) boolean |
isOuter()
Indicate whether this component is joined with the previous component
via a left outer join.
|
protected HQLPreprocessor |
prepareHQLPreprocessor(java.lang.Object[] queryArgs)
Create the
HQLPreprocessor which backs this component. |
(package private) static QueryComponent.ServerJoinData |
prepareServerJoinData(java.util.List<? extends QueryComponent> joinList,
RecordBuffer buffer,
AbstractJoin join,
java.lang.Object[] args)
Prepare the information needed to convert a nested looping (client-side) join of two
tables to a server-side join of those tables.
|
protected void |
resetArgs()
Reset current arguments, so that they will need to be resolved the next time they are
requested.
|
protected void |
resetHQLPreprocessor()
Reset the HQL preprocessor, so that it needs to be recreated the next
time it is requested.
|
protected java.lang.Object |
resolveArg(java.lang.Object arg)
Resolve a single resolvable query substitution parameter, with the exception of
FieldReference s. |
protected java.lang.Object[] |
resolveArgs()
Resolve all resolvable query substitution parameters, with the exception of
FieldReference s. |
(package private) void |
setIteration(int iteration,
java.lang.String sort)
Set iteration/retrieval mode (first, last, next, etc.).
|
(package private) void |
setNotTop()
Mark this query component as being nested within an outer component (i.e., not the top
component in a nested looping query).
|
protected void |
setReferenceSubs(java.lang.String[] referenceSubs)
Set the array of field reference names and nulls used when converting a nested loop where
clause to a server-join where clause.
|
protected void |
setRelatedBuffers(java.util.Set<RecordBuffer> relatedBuffers)
Store a set of outer component buffers to which this component is related through a server
side join.
|
(package private) void |
setSortIndex(SortIndex sortIndex)
Set sort criteria in HQL order by clause format for this component.
|
private final Joinable query
private final java.lang.String where
private final RecordBuffer buffer
private final AbstractJoin join
private final LockType lockType
private final java.lang.Object[] args
private final boolean outer
true
if component forms outer join with previous component; else false
private final boolean idOnly
private boolean top
private java.lang.String[] referenceSubs
private java.util.Set<RecordBuffer> relatedBuffers
private int iteration
private java.lang.String sort
private HQLPreprocessor hqlPreprocessor
private boolean[] nullArguments
null
elements in argument list with which HQL was preprocessedprivate SortIndex sortIndex
private java.lang.Object[] currentArgs
private java.lang.String indexInfo
private java.util.Map<FieldReference,BaseDataType> dynamicFilters
protected QueryComponent(Joinable query, BufferReference proxy, AbstractJoin join, java.lang.String where, java.lang.String indexInfo, LockType lockType, java.lang.Object[] args, int iteration, boolean outer)
query
- Enclosing query.proxy
- DMO proxy which references the record buffer updated by
this component of the query.join
- Helper object for a join via a foreign key relation. May
be null
.where
- Restriction criteria in HQL where clause format.indexInfo
- Index information string as it is returned by INDEX-INFORMATION.
May be null
if it is not an OPEN QUERY case or if
you don't need debug information about selected indexes.lockType
- Requested record lock type.args
- Default (unresolved) query substitution arguments.iteration
- Type of iteration: FIRST, LAST, NEXT, PREVIOUS, or UNIQUE.outer
- true
if this component is joined with the
previous component via an outer join; false
if there is no previous component, or if this component is
joined with the previous component via an inner join.static QueryComponent.ServerJoinData prepareServerJoinData(java.util.List<? extends QueryComponent> joinList, RecordBuffer buffer, AbstractJoin join, java.lang.Object[] args)
joinList
- List of enclosing query components, from outermost to innermost (if any), from the
original nested query. Does not include the component currently being visited.buffer
- Record buffer associated with the query component currently being visited.join
- Original join helper object which joins the current query component with an outer
component or external buffer.args
- Query substitution arguments for the where clause of the current query component.protected HQLPreprocessor getHQLPreprocessor() throws PersistenceException
PersistenceException
- if the preprocessor must first be created, and there is an error during
its creation.protected HQLPreprocessor prepareHQLPreprocessor(java.lang.Object[] queryArgs) throws PersistenceException
HQLPreprocessor
which backs this component. If this component
represents a nested FIRST or LAST iteration, the where clause portion associated with this
component will be embedded within a subselect. To avoid conflicts with the enclosing
where clause, this portion will be emitted without DMO alias qualifiers for its references
to the associated buffer.queryArgs
- Query substitution parameters used in the preprocessor's creation.PersistenceException
- if there is an error creating the preprocessor.protected RecordBuffer[] getReferencedBuffers()
protected java.lang.Object[] getArgs() throws PersistenceException
PersistenceException
- if there is any error creating the HQL preprocessor, which
is necessary to properly filter/order the arguments.protected void resetArgs()
protected void resetHQLPreprocessor()
protected java.lang.Object[] filterArgs(HQLPreprocessor preproc)
FieldReference
parameters which are actually resolved by
the query itself, when the query's full HQL is being assembled and
when the final array of substitution parameters is prepared.preproc
- HQL preprocessor which maps parameter indices to the
original parameters, in case any were changed during HQL
where clause preprocessing.protected void setReferenceSubs(java.lang.String[] referenceSubs)
referenceSubs
- Array of field reference names and nulls.protected void setRelatedBuffers(java.util.Set<RecordBuffer> relatedBuffers)
relatedBuffers
- Set of related buffers; may be null
.protected java.lang.Object[] resolveArgs()
FieldReference
s. The latter are only query substitution parameters when it
is necessary to join the enclosing query's results with those of a related query, as
would be the case when each query is a component of a CompoundQuery
.FieldReference
resolvable parameters have been resolved.protected java.lang.Object resolveArg(java.lang.Object arg)
FieldReference
s.arg
itself if it is an
instance of FieldReference
.protected boolean isIdOnly()
true
for a projection query which returns only
the ID; false
to fetch the entire DMO.protected Joinable getEnclosingQuery()
RecordBuffer getBuffer()
java.lang.String getOriginalWhere()
AbstractJoin getJoin()
null
if there is none.HQLExpression getWhere() throws PersistenceException
PersistenceException
- if there is an error creating the HQLPreprocessor
from which the
preprocessed where clause is retrieved.boolean addDynamicFilter(FieldReference fr, BaseDataType val)
new-where := (fr = val) AND (old-query)
.
Note: The constraints are exclusive meaning that if constraints will be added for same field of same buffer, the query will return an empty result because the field cannot be at the same time equals to two different values.
Use clearDynamicFilters()
to clean all dynamically added criteria and restore the
sorting order of the query to its original form.
fr
- A reference to field used as filtering criterion. Only the rows that matches the
specified value for this field will be selected. Must not be null
.val
- The filtering value for this constraint. Can be null
or unknown
, in
which case the SQL null
value will be assumed. In this case the predicate
will look like:
new-where := (fr IS NULL) AND (old-query)
true
if the filtering constraint was successfully added. If the field
reference is not related to the buffer(s) of this query, false
is returned.void clearDynamicFilters()
LockType getLockType()
java.lang.Object[] getRawArgs()
null
if none.int getIteration()
QueryConstants
.void setIteration(int iteration, java.lang.String sort) throws PersistenceException
iteration
- Retrieval mode from QueryConstants
.sort
- Order by clause which should be associated with this query component. Must be
non-null
for iteration types FIRST
and
LAST
.java.lang.IllegalArgumentException
- if iteration
type is FIRST
or LAST
, but
sort
is null
.PersistenceException
- if sort
clause is invalid.void setNotTop()
boolean isOuter()
true
if an outer join, false
if
an inner join or no join (i.e., no previous component).java.util.Iterator<java.lang.String> compositeJoins() throws PersistenceException
null
.PersistenceException
- if there is an error creating the
HQLPreprocessor
from which the composite join
subexpressions are gathered.java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getRestrictionProperties() throws PersistenceException
null
if the where clause for this component
contained no restriction properties.PersistenceException
- if there is an error creating the
HQLPreprocessor
from which the restriction
properties are gathered.SortIndex getSortIndex()
void setSortIndex(SortIndex sortIndex)
sortIndex
- Sort index.java.lang.String getIndexInfo()