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 boolean
afterLast
private boolean
beforeFirst
private int
currentPosition
private int
extraColumns
private BackingStoreHashtable
ht
private boolean
keepAfterCommit
private static int
LAST_EXTRA_COLUMN
private int
lastPosition
private long
maxRows
private boolean
needsRepositioning
int
numFromHashTable
int
numToHashTable
private static int
POS_ROWDELETED
private static int
POS_ROWLOCATION
private static int
POS_ROWUPDATED
private SQLInteger
positionInHashTable
private int
positionInSource
private ExecRow
resultRow
private boolean
seenFirst
private boolean
seenLast
NoPutResultSet
source
private int
sourceRowWidth
private CursorResultSet
target
-
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 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().ExecRow
getAbsoluteRow(int row)
Returns the row at the absolute position from the query, and returns NULL when there is no such position.ExecRow
getCurrentRow()
Gets information from last getNextRow call.private DataValueDescriptor[]
getCurrentRowFromHashtable()
Get the column array from the current position in the hash tableExecRow
getFirstRow()
Returns the first row from the query, and returns NULL when there are no rows.ExecRow
getLastRow()
Returns the last row from the query, and returns NULL when there are no rows.ExecRow
getNextRowCore()
Return the requested values computed from the next row (if any) for which the restriction evaluates to true.private ExecRow
getNextRowFromSource()
ExecRow
getPreviousRow()
Returns the previous row from the query, and returns NULL when there are no more previous rows.ExecRow
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.RowLocation
getRowLocation()
Gets information from its source.int
getRowNumber()
Returns the row number of the current row.long
getTimeSpent(int type)
Return the total amount of time spent in this ResultSetboolean
isDeleted()
Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSEboolean
isForUpdate()
Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is trueboolean
isUpdated()
Returns TRUE if the row was been updated within the transaction, otherwise returns FALSEvoid
markRowAsDeleted()
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
positionInLastFetchedRow()
Positions the cursor in the last fetched row.void
reopenCore()
reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...ExecRow
setAfterLastRow()
Sets the current position to after the last row and returns NULL because there is no current row.ExecRow
setBeforeFirstRow()
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 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 StandardException
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
public void reopenCore() throws StandardException
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:
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:
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:
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:
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:
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:
setBeforeFirstRow
in interfaceResultSet
- Overrides:
setBeforeFirstRow
in 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:
getFirstRow
in interfaceResultSet
- Overrides:
getFirstRow
in 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: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:
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:
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:
Row
-
getLastRow
public ExecRow getLastRow() throws StandardException
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:
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:
setAfterLastRow
in interfaceResultSet
- Overrides:
setAfterLastRow
in classBasicNoPutResultSetImpl
- Returns:
- NULL.
- Throws:
StandardException
- Thrown on failure- See Also:
Row
-
checkRowPosition
public boolean checkRowPosition(int isType) throws StandardException
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
private ExecRow getNextRowFromSource() throws StandardException
- Throws:
StandardException
-
close
public void close() throws StandardException
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
public void finish() throws StandardException
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
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:
getRowLocation
in 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:
getCurrentRow
in 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 StandardException
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
public void updateRow(ExecRow row, RowChanger rowChanger) throws StandardException
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:
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 StandardException
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:
Sets the deleted column of the hash table to true in the current row.
-
isDeleted
public boolean isDeleted() throws StandardException
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
public boolean isUpdated() throws StandardException
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
private DataValueDescriptor[] getCurrentRowFromHashtable() throws StandardException
Get the column array from the current position in the hash table- Throws:
StandardException
-
-