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.io.Serializable[] |
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.io.Serializable[] |
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.io.Serializable[] |
prevRow
Cache for non-scrolling queries.
|
private boolean |
resultsCached
Indicates whether backing results has 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.io.Serializable[] 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.
|
protected int |
getNumberOfLoadedRows()
Returns the number of rows which have been loaded by this
Results . |
private java.io.Serializable[] |
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 |
last()
Move cursor to the last results row.
|
private void |
loadBDTIntoArray(java.io.Serializable[] 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.
|
deleteRow, get, getID, getRowNumber, getRows, isFirst, isLast, previous, reset
private 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.io.Serializable[] currentRow
private java.io.Serializable[] prevRow
private java.io.Serializable[] 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 Results
get
in class SimpleResults
null
.public boolean first()
first
in interface Results
first
in class SimpleResults
true
if there are any results.public boolean last()
last
in interface Results
last
in class SimpleResults
true
if there are any results.public boolean next()
next
in interface Results
next
in class SimpleResults
true
if there is a result under the cursor
under the move.public boolean setRowNumber(int row)
setRowNumber
in interface Results
setRowNumber
in class SimpleResults
row
- 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 Results
scroll
in class SimpleResults
rows
- Number of rows to jump ahead or back.true
if there is a row at the new location;
else false
.protected int getNumberOfLoadedRows()
Results
.getNumberOfLoadedRows
in class SimpleResults
public void sessionClosing()
sessionClosing
in interface Results
sessionClosing
in class SimpleResults
public void cleanup()
cleanup
in interface Results
cleanup
in class SimpleResults
public boolean sessionEvent(SessionListener.Event event) throws PersistenceException
SimpleResults
instance. On rollback, it just cleans up.sessionEvent
in interface SessionListener
event
- 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 SessionListener
public void evaluate(int row, boolean firstOf)
evaluate
in interface Presorter.LazyEvaluator
row
- 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.io.Serializable[] ids)
ids
- Identifiers to be stored.private java.io.Serializable[] 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.io.Serializable[] 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.