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 RecordBuffer |
definition
For bound buffers, this is the definition buffer
|
private java.lang.Object[] |
dfArgs
The substitution arguments with dynamic filtered ones inserted in front.
|
private java.lang.String |
dfWhere
The where clause, including the dynamic filters, before preprocessing.
|
private java.util.Map<FieldReference,BaseDataType> |
dynamicFilters
The list of dynamic filters.
|
private java.util.Map<FieldReference,java.lang.String> |
dynamicFormats
The list of format used by dynamic filters.
|
private FQLPreprocessor |
fqlPreprocessor
FQL 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 FQL was preprocessed |
private java.lang.Object[] |
origArgs
Original arguments before query substitution arguments preprocessing.
|
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.util.function.Supplier<java.lang.String> |
translateWhere
A function to translate the where clause, just before it gets executed.
|
private java.lang.String |
where
Original where clause, before preprocessing
|
CURRENT, FIRST, ITERATE, LAST, NEXT, NONE, PREVIOUS, RETRIEVE_MODES, UNIQUE| Modifier | Constructor and Description |
|---|---|
protected |
QueryComponent(Joinable query,
BufferReference proxy,
AbstractJoin join,
java.lang.String where,
java.util.function.Supplier<java.lang.String> translateWhere,
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,
java.lang.String format)
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 FQL query statement
in order to properly join associated composite element lists (if
any).
|
(package private) void |
enableTranslateWhere(java.util.function.Function<java.lang.String,java.lang.String> translate)
Enable the
translateWhere for this component (if not already enabled). |
protected java.lang.Object[] |
filterArgs(FQLPreprocessor 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.
|
(package private) RecordBuffer |
getDefinitionBuffer()
Get definition record buffer for this component of the query.
|
protected Joinable |
getEnclosingQuery()
Get the query which encloses this component.
|
protected FQLPreprocessor |
getHQLPreprocessor()
Get the FQL 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 FQL where clause format for this component (before the FQL
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 FQL order by clause format for this component.
|
(package private) FQLExpression |
getWhere()
Get restriction criteria in FQL 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 FQLPreprocessor |
prepareHQLPreprocessor(java.lang.Object[] queryArgs)
Create the
FQLPreprocessor 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.
|
(package private) void |
processDynamicFilters()
Processes all dynamic filters altering the original
where predicate and inserting
optional substitution arguments in the list of static ones. |
protected void |
resetArgs(boolean forceOrigArgs)
Reset current arguments, so that they will need to be resolved the next time they are
requested.
|
protected void |
resetHQLPreprocessor()
Reset the FQL preprocessor, so that it needs to be recreated the next time it is requested.
|
private java.lang.Object |
resolveArg(java.lang.Object arg)
Resolve a single resolvable query substitution parameter, with the exception of
FieldReferences. |
private java.lang.Object[] |
resolveArgs()
Resolve all resolvable query substitution parameters, with the exception of
FieldReferences. |
(package private) void |
setBuffer(RecordBuffer buffer)
Set the record buffer for this component's query.
|
(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 FQL order by clause format for this component.
|
protected void |
translateWhere()
Translate the
where clause, using the translateWhere function. |
private final Joinable query
private java.lang.String where
private java.util.function.Supplier<java.lang.String> translateWhere
private java.lang.String dfWhere
private RecordBuffer buffer
private final RecordBuffer definition
private final AbstractJoin join
private final LockType lockType
private final java.lang.Object[] origArgs
private final java.lang.Object[] args
private java.lang.Object[] dfArgs
private final boolean outer
true if component forms outer join with previous component; else falseprivate 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 FQLPreprocessor fqlPreprocessor
private boolean[] nullArguments
null elements in argument list with which FQL was preprocessedprivate SortIndex sortIndex
private java.lang.Object[] currentArgs
private java.lang.String indexInfo
private java.util.Map<FieldReference,BaseDataType> dynamicFilters
private java.util.Map<FieldReference,java.lang.String> dynamicFormats
protected QueryComponent(Joinable query, BufferReference proxy, AbstractJoin join, java.lang.String where, java.util.function.Supplier<java.lang.String> translateWhere, 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 FQL where clause format.translateWhere - A function to translate the where clause, just before it gets executed.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 void translateWhere()
where clause, using the translateWhere function.protected FQLPreprocessor getHQLPreprocessor() throws PersistenceException
PersistenceException - if the preprocessor must first be created, and there is an error during its creation.protected FQLPreprocessor prepareHQLPreprocessor(java.lang.Object[] queryArgs) throws PersistenceException
FQLPreprocessor 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 FQL preprocessor, which
is necessary to properly filter/order the arguments.protected void resetArgs(boolean forceOrigArgs)
forceOrigArgs - Flag indicating that the original arguments used at the construction of the query must be
re-calculated.protected void resetHQLPreprocessor()
protected java.lang.Object[] filterArgs(FQLPreprocessor preproc)
FieldReference parameters which are actually resolved by
the query itself, when the query's full FQL is being assembled and
when the final array of substitution parameters is prepared.preproc - FQL preprocessor which maps parameter indices to the original parameters, in case any were
changed during FQL 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.void processDynamicFilters()
where predicate and inserting
optional substitution arguments in the list of static ones.
This method must be always called before accessing the where predicate or substitutions arguments, otherwise the dynamic filtering will not be correctly applied.
private java.lang.Object[] resolveArgs()
FieldReferences. 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.private java.lang.Object resolveArg(java.lang.Object arg)
FieldReferences.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()
void enableTranslateWhere(java.util.function.Function<java.lang.String,java.lang.String> translate)
translateWhere for this component (if not already enabled).translate - The translation function, which will receive as argument the where predicate.RecordBuffer getBuffer()
void setBuffer(RecordBuffer buffer)
buffer - Record buffer.RecordBuffer getDefinitionBuffer()
java.lang.String getOriginalWhere()
AbstractJoin getJoin()
null if there is none.FQLExpression getWhere() throws PersistenceException
PersistenceException - if there is an error creating the FQLPreprocessor from which the
preprocessed where clause is retrieved.boolean addDynamicFilter(FieldReference fr, BaseDataType val, java.lang.String format)
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)
format - The format to be used when comparing values. The reason for this parameter is that
for some datatype (ex: decimal) the on-screen value can be different from
the database (because of rounding).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
FQLPreprocessor 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 FQLPreprocessor from which the restriction
properties are gathered.SortIndex getSortIndex()
void setSortIndex(SortIndex sortIndex)
sortIndex - Sort index.java.lang.String getIndexInfo()