public class AdaptiveFind extends AdaptiveQuery
AdaptiveQuery
which may begin in dynamic
record retrieval mode. If so, it switches to preselect mode as soon as
possible. It is intended as the backing implementation for converted FIND
statements which can be executed in succession without requiring a new
query to be executed for each record retrieved. Candidates are
combinations of FIND FIRST/NEXT and FIND LAST/PREV, or instances of FIND
NEXT and FIND PREV which operate in loops.
This type of query by its nature operates only on a single table and therefore on a single record buffer. If the record buffer already is in use, its latest record is used as a reference point for the next record to be retrieved and the query is initialized in dynamic mode. Otherwise, the query is initialized in preselect mode.
P2JQuery.Parameter
SessionListener.Event, SessionListener.Scope
Modifier and Type | Field and Description |
---|---|
private RecordBuffer |
buffer
Buffer updated by this query
|
private boolean |
initialized
Flag indicating whether this object has been initialized
|
private Persistable |
lastFound
Record most recently found by this query
|
cursor, errorCondition, foundFirst
betweenRows, components, currentRowDeleted, offEnd, sort
closed, inverseSorting, parameterFilter
CURRENT, FIRST, LAST, NEXT, NONE, PREVIOUS, RETRIEVE_MODES, UNIQUE
Constructor and Description |
---|
AdaptiveFind()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addComponent(QueryComponent comp)
Add a component to the query.
|
protected DynamicQuery |
createCompoundQuery(RecordBuffer invalidBuffer)
Overrides the parent to disallow creation of a compound query, since
this class supports only single-table find queries.
|
protected DynamicQuery |
createSimpleQuery(RecordBuffer invalidBuffer)
Create a single-table, dynamic query to be used as the worker object
for a
DynamicResults object when this query switches from
preselect to dynamic mode. |
void |
first(LockType lockType)
Retrieve the first composite row of results for the query.
|
private void |
init()
Initialize and flush the buffer.
|
AdaptiveFind |
initialize(DataModelObject dmo,
java.lang.String where,
java.lang.String sort,
boolean inverseSorting,
DataModelObject... dmos)
Convenience deferred initializer designed for a single-table adaptive query.
|
AdaptiveFind |
initialize(DataModelObject dmo,
java.lang.String where,
java.lang.String sort,
DataModelObject... dmos)
Convenience deferred initializer designed for a single-table adaptive query.
|
AdaptiveFind |
initialize(DataModelObject dmo,
java.lang.String where,
java.lang.String sort,
LockType lockType,
DataModelObject... dmos)
Convenience deferred initializer designed for a single-table adaptive query.
|
protected boolean |
isGlobalInvalidation()
Report whether this query must check for changes across all sessions and
possibly invalidate its current results if any are found.
|
boolean |
isLenientOffEnd()
If in silent error mode, this method will always return
true . |
protected boolean |
isTopLevelCleanup()
Indicate whether results resources should be cleaned up upon exiting
the current program's top-level scope or upon exiting the nearest
enclosing scope in which the results were created.
|
private void |
maybeInvalidate()
Invalidate the current result set associated with this query if the
record buffer's contents have changed since the last time this query
updated the buffer.
|
void |
next(LockType lockType)
Retrieve the next composite row of results for the query.
|
protected void |
releaseBuffers()
Release the current record, if any, from the buffer which is used by
this query.
|
addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, assembleOrderByClause, assembleWhereClause, backward, cleanup, close, close, createCompoundQuery, createResults, createSimpleQuery, current, currentRow, currentRowImpl, deleteResultListEntry, execute, executeQuery, fetch, forceDynamicOperation, forward, getCachedRow, getCurrentIds, getRow, handleMissingJoinRecord, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, initialize, invalidate, invalidateIfReferenceRowExists, isNativelyPreselect, isNativelyScrolling, isPreselect, last, load, loadByValues, open, peekNext, peekPrevious, prepareParameters, previous, recordBuffers, registerRecordChangeListeners, reposition, repositionByID, repositionByID, reset, resetResults, resultsChanged, sessionEvent, setScrolling, setWorkerRefererenceRecord, size, stateChanged, storeReferenceRow, toString, treatPreviousAsLast
_isOffEnd, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addWhereExpression, assembleFromClause, assembleOrderByClauseNoPreamble, assembleOrderByClauseNoPreamble, assembleSelectClause, backward, buildSortCriteria, cacheResults, clearRepoCache, components, coreFetch, current, deleted, deregisteredSessionListener, executeScroll, finished, first, forward, getArgs, getEntities, getHQL, getJoin, getOffEnd, getOffEndListeners, getOriginalWhere, getPersistence, getRecordBuffers, getResults, getSortPhrase, getTableCount, getTemplateQueryRowid, getWhereExpressions, hasWhereExpression, indexInformation, initialize, initialize, isClientWhere, isFullRecords, isOffEnd, isScrolling, iterate, last, makeAdaptiveServerJoinComponent, makePreselectServerJoinComponent, next, peekFirst, peekLast, prepareReposition, preserveBuffersOnEmptyResults, previous, processJoin, registerCleaner, reposition, repositionByID, repositionByID, retry, setEmptyBuffersUnknown, setFullRecords, setIterationType, setIterationType, setLenientOffEnd, setNonScrolling, setResults, setUnknownRecord, supportsArbitraryIteration, unique, unique, verifyJoins, whereExpressions
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, 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, isFetchOnReposition, isLastOfBreakGroup, isNewBreakGroup, isOpen, isRepositionNotificationActive, isSkipDeletedRecord, isStandalone, loadRowAtCursor, notifyRepositionListeners, numBuffers, numResults, numResults, optimize, prepare, prepare, prepareFetch, prepareString, preprocessSubstitutionArguments, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, removeRepositionListener, setBrowsed, setBuffers, setBuffers, setErrorIfNull, setExternalBuffers, setFetchOnReposition, setParameterFilter, setSkipDeletedRecord, setStandalone, validateSubstitutionArguments
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getReferencedBuffers, setErrorIfNull
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, 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, isOpen, isSkipDeletedRecord, isStandalone, notifyRepositionListeners, numBuffers, optimize, prepare, prepare, prepareString, queryBackward, queryBackward, queryClose, queryForward, queryForward, queryOpen, queryReposition, queryReposition, queryRepositionByID, removeRepositionListener, setBrowsed, setBuffers, setBuffers, setExternalBuffers, setFetchOnReposition, setParameterFilter, setSkipDeletedRecord, setStandalone
initFailure
private RecordBuffer buffer
private Persistable lastFound
private boolean initialized
public AdaptiveFind()
initialize()
is
called.public AdaptiveFind initialize(DataModelObject dmo, java.lang.String where, java.lang.String sort, DataModelObject... dmos)
dmo
- DMO proxy which defines buffer and record type.where
- HQL where clause. May be null
.sort
- HQL order by clause.dmos
- Zero or more external buffers.this
) so that chaining can be used.public AdaptiveFind initialize(DataModelObject dmo, java.lang.String where, java.lang.String sort, LockType lockType, DataModelObject... dmos)
dmo
- DMO proxy which defines buffer and record type.where
- HQL where clause. May be null
.sort
- HQL order by clause.lockType
- Lock type to apply to records retrieved by this query.dmos
- Zero or more external buffers.this
) so that chaining can be used.public AdaptiveFind initialize(DataModelObject dmo, java.lang.String where, java.lang.String sort, boolean inverseSorting, DataModelObject... dmos)
dmo
- DMO proxy which defines buffer and record type.where
- HQL where clause. May be null
.sort
- HQL order by clause.inverseSorting
- Whether this query has the inverse sorting direction.dmos
- Zero or more external buffers.this
) so that chaining can be used.public void first(LockType lockType)
first
in interface P2JQuery
first
in class AdaptiveQuery
lockType
- Lock type to apply to records retrieved (overrides default
lock type set for each query component).ErrorConditionException
- if the query or the fetch of any record fails, or if no records
are available and the query is set to fail in this case.QueryOffEndException
- if no records are available and the query is set not to fail
in this case.java.lang.IllegalStateException
- if no query component has been added to this query.public void next(LockType lockType)
next
in interface P2JQuery
next
in class AdaptiveQuery
lockType
- Lock type to apply to records retrieved (overrides default
lock type set for each query component).ErrorConditionException
- if the query or the fetch of any record fails, or if no records
are available and the query is set to fail in this case.QueryOffEndException
- if no records are available and the query is set not to fail
in this case.java.lang.IllegalStateException
- if no query component has been added to this query.public boolean isLenientOffEnd()
true
.
Else, it will let the PreselectQuery.isLenientOffEnd()
decide
the mode.isLenientOffEnd
in class PreselectQuery
true
if an exception will be thrown, else
false
.protected boolean isGlobalInvalidation()
isGlobalInvalidation
in class AdaptiveQuery
true
if query is against a permanent table;
false
if query is against a temporary table.protected void addComponent(QueryComponent comp)
addComponent
in class PreselectQuery
comp
- Query component to be added.java.lang.UnsupportedOperationException
- if invoked more than once per instance; also:
if attempting an outer join (temporary);
if iteration type is not NEXT
(temporary);protected DynamicQuery createSimpleQuery(RecordBuffer invalidBuffer) throws PersistenceException
DynamicResults
object when this query switches from
preselect to dynamic mode. Overrides the parent's implementation to
create a FindQuery
for its lenient-off-end behavior.invalidBuffer
- Record buffer which caused this query to be invalidated.FindQuery
based upon this query's single
component.PersistenceException
- if there is an error creating the HQLPreprocessor
from which setup data is required.protected DynamicQuery createCompoundQuery(RecordBuffer invalidBuffer) throws PersistenceException
invalidBuffer
- Record buffer which caused this query to be invalidated.java.lang.UnsupportedOperationException
- always.PersistenceException
- if there is an error creating the HQLPreprocessor
from which setup data is required. Not thrown by this
implementation.protected void releaseBuffers()
releaseBuffers
in class AbstractQuery
QueryOffEndException
- if the buffer contained a record and it was released.protected boolean isTopLevelCleanup()
isTopLevelCleanup
in class PreselectQuery
true
.private void init()
private void maybeInvalidate()