private class Presorter.IncrementalResults extends SimpleResults implements SessionListener, Presorter.LazyEvaluator
Presorter.SortedResults when the sort
criteria added to the Presorter match the leading components of the
presort query sort phrase (i.e. results are already sorted in the proper
order). This class retrieves results iteratively on demand which lead
to faster initial response / less memory consumption compared to
Presorter.SortedResults which caches and sorts all results up front.
If session expires, all remaining results (record IDs) are cached. Break group information in this case will be retrieved iteratively on request.
SessionListener.Event, SessionListener.Scope| Modifier and Type | Field and Description |
|---|---|
private Results |
backingResults
Original sorted results.
|
private int |
backingResultsOffset
Offset that is used to determine the row number into the whole result
set (global row number = offset + row number into cached result set).
|
private static java.lang.String |
BACKWARD_SCROLL_ERROR
Error message if a non-scrolling query is scrolled backward.
|
private BaseDataType[] |
currentBDT
Array which contains the sort criteria values for the last loaded row.
|
private java.lang.Long[] |
currentRow
Cache for non-scrolling queries.
|
private int |
lastEvaluatedRow
Number of the row which corresponds the
currentBDT. |
private BaseDataType[] |
nextBDT
Array which contains the sort criteria values for the row after the
last loaded row (i.e.
|
private java.lang.Long[] |
nextRow
Cache for non-scrolling queries.
|
private BaseDataType[] |
prevBDT
Array which contains the sort criteria values for the row before the last loaded row.
|
private java.lang.Long[] |
prevRow
Cache for non-scrolling queries.
|
private boolean |
resultsCached
Indicates whether backing results have been cached because of session closing.
|
private int |
rowsSize
Number of loaded rows (for non-scrolling queries).
|
private boolean |
scrolling
Determines whether this
Results are scrolling. |
| Modifier | Constructor and Description |
|---|---|
private |
IncrementalResults(Results sorted)
Create a result set that will interrogate
sorted results
iteratively on request. |
| Modifier and Type | Method and Description |
|---|---|
private void |
addRow(java.lang.Long[] ids)
Store the given record identifiers to the rows cache.
|
void |
cleanup()
Clear the internal list of result rows and the backing results.
|
private void |
cleanupBackingResults()
Clear the backing results.
|
void |
deregisteredSessionListener()
No-op in this implementation.
|
void |
evaluate(int row,
boolean firstOf)
Evalualte break row(s) which help to determine whether the given row
if the first/last in a break group.
|
boolean |
first()
Move cursor to the first results row.
|
java.lang.Object[] |
get()
Get the array of objects at the current result row.
|
int |
getNumberOfLoadedRows()
Returns the number of rows which have been loaded by this
Results. |
private java.lang.Long[] |
getRow(int row)
Get the specified row (an array of record identifiers).
|
private boolean |
isFirst(int row)
Tests whether the given row is the first row in the results set.
|
private boolean |
isLast(int row)
Tests whether the given row is the last row in the results set.
|
boolean |
isResultSetCached()
Indicate whether the full result set is cached in this object.
|
boolean |
last()
Move cursor to the last results row.
|
private void |
loadBDTIntoArray(java.lang.Long[] ids,
BaseDataType[] targetArray)
Load sort criteria values using identifiers of corresponding records.
|
private void |
loadRow(int rowNumber)
Load the specified row into the cache.
|
boolean |
next()
Move cursor to the next results row.
|
boolean |
scroll(int rows)
Scroll the cursor ahead by the specified number of rows.
|
void |
sessionClosing()
Clears the backing results.
|
boolean |
sessionEvent(SessionListener.Event event)
Invoked when a Hibernate session event occurs.
|
boolean |
setRowNumber(int row)
Set the row number currently under the cursor.
|
addRow, deleteRow, get, getID, getRowNumber, getRows, isEmpty, isFirst, isLast, previous, resetclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitget, isAutoFetchprivate static final java.lang.String BACKWARD_SCROLL_ERROR
private Results backingResults
private int backingResultsOffset
private BaseDataType[] currentBDT
private BaseDataType[] prevBDT
private BaseDataType[] nextBDT
private final boolean scrolling
Results are scrolling.private int lastEvaluatedRow
currentBDT.private java.lang.Long[] currentRow
private java.lang.Long[] prevRow
private java.lang.Long[] nextRow
private int rowsSize
private boolean resultsCached
private IncrementalResults(Results sorted)
sorted results
iteratively on request.sorted - Original sorted results.public java.lang.Object[] get()
get in interface Resultsget in class SimpleResultsnull.public boolean first()
first in interface Resultsfirst in class SimpleResultstrue if there are any results.public boolean last()
last in interface Resultslast in class SimpleResultstrue if there are any results.public boolean next()
next in interface Resultsnext in class SimpleResultstrue if there is a result under the cursor
under the move.public boolean setRowNumber(int row)
setRowNumber in interface ResultssetRowNumber in class SimpleResultsrow - Zero-based index of the row to be set as the current row.true if there is a row at the specified row
number; else false.public boolean scroll(int rows)
scroll in interface Resultsscroll in class SimpleResultsrows - Number of rows to jump ahead or back.true if there is a row at the new location;
else false.public int getNumberOfLoadedRows()
Results.getNumberOfLoadedRows in interface ResultsgetNumberOfLoadedRows in class SimpleResultspublic void sessionClosing()
sessionClosing in interface ResultssessionClosing in class SimpleResultspublic void cleanup()
cleanup in interface Resultscleanup in class SimpleResultspublic boolean isResultSetCached()
isResultSetCached in interface ResultsisResultSetCached in class SimpleResultstrue if all results have been collected and cached, else false.public boolean sessionEvent(SessionListener.Event event) throws PersistenceException
SimpleResults
instance. On rollback, it just cleans up.sessionEvent in interface SessionListenerevent - Session event type.true in this implemetation (i.e. this listener
should be removed from the current set of registered
listeners).PersistenceException - if any error occurs during the implementor's processing.public void deregisteredSessionListener()
deregisteredSessionListener in interface SessionListenerpublic void evaluate(int row,
boolean firstOf)
evaluate in interface Presorter.LazyEvaluatorrow - Row to be checked as the beginning/end of a break group.firstOf - true indicates that the row should be checked as
the beginning of a break group. false indicates
that the row should be checked as the end of a break groupprivate void cleanupBackingResults()
private void loadRow(int rowNumber)
rowNumber - Position of the requested row in the results set.private void addRow(java.lang.Long[] ids)
ids - Identifiers to be stored.private java.lang.Long[] getRow(int row)
row - Number of row to return.private boolean isFirst(int row)
row - Row to test.true if the given row is the first row.private boolean isLast(int row)
row - Row to test.true if the given row is the last row.private void loadBDTIntoArray(java.lang.Long[] ids,
BaseDataType[] targetArray)
throws PersistenceException
ids - Array of record identifiers.targetArray - Array for storing sort criteria values.PersistenceException - if there was an error creating a Hibernate session or getting
a record or record eviction problems.