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 BasicNoPutResultSetImpl
BasicNoPutResultSetImpl.FieldComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate intprivate intprivate BackingStoreHashtableprivate booleanprivate static final intprivate intprivate longprivate booleanintintprivate static final intprivate static final intprivate static final intprivate SQLIntegerprivate intprivate ExecRowprivate booleanprivate booleanprivate intprivate CursorResultSetFields inherited from class NoPutResultSetImpl
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSetFields inherited from class BasicNoPutResultSetImpl
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArrayFields inherited from interface NoPutResultSet
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE, TEMPORARY_RESULT_SET_NUMBERFields inherited from interface 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 voidaddRowToHashTable(ExecRow sourceRow, int position, RowLocation rowLoc, boolean rowUpdated) Add a row to the backing hash table, keyed on position.booleancheckRowPosition(int isType) Determine if the cursor is before the first row in the result set.voidclose()If the result set has been opened, close the open scan.voidfinish()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 ExecRowReturns 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 ExecRowgetRowFromHashTable(int position) Get the row at the specified position from the hash table.Gets information from its source.intReturns the row number of the current row.longgetTimeSpent(int type) Return the total amount of time spent in this ResultSetbooleanReturns TRUE if the row was been deleted within the transaction, otherwise returns FALSEbooleanIs this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is truebooleanReturns TRUE if the row was been updated within the transaction, otherwise returns FALSEvoidMarks the resultSet's currentRow as deleted after a delete has been issued by either by using positioned delete or JDBC's deleteRow method.voidopenCore()open a scan on the source. scan parameters are evaluated at each open, so there is probably some way of altering their values...private voidPositions the cursor in the last fetched row.voidreopen 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.voidupdateRow(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 NoPutResultSetImpl
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, needsRowLocation, needsRowLocationForDeferredCheckConstraints, needsToClone, offendingRowLocation, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setHasDeferrableChecks, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, unpackHashValueMethods inherited from class 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, toXMLMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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:
openCorein 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:
reopenCorein interfaceNoPutResultSet- Overrides:
reopenCorein 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:
getAbsoluteRowin interfaceResultSet- Overrides:
getAbsoluteRowin 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:
getRelativeRowin interfaceResultSet- Overrides:
getRelativeRowin 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:
setBeforeFirstRowin interfaceResultSet- Overrides:
setBeforeFirstRowin classBasicNoPutResultSetImpl- Returns:
- NULL.
- See Also:
-
getFirstRow
Returns the first row from the query, and returns NULL when there are no rows.- Specified by:
getFirstRowin interfaceResultSet- Overrides:
getFirstRowin classBasicNoPutResultSetImpl- Returns:
- The first row, or NULL if no rows.
- Throws:
StandardException- Thrown on failure- See Also:
-
getNextRowCore
Description copied from interface:NoPutResultSetReturn 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:
getNextRowCorein interfaceNoPutResultSet- Specified by:
getNextRowCorein 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:
getPreviousRowin interfaceResultSet- Overrides:
getPreviousRowin 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:
getLastRowin interfaceResultSet- Overrides:
getLastRowin 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:
setAfterLastRowin interfaceResultSet- Overrides:
setAfterLastRowin 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:
checkRowPositionin interfaceResultSet- Overrides:
checkRowPositionin 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:
getRowNumberin interfaceResultSet- Overrides:
getRowNumberin 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:
closein interfaceResultSet- Overrides:
closein classNoPutResultSetImpl- Throws:
StandardException- thrown on error
-
finish
Description copied from interface:ResultSetTells 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:
finishin interfaceResultSet- Overrides:
finishin classBasicNoPutResultSetImpl- Throws:
StandardException- on error
-
getTimeSpent
public long getTimeSpent(int type) Return the total amount of time spent in this ResultSet- Specified by:
getTimeSpentin 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:
getRowLocationin 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:
getCurrentRowin 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:NoPutResultSetUpdates 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:
updateRowin interfaceNoPutResultSet- Overrides:
updateRowin 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:NoPutResultSetMarks 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:
markRowAsDeletedin interfaceNoPutResultSet- Overrides:
markRowAsDeletedin 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:NoPutResultSetImplIs 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:
isForUpdatein interfaceNoPutResultSet- Overrides:
isForUpdatein 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
-