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
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, unregisterOnCleanup
cursor
closed, inverseSorting, outer, parameterFilter
CURRENT, FIRST, 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.
|
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.
|
logical |
isFirst()
Determine whether the query result row currently being visited is the
first row in the presorted results list.
|
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(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.
|
protected boolean |
isPresorted()
Determines if the query is presorted, i.e.
|
void |
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, canOptimize, cleanup, clearDynamicFilters, close, close, current, current, deleteResultListEntry, first, first, first, first, getBreakValue, getOffEnd, getOffEndListeners, getOriginalComponents, getTableCount, indexInformation, initialize, initReferenceRowSupport, iterate, last, last, last, last, loadByValues, loadRowAtCursor, next, next, next, notifyRepositionListeners, open, peekFirst, peekLast, peekNext, peekPrevious, postponeAccumulation, preselectResults, previous, previous, previous, previous, recordBuffers, releaseAllBuffers, releaseBuffers, restoreAccumulation, retrieve, retrieve, setBrowsed, setExternalBuffers, setScrolling, setStandalone, stateChanged
_isOffEnd, backward, backward, currentRow, currentRowImpl, forward, forward, incrementMoves, isNativelyPreselect, isPreselect, isScrolling, reposition, reposition, repositionByID, repositionByID, resetScrolling, size, verifyScrolling
accumulate, addAccumulator, addAccumulator, addBuffer, addBuffer, addRepositionListener, afterReposition, bufferHandle, bufferHandle, bufferHandle, bufferHandle, bufferHandle, changeForwardOnly, changeForwardOnly, deleteResultListEntry, exclude, forwardOnly, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getExternalBuffers, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, getFirst, 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, getReferencedBuffers, hasAccumulators, hasAny, hasAny, hasAny, hasAny, hasOne, hasOne, hasOne, hasOne, include, indexInformation, indexInformation, isBrowsed, isErrorIfNull, isFatalError, isFetchOnReposition, isOffEnd, isOmitAlias, isOpen, isRepositionNotificationActive, isSkipDeletedRecord, isStandalone, numBuffers, numResults, numResults, prepare, prepare, prepareFetch, prepareString, preprocessSubstitutionArguments, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, removeRepositionListener, setBuffers, setBuffers, setErrorIfNull, setFatalError, setFetchOnReposition, setOmitAlias, setOuter, setParameterFilter, setSkipDeletedRecord
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAccumulator, addAccumulator, addBuffer, addBuffer, addRepositionListener, bufferHandle, bufferHandle, bufferHandle, bufferHandle, bufferHandle, changeForwardOnly, changeForwardOnly, deleteResultListEntry, exclude, forwardOnly, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, getCurrent, 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, isFetchOnReposition, isOffEnd, isOpen, isSkipDeletedRecord, isStandalone, numBuffers, prepare, prepare, prepareString, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, removeRepositionListener, setBuffers, setBuffers, setErrorIfNull, setFetchOnReposition, setParameterFilter, setSkipDeletedRecord, unique, unique
private Presorter sorter
private PresortCompoundQuery.CursorResults cursorResults
Results
interface.public PresortCompoundQuery()
initialize()
is
called.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 void addComponent(Joinable query, int iteration, boolean outer)
outer
.addComponent
in class CompoundQuery
query
- 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 P2JQuery
getRecordBuffers
in interface Presortable
public 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 PresortDelegate
sort
- 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 PresortDelegate
sort
- 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 PresortDelegate
sort
- 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 PresortDelegate
public void enableBreakGroups()
enableBreakGroups
in interface PresortDelegate
public logical isFirst()
isFirst
in interface PresortDelegate
true
if the current result row is the first row,
else false
.public logical isFirstOfGroup(Resolvable key)
isFirstOfGroup
in interface PresortDelegate
key
- 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 isLast()
isLast
in interface PresortDelegate
true
if the current result row is the last row,
else false
.public logical isLastOfGroup(Resolvable key)
isLastOfGroup
in interface PresortDelegate
key
- 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 Results getSortedResults()
getSortedResults
in interface Presortable
Results
object used to retrieve sorted results.public void 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 CompoundQuery
iterating
- 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.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 AbstractQuery
key
- 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 AbstractQuery
key
- 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 CompoundQuery
true
for this implementation.protected PresortCompoundQuery.CursorResults cursorAsResults()
Results
interface.Results
interface.protected void presort()
presort
in class CompoundQuery