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
public class ScrollInsensitiveResultSet extends NoPutResultSetImpl implements CursorResultSet
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
Fields Modifier and Type Field Description private booleanafterLastprivate booleanbeforeFirstprivate intcurrentPositionprivate intextraColumnsprivate BackingStoreHashtablehtprivate booleankeepAfterCommitprivate static intLAST_EXTRA_COLUMNprivate intlastPositionprivate longmaxRowsprivate booleanneedsRepositioningintnumFromHashTableintnumToHashTableprivate static intPOS_ROWDELETEDprivate static intPOS_ROWLOCATIONprivate static intPOS_ROWUPDATEDprivate SQLIntegerpositionInHashTableprivate intpositionInSourceprivate ExecRowresultRowprivate booleanseenFirstprivate booleanseenLastNoPutResultSetsourceprivate intsourceRowWidthprivate CursorResultSettarget-
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
Constructors Constructor Description ScrollInsensitiveResultSet(NoPutResultSet source, Activation activation, int resultSetNumber, int sourceRowWidth, double optimizerEstimatedRowCount, double optimizerEstimatedCost)Constructor for a ScrollInsensitiveResultSet
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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().ExecRowgetAbsoluteRow(int row)Returns the row at the absolute position from the query, and returns NULL when there is no such position.ExecRowgetCurrentRow()Gets information from last getNextRow call.private DataValueDescriptor[]getCurrentRowFromHashtable()Get the column array from the current position in the hash tableExecRowgetFirstRow()Returns the first row from the query, and returns NULL when there are no rows.ExecRowgetLastRow()Returns the last row from the query, and returns NULL when there are no rows.ExecRowgetNextRowCore()Return the requested values computed from the next row (if any) for which the restriction evaluates to true.private ExecRowgetNextRowFromSource()ExecRowgetPreviousRow()Returns the previous row from the query, and returns NULL when there are no more previous rows.ExecRowgetRelativeRow(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.RowLocationgetRowLocation()Gets information from its source.intgetRowNumber()Returns the row number of the current row.longgetTimeSpent(int type)Return the total amount of time spent in this ResultSetbooleanisDeleted()Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSEbooleanisForUpdate()Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is truebooleanisUpdated()Returns TRUE if the row was been updated within the transaction, otherwise returns FALSEvoidmarkRowAsDeleted()Marks 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 voidpositionInLastFetchedRow()Positions the cursor in the last fetched row.voidreopenCore()reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...ExecRowsetAfterLastRow()Sets the current position to after the last row and returns NULL because there is no current row.ExecRowsetBeforeFirstRow()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 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 Detail
-
source
public NoPutResultSet source
-
sourceRowWidth
private int sourceRowWidth
-
ht
private BackingStoreHashtable ht
-
resultRow
private ExecRow 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
private SQLInteger positionInHashTable
-
target
private CursorResultSet target
-
needsRepositioning
private boolean needsRepositioning
-
POS_ROWLOCATION
private static final int POS_ROWLOCATION
- See Also:
- Constant Field Values
-
POS_ROWDELETED
private static final int POS_ROWDELETED
- See Also:
- Constant Field Values
-
POS_ROWUPDATED
private static final int POS_ROWUPDATED
- See Also:
- Constant Field Values
-
LAST_EXTRA_COLUMN
private static final int LAST_EXTRA_COLUMN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
openCore
public void openCore() throws StandardExceptionopen 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
public void reopenCore() throws StandardExceptionreopen 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:
NoPutResultSet.openCore()
-
getAbsoluteRow
public ExecRow getAbsoluteRow(int row) throws StandardException
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:
Row
-
getRelativeRow
public ExecRow getRelativeRow(int row) throws StandardException
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:
Row
-
setBeforeFirstRow
public ExecRow 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:
Row
-
getFirstRow
public ExecRow getFirstRow() throws StandardException
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:
Row
-
getNextRowCore
public ExecRow getNextRowCore() throws StandardException
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:
NoPutResultSet.getNextRowCore()
-
getPreviousRow
public ExecRow getPreviousRow() throws StandardException
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:
Row
-
getLastRow
public ExecRow getLastRow() throws StandardException
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:
Row
-
setAfterLastRow
public ExecRow setAfterLastRow() throws StandardException
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:
Row
-
checkRowPosition
public boolean checkRowPosition(int isType) throws StandardExceptionDetermine 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
private ExecRow getNextRowFromSource() throws StandardException
- Throws:
StandardException
-
close
public void close() throws StandardExceptionIf the result set has been opened, close the open scan.- Specified by:
closein interfaceResultSet- Overrides:
closein classNoPutResultSetImpl- Throws:
StandardException- thrown on error
-
finish
public void finish() throws StandardExceptionDescription 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
public RowLocation getRowLocation() throws StandardException
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:
CursorResultSet
-
getCurrentRow
public ExecRow getCurrentRow() throws StandardException
Gets information from last getNextRow call.- Specified by:
getCurrentRowin interfaceCursorResultSet- Returns:
- the last row returned.
- Throws:
StandardException- thrown on failure.- See Also:
CursorResultSet
-
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
private ExecRow getRowFromHashTable(int position) throws StandardException
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
private DataValueDescriptor[] getRowArrayFromHashTable(int position) throws StandardException
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
private void positionInLastFetchedRow() throws StandardExceptionPositions 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
public void updateRow(ExecRow row, RowChanger rowChanger) throws StandardException
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:
Sets the updated column of the hash table to true and updates the row in the hash table with the new values for the row.
-
markRowAsDeleted
public void markRowAsDeleted() throws StandardExceptionDescription 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:
Sets the deleted column of the hash table to true in the current row.
-
isDeleted
public boolean isDeleted() throws StandardExceptionReturns 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
public boolean isUpdated() throws StandardExceptionReturns 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
private DataValueDescriptor[] getCurrentRowFromHashtable() throws StandardException
Get the column array from the current position in the hash table- Throws:
StandardException
-
-