public final class PresortCompoundQuery extends CompoundQuery implements Presortable, PresortDelegate
Upon the first request for a record, this query preselects all of its
results in the order prescribed by each of its individual query components.
It then sorts these results according to the sort criteria provided by one
of the addSortCriterion() method variants. These results are
cached. The appropriate record is returned for the original request, and
thereafter, the cache is accessed for all subsequent record retrieval
requests. The cache contains only primary key ID values; the actual
records associated with these are retrieved on demand.
| Modifier and Type | Class and Description |
|---|---|
private static class |
PresortCompoundQuery.CursorResults
An implementation of the
Results interface which is backed
by a dynamic Cursor object. |
P2JQuery.Parameter, P2JQuery.ParamResolver, P2JQuery.QueryEventListener, P2JQuery.QueryOpenedListener| Modifier and Type | Field and Description |
|---|---|
private PresortCompoundQuery.CursorResults |
cursorResults
The cached results stored in the cursor, wrapped by
Results interface. |
private Presorter |
sorter
Helper which sorts preselected, unsorted results
|
currentRowDeleted, foundFirst, unregisterOnCleanupcursorclosed, dynamicPredicate, errorHelper, excluded, included, indexedReposition, inverseSorting, lenientOffEnd, outer, parameterFilterCURRENT, FIRST, ITERATE, LAST, NEXT, NONE, PREVIOUS, RETRIEVE_MODES, UNIQUE| Constructor and Description |
|---|
PresortCompoundQuery()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addComponent(Joinable query,
int iteration,
boolean outer)
Add a joinable query to the compound query, and specify the nature of
the iteration which will be performed (first, last, next, etc.) on that
component, when the compound query is iterated.
|
void |
addDynamicSortCriterion(Resolvable sort,
boolean ascending)
Add a single dynamic sort criterion, in the form of a
Resolvable object which is
resolved at runtime. |
void |
addSortCriterion(Resolvable sort)
Add a single sort criterion, in the form of a
Resolvable
object which is resolved at sort time. |
void |
addSortCriterion(Resolvable sort,
boolean descending)
Add a single sort criterion, in the form of a
Resolvable
object which is resolved at runtime. |
void |
clearDynamicSortCriteria()
Clears all sort criteria added dynamically.
|
void |
clearResults()
Clear the current results from the query, so the same query instance can be executed again, without
having to
re-open it. |
protected PresortCompoundQuery.CursorResults |
cursorAsResults()
Get the cached results stored in the cursor, wrapped by
Results interface. |
void |
enableBreakGroups()
Enable all sort criteria set for this query to act as break group
categories.
|
RecordBuffer[] |
getRecordBuffers()
Access the record buffers manipulated by this query, in order from
left-most (outermost) table of the query's join (if any) to right-most
(innermost) table.
|
Results |
getSortedResults()
Access the current, sorted results for this query.
|
PresortCompoundQuery |
initialize()
Initialization logic.
|
PresortCompoundQuery |
initialize(boolean resolveOnce,
boolean preselect)
Initialization logic.
|
PresortCompoundQuery |
initialize2f()
Initialization logic.
|
logical |
isFirst()
Determine whether the query result row currently being visited is the
first row in the presorted results list.
|
logical |
isFirstOfGroup(int level)
Determine whether the query result row currently being visited is the first row of the
query's result set or the first row within a break group whose category is identified by
the specified BREAK-BY level.
|
logical |
isFirstOfGroup(integer level)
Determine whether the query result row currently being visited is the first row of the
query's result set or the first row within a break group whose category is identified by
the specified BREAK-BY level.
|
logical |
isFirstOfGroup(Resolvable key)
Determine whether the query result row currently being visited is the
first row within a break group whose category is identified by the
specified resolvable object.
|
logical |
isLast()
Determine whether the query result row currently being visited is the
last row in the presorted results list.
|
protected boolean |
isLastOfBreakGroup(Resolvable key)
Determine whether the query result row currently being visited is the
last row within a break group whose category is identified by the
specified resolvable object.
|
logical |
isLastOfGroup(int level)
Determine whether the query result row currently being visited is the last row of the
query's result set or the last row within a break group whose category is identified by
the specified BREAK-BY level.
|
logical |
isLastOfGroup(integer level)
Determine whether the query result row currently being visited is the last row of the
query's result set or the last row within a break group whose category is identified by
the specified BREAK-BY level.
|
logical |
isLastOfGroup(Resolvable key)
Determine whether the query result row currently being visited is the
last row within a break group whose category is identified by the
specified resolvable object.
|
protected boolean |
isNewBreakGroup(Resolvable key)
Determine whether the query result row currently being visited is the
first row within a break group whose category is identified by the
specified resolvable object.
|
boolean |
isPresort()
Indicate whether the query is of presort type.
|
protected boolean |
isPresorted()
Determines if the query is presorted, i.e.
|
boolean |
next(boolean iterating,
LockType lockType)
Retrieve the next virtual, composite row of results for the compound
query, overriding the lock type to apply to each underlying query.
|
protected void |
presort()
Presort the results stored in the cursor.
|
addComponent, addComponent, addCompoundComponent, addDynamicFilter, addExternalBuffers, afterReposition, canOptimize, cleanup, clearDynamicFilters, close, close, createResultListEntry, current, current, deleteResultListEntry, first, first, first, first, getBreakValue, getCombinedExecutionTime, getCombinedFqls, getOffEnd, getOffEndListeners, getOriginalComponents, getTableCount, hintFullResults, indexInformation, initReferenceRowSupport, iterate, last, last, last, last, loadByValues, loadRowAtCursor, next, next, next, notifyRepositionListeners, open, peekFirst, peekLast, peekNext, peekPrevious, postponeAccumulation, preselectResults, previous, previous, previous, previous, recordBuffers, registerCleaner, releaseAllBuffers, releaseBuffers, restoreAccumulation, retrieve, retrieve, setBrowsed, setDataRelation, setScrolling, setSkipDeletedRecord, setStandalone, stateChanged_isOffEnd, backward, backward, currentRow, currentRowImpl, forward, forward, incrementMoves, isNativelyPreselect, isPreselect, isScrolling, reposition, reposition, repositionByID, repositionByID, repositionByID, reset, resetScrolling, size, verifyScrolling_getNext, _isSkipDeletedRecord, accumulate, addAccumulator, addAccumulator, addBuffer, addBuffer, addQueryEventListener, addRepositionListener, afterReposition, afterReposition, bufferHandle, bufferHandle, bufferHandle, bufferHandle, bufferHandle, buffersMatch, changeForwardOnly, changeForwardOnly, deleteResultListEntry, exclude, forwardOnly, getCache, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getDataRelation, getDefaultLock, getErrorHelper, getExternalBuffers, getExternalBuffersDefs, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getLast, getLast, getLast, getLast, getLast, getLast, getLast, getLast, getNext, getNext, getNext, getNext, getNext, getNext, getNext, getNumResults, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getReferencedBuffers, hasAccumulators, hasAny, hasAny, hasAny, hasAny, hasOne, hasOne, hasOne, hasOne, include, indexInformation, indexInformation, isBrowsed, isDynamicPredicate, isErrorIfNull, isFatalError, isFetchOnReposition, isFillingBrowseRows, isIndexedReposition, isIterating, isLenientOffEnd, isOffEnd, isOmitAlias, isOpen, isRepositionNotificationActive, isSkipDeletedRecord, isStandalone, notifyQueryCloseListeners, notifyQueryOpenListeners, numBuffers, numResults, numResults, prepare, prepare, prepareFetch, prepareString, preprocessSubstitutionArguments, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, removeRepositionListener, setBuffers, setBuffers, setCache, setCache, setDynamicPredicate, setErrorIfNull, setFatalError, setFetchOnReposition, setFillingBrowseRows, setIndexedReposition, setIterating, setLenientOffEnd, setOmitAlias, setOuter, setParameterFilter, setPresort, silentCurrent, silentCurrent, silentFirst, silentFirst, silentLast, silentLast, silentNext, silentNext, silentPrevious, silentPrevious, silentUnique, silentUnique, translateSort, translateSort, translateWhereclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait_getNext, addAccumulator, addAccumulator, addQueryEventListener, addRepositionListener, changeForwardOnly, changeForwardOnly, deleteResultListEntry, exclude, forwardOnly, getBasicLogging, getCache, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getDataRelation, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getJoin, getLast, getLast, getLast, getLast, getLast, getLast, getLast, getLast, getNext, getNext, getNext, getNext, getNext, getNext, getNext, getNext, getNumResults, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, getPrevious, hasAny, hasAny, hasAny, hasAny, hasOne, hasOne, hasOne, hasOne, include, indexInformation, indexInformation, isBrowsed, isDynamicPredicate, isFetchOnReposition, isFillingBrowseRows, isFindByRowid, isIndexedReposition, isIterating, isOffEnd, isSkipDeletedRecord, isStandalone, notifyQueryCloseListeners, notifyQueryOpenListeners, prepare, prepare, prepareString, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, queryRepositionByID, removeRepositionListener, resetQuery, setBasicLogging, setBasicLogging, setCache, setCache, setDynamicPredicate, setErrorIfNull, setFetchOnReposition, setFillingBrowseRows, setIndexedReposition, setIterating, setLenientOffEnd, setParameterFilter, setPresort, unique, uniqueaddBuffer, addBuffer, addBuffer, addBuffer, bufferHandle, bufferHandle, bufferHandle, bufferHandle, bufferHandle, numBuffers, setBuffers, setBuffers, setBuffersprivate Presorter sorter
private PresortCompoundQuery.CursorResults cursorResults
Results interface.public PresortCompoundQuery()
initialize() is
called.public void clearResults()
re-open it.clearResults in interface P2JQueryclearResults in class CompoundQuerypublic PresortCompoundQuery initialize(boolean resolveOnce, boolean preselect)
This code is intentionally separated from the constructor. The purpose of this separation is to allow construction to occur in the prior scope while initialization can still occur within a method or lambda that is inside the next block's scope.
initialize in class CompoundQueryresolveOnce - true to resolve arguments once, up front, or on every loop cycle.preselect - true to force preselection of all results; false otherwise.public PresortCompoundQuery initialize()
This code is intentionally separated from the constructor. The purpose of this separation is to allow construction to occur in the prior scope while initialization can still occur within a method or lambda that is inside the next block's scope.
public PresortCompoundQuery initialize2f()
This code is intentionally separated from the constructor. The purpose of this separation is to allow construction to occur in the prior scope while initialization can still occur within a method or lambda that is inside the next block's scope.
initialize2f in class CompoundQuerypublic void addComponent(Joinable query, int iteration, boolean outer)
outer.addComponent in class CompoundQueryquery - Query which will perform the fundamental work for this
component when the compound query is iterated.iteration - A constant indicating the type of work
to be performed upon an iteration of the compound query. This
parameter determines whether the underlying query will be asked
to perform a first, last, next, previous, or unique record
retrieval.outer - true if this component should be joined to the
previously added component via a left outer join;
false if an inner join is required. Note that
adding an inner join component will cause any previously added
components added as outer joins to be reset to inner joins.java.lang.IllegalStateException - if this method is invoked during an iteration cycle.CompoundQuery.iterate()public RecordBuffer[] getRecordBuffers()
getRecordBuffers in interface P2JQuerygetRecordBuffers in interface Presortablepublic void addSortCriterion(Resolvable sort)
Resolvable
object which is resolved at sort time. It is the value of the resolved
result which is used for the sort.
The sort is ascending, from lowest resolved value to highest.
addSortCriterion in interface PresortDelegatesort - A resolvable object whose resolved result is used for sorting.public void addSortCriterion(Resolvable sort, boolean descending)
Resolvable
object which is resolved at runtime. It is the value of the resolved
result which is used for the sort.addSortCriterion in interface PresortDelegatesort - A resolvable object whose resolved result is used for sorting.descending - if true, the sort is descending, from highest
resolved value to lowest; otherwise, the sort is ascending.public void addDynamicSortCriterion(Resolvable sort, boolean ascending)
Resolvable object which is
resolved at runtime. It is the value of the resolved result which is used for the sort.
Unlike addSortCriterion(com.goldencode.p2j.util.Resolvable) methods, the criterion is added with higher priority.
addDynamicSortCriterion in interface PresortDelegatesort - A resolvable object whose resolved result is used for sorting.ascending - if true, the sort is ascending, from lowest resolved value to highest;
otherwise, the sort is descending.public void clearDynamicSortCriteria()
clearDynamicSortCriteria in interface PresortDelegatepublic void enableBreakGroups()
enableBreakGroups in interface PresortDelegatepublic logical isFirst()
isFirst in interface PresortDelegatetrue if the current result row is the first row,
else false.public logical isFirstOfGroup(Resolvable key)
isFirstOfGroup in interface PresortDelegatekey - Break group category key. Must be the same object reference
as was specified previously when invoking one of the
addSortCriterion method variants.true if break groups are enabled and current row
is first in the specified break group;
false if break groups have not been enabled or
current row is not first in the specified break group.public logical isFirstOfGroup(integer level)
isFirstOfGroup in interface P2JQueryisFirstOfGroup in interface PresortDelegatelevel - Break group level, where 0 is the whole query, 1 is the first BREAK-BY sort
criterion, etc. Must not be negative or greater than the number of sort criteria.true if the current row is first in the result set or within the specified
break group; else false.public logical isFirstOfGroup(int level)
isFirstOfGroup in interface P2JQuerylevel - Break group level, where 0 is the whole query, 1 is the first BREAK-BY sort
criterion, etc. Must not be negative or greater than the number of sort criteria.true if the current row is first in the result set or within the specified
break group; else false.public logical isLast()
isLast in interface PresortDelegatetrue if the current result row is the last row,
else false.public boolean isPresort()
isPresort in interface P2JQueryisPresort in class AbstractQuerytrue if the query is of presort type..public logical isLastOfGroup(Resolvable key)
isLastOfGroup in interface PresortDelegatekey - Break group category key. Must be the same object reference
as was specified previously when invoking one of the
addSortCriterion method variants.true if break groups are enabled and current row
is last in the specified break group;
false if break groups have not been enabled or
current row is not last in the specified break group.public logical isLastOfGroup(integer level)
isLastOfGroup in interface P2JQueryisLastOfGroup in interface PresortDelegatelevel - Break group level, where 0 is the whole query, 1 is the first BREAK-BY sort
criterion, etc. Must not be negative or greater than the number of sort criteria.
Must not be unknown value.true if the current row is last in the result set or within the specified
break group; else false.public logical isLastOfGroup(int level)
isLastOfGroup in interface P2JQuerylevel - Break group level, where 0 is the whole query, 1 is the first BREAK-BY sort
criterion, etc. Must not be negative or greater than the number of sort criteria.true if the current row is last in the result set or within the specified
break group; else false.public Results getSortedResults()
getSortedResults in interface PresortableResults object used to retrieve sorted results.public boolean next(boolean iterating,
LockType lockType)
This is a combination of records retrieved by each component query. If the compound query involves outer joins, some of the underlying buffers may be empty when this method returns.
next in class CompoundQueryiterating - true if this method is being invoked within the
context of an iterating loop, which can only be exited by
raising an end condition; false if end condition
should not be raised, even if no further advancement of the
composite result is possible.lockType - Lock type which should override that of any underlying query.true if query could retrive the next record succefully;
false if unsuccessful and lenientOffEnd is set on true.QueryOffEndException - if no more results were available in iterating mode.ErrorConditionException - if an underlying query triggers an error.protected boolean isLastOfBreakGroup(Resolvable key)
isLastOfBreakGroup in class AbstractQuerykey - Break group category key. Must be the same object reference
as was specified previously when invoking one of the
addSortCriterion method variants.true if break groups are enabled and current row
is last in the specified break group;
false if break groups have not been enabled or
current row is not last in the specified break group.protected boolean isNewBreakGroup(Resolvable key)
This is the backing worker method for isFirstOfGroup(com.goldencode.p2j.util.Resolvable) and is
used internally by the query to manage accumulators.
isNewBreakGroup in class AbstractQuerykey - Break group category key. Must be the same object reference
as was specified previously when invoking one of the
addSortCriterion method variants.true if current row is first in a break group;
false if it is not; unknown value if break groups
have not been enabled.protected boolean isPresorted()
isPresorted in class CompoundQuerytrue for this implementation.protected PresortCompoundQuery.CursorResults cursorAsResults()
Results interface.Results interface.protected void presort()
presort in class CompoundQuery