Class ScrollInsensitiveResultSet
java.lang.Object
org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
org.apache.derby.impl.sql.execute.NoPutResultSetImpl
org.apache.derby.impl.sql.execute.ScrollInsensitiveResultSet
- All Implemented Interfaces:
CursorResultSet
,NoPutResultSet
,ResultSet
,RowLocationRetRowSource
,RowSource
Provide insensitive scrolling functionality for the underlying
result set. We build a disk backed hash table of rows as the
user scrolls forward, with the position as the key.
For read-only result sets the hash table will containg the
following columns:
+-------------------------------+ | KEY | +-------------------------------+ | Row | +-------------------------------+where key is the position of the row in the result set and row is the data. And for updatable result sets it will contain:
+-------------------------------+ | KEY | [0] +-------------------------------+ | RowLocation | [POS_ROWLOCATION] +-------------------------------+ | Deleted | [POS_ROWDELETED] +-------------------------------+ | Updated | [POS_ROWUPDATED] +-------------------------------+ | Row | [extraColumns ... n] +-------------------------------+where key is the position of the row in the result set, rowLocation is the row location of that row in the Heap, Deleted indicates whether the row has been deleted, Updated indicates whether the row has been updated, and row is the data.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
BasicNoPutResultSetImpl.FieldComparator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private int
private int
private BackingStoreHashtable
private boolean
private static final int
private int
private long
private boolean
int
int
private static final int
private static final int
private static final int
private SQLInteger
private int
private ExecRow
private boolean
private boolean
private int
private CursorResultSet
Fields inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSet
Fields inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArray
Fields inherited from interface org.apache.derby.iapi.sql.execute.NoPutResultSet
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE, TEMPORARY_RESULT_SET_NUMBER
Fields inherited from interface org.apache.derby.iapi.sql.ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
-
Constructor Summary
ConstructorsConstructorDescriptionScrollInsensitiveResultSet
(NoPutResultSet source, Activation activation, int resultSetNumber, int sourceRowWidth, double optimizerEstimatedRowCount, double optimizerEstimatedCost) Constructor for a ScrollInsensitiveResultSet -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addRowToHashTable
(ExecRow sourceRow, int position, RowLocation rowLoc, boolean rowUpdated) Add a row to the backing hash table, keyed on position.boolean
checkRowPosition
(int isType) Determine if the cursor is before the first row in the result set.void
close()
If the result set has been opened, close the open scan.void
finish()
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open().getAbsoluteRow
(int row) Returns the row at the absolute position from the query, and returns NULL when there is no such position.Gets information from last getNextRow call.private DataValueDescriptor[]
Get the column array from the current position in the hash tableReturns the first row from the query, and returns NULL when there are no rows.Returns the last row from the query, and returns NULL when there are no rows.Return the requested values computed from the next row (if any) for which the restriction evaluates to true.private ExecRow
Returns the previous row from the query, and returns NULL when there are no more previous rows.getRelativeRow
(int row) Returns the row at the relative position from the current cursor position, and returns NULL when there is no such position.private DataValueDescriptor[]
getRowArrayFromHashTable
(int position) Get the row data at the specified position from the hash table.private ExecRow
getRowFromHashTable
(int position) Get the row at the specified position from the hash table.Gets information from its source.int
Returns the row number of the current row.long
getTimeSpent
(int type) Return the total amount of time spent in this ResultSetboolean
Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSEboolean
Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is trueboolean
Returns TRUE if the row was been updated within the transaction, otherwise returns FALSEvoid
Marks the resultSet's currentRow as deleted after a delete has been issued by either by using positioned delete or JDBC's deleteRow method.void
openCore()
open a scan on the source. scan parameters are evaluated at each open, so there is probably some way of altering their values...private void
Positions the cursor in the last fetched row.void
reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...Sets the current position to after the last row and returns NULL because there is no current row.Sets the current position to before the first row and returns NULL because there is no current row.void
updateRow
(ExecRow row, RowChanger rowChanger) Updates the resultSet's current row with it's new values after an update has been issued either using positioned update or JDBC's udpateRow method.Methods inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, needsRowLocation, needsRowLocationForDeferredCheckConstraints, needsToClone, offendingRowLocation, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setHasDeferrableChecks, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, unpackHashValue
Methods inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
addWarning, attachStatementContext, checkCancellationFlag, childrenToXML, cleanUp, dumpTimeStats, finishAndRTS, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentTimeMillis, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getLanguageConnectionContext, getNextRow, getPointOfAttachment, getScanIsolationLevel, getSubqueryTrackingArray, getTransactionController, getWarnings, isClosed, isXplainOnlyMode, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, requiresRelocking, returnsRows, setCompactRow, setCompatRow, toXML, toXML
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.derby.iapi.sql.ResultSet
addWarning, cleanUp, clearCurrentRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getNextRow, getResultDescription, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows, toXML
-
Field Details
-
source
-
sourceRowWidth
private int sourceRowWidth -
ht
-
resultRow
-
positionInSource
private int positionInSource -
currentPosition
private int currentPosition -
lastPosition
private int lastPosition -
seenFirst
private boolean seenFirst -
seenLast
private boolean seenLast -
beforeFirst
private boolean beforeFirst -
afterLast
private boolean afterLast -
numFromHashTable
public int numFromHashTable -
numToHashTable
public int numToHashTable -
maxRows
private long maxRows -
keepAfterCommit
private boolean keepAfterCommit -
extraColumns
private int extraColumns -
positionInHashTable
-
target
-
needsRepositioning
private boolean needsRepositioning -
POS_ROWLOCATION
private static final int POS_ROWLOCATION- See Also:
-
POS_ROWDELETED
private static final int POS_ROWDELETED- See Also:
-
POS_ROWUPDATED
private static final int POS_ROWUPDATED- See Also:
-
LAST_EXTRA_COLUMN
private static final int LAST_EXTRA_COLUMN- See Also:
-
-
Constructor Details
-
ScrollInsensitiveResultSet
public ScrollInsensitiveResultSet(NoPutResultSet source, Activation activation, int resultSetNumber, int sourceRowWidth, double optimizerEstimatedRowCount, double optimizerEstimatedCost) throws StandardException Constructor for a ScrollInsensitiveResultSet- Parameters:
source
- The NoPutResultSet from which to get rows to scroll throughactivation
- The activation for this executionresultSetNumber
- The resultSetNumbersourceRowWidth
- # of columns in the source row- Throws:
StandardException
- on error
-
-
Method Details
-
openCore
open a scan on the source. scan parameters are evaluated at each open, so there is probably some way of altering their values...- Specified by:
openCore
in interfaceNoPutResultSet
- Throws:
StandardException
- thrown on failure
-
reopenCore
reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...- Specified by:
reopenCore
in interfaceNoPutResultSet
- Overrides:
reopenCore
in classBasicNoPutResultSetImpl
- Throws:
StandardException
- thrown if cursor finished.- See Also:
-
getAbsoluteRow
Returns the row at the absolute position from the query, and returns NULL when there is no such position. (Negative position means from the end of the result set.) Moving the cursor to an invalid position leaves the cursor positioned either before the first row (negative position) or after the last row (positive position). NOTE: An exception will be thrown on 0.- Specified by:
getAbsoluteRow
in interfaceResultSet
- Overrides:
getAbsoluteRow
in classBasicNoPutResultSetImpl
- Parameters:
row
- The position.- Returns:
- The row at the absolute position, or NULL if no such position.
- Throws:
StandardException
- Thrown on failure- See Also:
-
getRelativeRow
Returns the row at the relative position from the current cursor position, and returns NULL when there is no such position. (Negative position means toward the beginning of the result set.) Moving the cursor to an invalid position leaves the cursor positioned either before the first row (negative position) or after the last row (positive position). NOTE: 0 is valid. NOTE: An exception is thrown if the cursor is not currently positioned on a row.- Specified by:
getRelativeRow
in interfaceResultSet
- Overrides:
getRelativeRow
in classBasicNoPutResultSetImpl
- Parameters:
row
- The position.- Returns:
- The row at the relative position, or NULL if no such position.
- Throws:
StandardException
- Thrown on failure- See Also:
-
setBeforeFirstRow
Sets the current position to before the first row and returns NULL because there is no current row.- Specified by:
setBeforeFirstRow
in interfaceResultSet
- Overrides:
setBeforeFirstRow
in classBasicNoPutResultSetImpl
- Returns:
- NULL.
- See Also:
-
getFirstRow
Returns the first row from the query, and returns NULL when there are no rows.- Specified by:
getFirstRow
in interfaceResultSet
- Overrides:
getFirstRow
in classBasicNoPutResultSetImpl
- Returns:
- The first row, or NULL if no rows.
- Throws:
StandardException
- Thrown on failure- See Also:
-
getNextRowCore
Description copied from interface:NoPutResultSet
Return the requested values computed from the next row (if any) for which the restriction evaluates to true.restriction and projection parameters are evaluated for each row.
- Specified by:
getNextRowCore
in interfaceNoPutResultSet
- Specified by:
getNextRowCore
in classBasicNoPutResultSetImpl
- Returns:
- the next row in the result
- Throws:
StandardException
- thrown on failure- See Also:
-
getPreviousRow
Returns the previous row from the query, and returns NULL when there are no more previous rows.- Specified by:
getPreviousRow
in interfaceResultSet
- Overrides:
getPreviousRow
in classBasicNoPutResultSetImpl
- Returns:
- The previous row, or NULL if no more previous rows.
- Throws:
StandardException
- Thrown on failure- See Also:
-
getLastRow
Returns the last row from the query, and returns NULL when there are no rows.- Specified by:
getLastRow
in interfaceResultSet
- Overrides:
getLastRow
in classBasicNoPutResultSetImpl
- Returns:
- The last row, or NULL if no rows.
- Throws:
StandardException
- Thrown on failure- See Also:
-
setAfterLastRow
Sets the current position to after the last row and returns NULL because there is no current row.- Specified by:
setAfterLastRow
in interfaceResultSet
- Overrides:
setAfterLastRow
in classBasicNoPutResultSetImpl
- Returns:
- NULL.
- Throws:
StandardException
- Thrown on failure- See Also:
-
checkRowPosition
Determine if the cursor is before the first row in the result set.- Specified by:
checkRowPosition
in interfaceResultSet
- Overrides:
checkRowPosition
in classBasicNoPutResultSetImpl
- Returns:
- true if before the first row, false otherwise. Returns false when the result set contains no rows.
- Throws:
StandardException
- Thrown on error.
-
getRowNumber
public int getRowNumber()Returns the row number of the current row. Row numbers start from 1 and go to 'n'. Corresponds to row numbering used to position current row in the result set (as per JDBC).- Specified by:
getRowNumber
in interfaceResultSet
- Overrides:
getRowNumber
in classBasicNoPutResultSetImpl
- Returns:
- the row number, or 0 if not on a row
-
getNextRowFromSource
- Throws:
StandardException
-
close
If the result set has been opened, close the open scan.- Specified by:
close
in interfaceResultSet
- Overrides:
close
in classNoPutResultSetImpl
- Throws:
StandardException
- thrown on error
-
finish
Description copied from interface:ResultSet
Tells the system that there will be no more access to any database information via this result set; in particular, no more calls to open(). Will close the result set if it is not already closed.- Specified by:
finish
in interfaceResultSet
- Overrides:
finish
in classBasicNoPutResultSetImpl
- Throws:
StandardException
- on error
-
getTimeSpent
public long getTimeSpent(int type) Return the total amount of time spent in this ResultSet- Specified by:
getTimeSpent
in interfaceResultSet
- Parameters:
type
- CURRENT_RESULTSET_ONLY - time spent only in this ResultSet ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.- Returns:
- long The total amount of time spent (in milliseconds).
-
getRowLocation
Gets information from its source. We might want to have this take a CursorResultSet in its constructor some day, instead of doing a cast here?- Specified by:
getRowLocation
in interfaceCursorResultSet
- Returns:
- the row location of the current cursor row.
- Throws:
StandardException
- thrown on failure- See Also:
-
getCurrentRow
Gets information from last getNextRow call.- Specified by:
getCurrentRow
in interfaceCursorResultSet
- Returns:
- the last row returned.
- Throws:
StandardException
- thrown on failure.- See Also:
-
addRowToHashTable
private void addRowToHashTable(ExecRow sourceRow, int position, RowLocation rowLoc, boolean rowUpdated) throws StandardException Add a row to the backing hash table, keyed on position. When a row gets updated when using scrollable insensitive updatable result sets, the old entry for the row will be deleted from the hash table and this method will be called to add the new values for the row to the hash table, with the parameter rowUpdated = true so as to mark the row as updated. The latter is done in order to implement detectability of own changes for result sets of this type.- Parameters:
sourceRow
- The row to add.position
- The keyrowLoc
- The rowLocation of the row to add.rowUpdated
- Indicates whether the row has been updated.- Throws:
StandardException
-
getRowFromHashTable
Get the row at the specified position from the hash table.- Parameters:
position
- The specified position.- Returns:
- The row at that position.
- Throws:
StandardException
- thrown on failure
-
getRowArrayFromHashTable
Get the row data at the specified position from the hash table.- Parameters:
position
- The specified position.- Returns:
- The row data at that position.
- Throws:
StandardException
- thrown on failure
-
positionInLastFetchedRow
Positions the cursor in the last fetched row. This is done before navigating to a row that has not previously been fetched, so that getNextRowCore() will re-start from where it stopped.- Throws:
StandardException
-
updateRow
Description copied from interface:NoPutResultSet
Updates the resultSet's current row with it's new values after an update has been issued either using positioned update or JDBC's udpateRow method.- Specified by:
updateRow
in interfaceNoPutResultSet
- Overrides:
updateRow
in classNoPutResultSetImpl
- Parameters:
row
- new values for the currentRowrowChanger
- holds information about row: what columns of it is to be used for updating, and what underlying base table column each such column corresponds to.- Throws:
StandardException
- thrown on failure.- See Also:
-
markRowAsDeleted
Description copied from interface:NoPutResultSet
Marks the resultSet's currentRow as deleted after a delete has been issued by either by using positioned delete or JDBC's deleteRow method.- Specified by:
markRowAsDeleted
in interfaceNoPutResultSet
- Overrides:
markRowAsDeleted
in classNoPutResultSetImpl
- Throws:
StandardException
- thrown on failure.- See Also:
-
isDeleted
Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSE- Returns:
- True if the row has been deleted, otherwise false
- Throws:
StandardException
- on error
-
isUpdated
Returns TRUE if the row was been updated within the transaction, otherwise returns FALSE- Returns:
- True if the row has been deleted, otherwise false
- Throws:
StandardException
- on error
-
isForUpdate
public boolean isForUpdate()Description copied from class:NoPutResultSetImpl
Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is true- Specified by:
isForUpdate
in interfaceNoPutResultSet
- Overrides:
isForUpdate
in classNoPutResultSetImpl
- Returns:
- Whether or not the result set is for update.
-
getCurrentRowFromHashtable
Get the column array from the current position in the hash table- Throws:
StandardException
-