Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

public Class ScrollInsensitiveResultSet

extends NoPutResultSetImpl
implements CursorResultSet
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.execute.CursorResultSet, org.apache.derby.iapi.sql.ResultSet
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.execute.CursorResultSet, .ExecRow, .NoPutResultSet, .RowChanger, org.apache.derby.iapi.sql.Activation, org.apache.derby.iapi.types.RowLocation, .DataValueDescriptor, .SQLBoolean, .SQLInteger, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.store.access.BackingStoreHashtable

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.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private int
private int
private BackingStoreHashtable
private boolean
private static final int
private int
private long
private boolean
public int
public int
private static final int
private static final int
private static final int
private SQLInteger
private int
private ExecRow
private boolean
private boolean
public NoPutResultSet
private int
private CursorResultSet
Inherited from org.apache.derby.impl.sql.execute.NoPutResultSetImpl:
checkNullColsclonedExecRowcncLenresultSetNumbertargetResultSet

Constructor Summary

AccessConstructor and Description
public
ScrollInsensitiveResultSet(NoPutResultSet
The NoPutResultSet from which to get rows to scroll through
source
,
Activation
The activation for this execution
activation
,
int
The resultSetNumber
resultSetNumber
,
int
# of columns in the source row
sourceRowWidth
,
double optimizerEstimatedRowCount, double optimizerEstimatedCost)

Constructor for a ScrollInsensitiveResultSet

Method Summary

Modifier and TypeMethod and Description
private void
addRowToHashTable(ExecRow
The row to add.
sourceRow
,
int
The key
position
,
RowLocation
The rowLocation of the row to add.
rowLoc
,
boolean
Indicates whether the row has been updated.
rowUpdated
)

Add a row to the backing hash table, keyed on position.

public boolean

Returns:

true if before the first row, false otherwise. Returns false when the result set contains no rows.
checkRowPosition
(int
The desired position type
isType
)

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.checkRowPosition.

Implements org.apache.derby.iapi.sql.ResultSet.checkRowPosition.

Determine if the cursor is before the first row in the result set.

public void
close()

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.close.

Implements org.apache.derby.iapi.sql.ResultSet.close.

If the result set has been opened, close the open scan.

public void
finish()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.finish.

Implements org.apache.derby.iapi.sql.ResultSet.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().

public ExecRow

Returns:

The row at the absolute position, or NULL if no such position.
getAbsoluteRow
(int
The position.
row
)

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getAbsoluteRow.

Implements org.apache.derby.iapi.sql.ResultSet.getAbsoluteRow.

Returns the row at the absolute position from the query, and returns NULL when there is no such position.

public ExecRow

Returns:

the last row returned.
getCurrentRow
()

Implements org.apache.derby.iapi.sql.execute.CursorResultSet.getCurrentRow.

Gets information from last getNextRow call.

private DataValueDescriptor[]
getCurrentRowFromHashtable()

Get the column array from the current position in the hash table

public ExecRow

Returns:

The first row, or NULL if no rows.
getFirstRow
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getFirstRow.

Implements org.apache.derby.iapi.sql.ResultSet.getFirstRow.

Returns the first row from the query, and returns NULL when there are no rows.

public ExecRow

Returns:

The last row, or NULL if no rows.
getLastRow
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getLastRow.

Implements org.apache.derby.iapi.sql.ResultSet.getLastRow.

Returns the last row from the query, and returns NULL when there are no rows.

public ExecRow
getNextRowCore()

Implements abstract org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRowCore.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.getNextRowCore.

Return the requested values computed from the next row (if any) for which the restriction evaluates to true.

private ExecRow
public ExecRow

Returns:

The previous row, or NULL if no more previous rows.
getPreviousRow
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getPreviousRow.

Implements org.apache.derby.iapi.sql.ResultSet.getPreviousRow.

Returns the previous row from the query, and returns NULL when there are no more previous rows.

public ExecRow

Returns:

The row at the relative position, or NULL if no such position.
getRelativeRow
(int
The position.
row
)

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getRelativeRow.

Implements org.apache.derby.iapi.sql.ResultSet.getRelativeRow.

Returns the row at the relative position from the current cursor position, and returns NULL when there is no such position.

private DataValueDescriptor[]

Returns:

The row data at that position.
getRowArrayFromHashTable
(int
The specified position.
position
)

Get the row data at the specified position from the hash table.

private ExecRow

Returns:

The row at that position.
getRowFromHashTable
(int
The specified position.
position
)

Get the row at the specified position from the hash table.

public RowLocation

Returns:

the row location of the current cursor row.
getRowLocation
()

Implements org.apache.derby.iapi.sql.execute.CursorResultSet.getRowLocation.

Gets information from its source.

public int

Returns:

the row number, or 0 if not on a row
getRowNumber
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getRowNumber.

Implements org.apache.derby.iapi.sql.ResultSet.getRowNumber.

Returns the row number of the current row.

public long

Returns:

long The total amount of time spent (in milliseconds).
getTimeSpent
(int
CURRENT_RESULTSET_ONLY - time spent only in this ResultSet ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.
type
)

Implements org.apache.derby.iapi.sql.ResultSet.getTimeSpent.

Return the total amount of time spent in this ResultSet

public boolean

Returns:

True if the row has been deleted, otherwise false
isDeleted
()

Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSE

public boolean
isForUpdate()

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.isForUpdate.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.isForUpdate.

Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is true

public boolean

Returns:

True if the row has been deleted, otherwise false
isUpdated
()

Returns TRUE if the row was been updated within the transaction, otherwise returns FALSE

public void
markRowAsDeleted()

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.markRowAsDeleted.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.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.

public void
private void
positionInLastFetchedRow()

Positions the cursor in the last fetched row.

public void
public ExecRow

Returns:

NULL.
setAfterLastRow
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.setAfterLastRow.

Implements org.apache.derby.iapi.sql.ResultSet.setAfterLastRow.

Sets the current position to after the last row and returns NULL because there is no current row.

public ExecRow

Returns:

NULL.
setBeforeFirstRow
()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.setBeforeFirstRow.

Implements org.apache.derby.iapi.sql.ResultSet.setBeforeFirstRow.

Sets the current position to before the first row and returns NULL because there is no current row.

public void
updateRow(ExecRow
new values for the currentRow
row
,
RowChanger
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.
rowChanger
)

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.updateRow.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.updateRow.

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.

Inherited from org.apache.derby.impl.sql.execute.NoPutResultSetImpl:
clearCurrentRowclearOrderableCachecloseRowSourcegetCursorNamegetNextRowFromRowSourcegetResultDescriptiongetValidColumnsneedsRowLocationneedsRowLocationForDeferredCheckConstraintsneedsToCloneoffendingRowLocationpositionScanAtRowLocationprintQualifiersresultSetNumberrowLocationsetCurrentRowsetHasDeferrableCheckssetNeedsRowLocationsetTargetResultSetskipRowskipScanunpackHashValue

Field Detail

afterLastback to summary
private boolean afterLast
beforeFirstback to summary
private boolean beforeFirst
currentPositionback to summary
private int currentPosition
extraColumnsback to summary
private int extraColumns
htback to summary
private BackingStoreHashtable ht
keepAfterCommitback to summary
private boolean keepAfterCommit
LAST_EXTRA_COLUMNback to summary
private static final int LAST_EXTRA_COLUMN
lastPositionback to summary
private int lastPosition
maxRowsback to summary
private long maxRows
needsRepositioningback to summary
private boolean needsRepositioning
numFromHashTableback to summary
public int numFromHashTable
numToHashTableback to summary
public int numToHashTable
POS_ROWDELETEDback to summary
private static final int POS_ROWDELETED
POS_ROWLOCATIONback to summary
private static final int POS_ROWLOCATION
POS_ROWUPDATEDback to summary
private static final int POS_ROWUPDATED
positionInHashTableback to summary
private SQLInteger positionInHashTable
positionInSourceback to summary
private int positionInSource
resultRowback to summary
private ExecRow resultRow
seenFirstback to summary
private boolean seenFirst
seenLastback to summary
private boolean seenLast
sourceback to summary
public NoPutResultSet source
sourceRowWidthback to summary
private int sourceRowWidth
targetback to summary
private CursorResultSet target

Constructor Detail

ScrollInsensitiveResultSetback to summary
public ScrollInsensitiveResultSet(NoPutResultSet source, Activation activation, int resultSetNumber, int sourceRowWidth, double optimizerEstimatedRowCount, double optimizerEstimatedCost) throws StandardException

Constructor for a ScrollInsensitiveResultSet

Parameters
source:NoPutResultSet

The NoPutResultSet from which to get rows to scroll through

activation:Activation

The activation for this execution

resultSetNumber:int

The resultSetNumber

sourceRowWidth:int

# of columns in the source row

Exceptions
StandardException:
on error

Method Detail

addRowToHashTableback to summary
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:ExecRow

The row to add.

position:int

The key

rowLoc:RowLocation

The rowLocation of the row to add.

rowUpdated:boolean

Indicates whether the row has been updated.

checkRowPositionback to summary
public boolean checkRowPosition(int isType) throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.checkRowPosition.

Implements org.apache.derby.iapi.sql.ResultSet.checkRowPosition.

Determine if the cursor is before the first row in the result set.

Parameters
isType:int

Doc from org.apache.derby.iapi.sql.ResultSet.checkRowPosition.

The desired position type

Returns:boolean

true if before the first row, false otherwise. Returns false when the result set contains no rows.

Exceptions
StandardException:
Thrown on error.
closeback to summary
public void close() throws StandardException

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.close.

Implements org.apache.derby.iapi.sql.ResultSet.close.

If the result set has been opened, close the open scan.

Exceptions
StandardException:
thrown on error
finishback to summary
public void finish() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.finish.

Implements org.apache.derby.iapi.sql.ResultSet.finish.

Doc from org.apache.derby.iapi.sql.ResultSet.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(). Will close the result set if it is not already closed.

Exceptions
StandardException:
on error
getAbsoluteRowback to summary
public ExecRow getAbsoluteRow(int row) throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getAbsoluteRow.

Implements org.apache.derby.iapi.sql.ResultSet.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.

Parameters
row:int

The position.

Returns:ExecRow

The row at the absolute position, or NULL if no such position.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
getCurrentRowback to summary
public ExecRow getCurrentRow() throws StandardException

Implements org.apache.derby.iapi.sql.execute.CursorResultSet.getCurrentRow.

Gets information from last getNextRow call.

Returns:ExecRow

the last row returned.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.sql.execute.CursorResultSet.getCurrentRow.

thrown on failure.

See Also
CursorResultSet
getCurrentRowFromHashtableback to summary
private DataValueDescriptor[] getCurrentRowFromHashtable() throws StandardException

Get the column array from the current position in the hash table

getFirstRowback to summary
public ExecRow getFirstRow() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getFirstRow.

Implements org.apache.derby.iapi.sql.ResultSet.getFirstRow.

Returns the first row from the query, and returns NULL when there are no rows.

Returns:ExecRow

The first row, or NULL if no rows.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
getLastRowback to summary
public ExecRow getLastRow() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getLastRow.

Implements org.apache.derby.iapi.sql.ResultSet.getLastRow.

Returns the last row from the query, and returns NULL when there are no rows.

Returns:ExecRow

The last row, or NULL if no rows.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
getNextRowCoreback to summary
public ExecRow getNextRowCore() throws StandardException

Implements abstract org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRowCore.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.getNextRowCore.

Doc from org.apache.derby.iapi.sql.execute.NoPutResultSet.getNextRowCore.

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.

Returns:ExecRow

the next row in the result

Exceptions
StandardException:
thrown on failure
getNextRowFromSourceback to summary
private ExecRow getNextRowFromSource() throws StandardException
getPreviousRowback to summary
public ExecRow getPreviousRow() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getPreviousRow.

Implements org.apache.derby.iapi.sql.ResultSet.getPreviousRow.

Returns the previous row from the query, and returns NULL when there are no more previous rows.

Returns:ExecRow

The previous row, or NULL if no more previous rows.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
getRelativeRowback to summary
public ExecRow getRelativeRow(int row) throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getRelativeRow.

Implements org.apache.derby.iapi.sql.ResultSet.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.

Parameters
row:int

The position.

Returns:ExecRow

The row at the relative position, or NULL if no such position.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
getRowArrayFromHashTableback to summary
private DataValueDescriptor[] getRowArrayFromHashTable(int position) throws StandardException

Get the row data at the specified position from the hash table.

Parameters
position:int

The specified position.

Returns:DataValueDescriptor[]

The row data at that position.

Exceptions
StandardException:
thrown on failure
getRowFromHashTableback to summary
private ExecRow getRowFromHashTable(int position) throws StandardException

Get the row at the specified position from the hash table.

Parameters
position:int

The specified position.

Returns:ExecRow

The row at that position.

Exceptions
StandardException:
thrown on failure
getRowLocationback to summary
public RowLocation getRowLocation() throws StandardException

Implements org.apache.derby.iapi.sql.execute.CursorResultSet.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?

Returns:RowLocation

the row location of the current cursor row.

Exceptions
StandardException:
thrown on failure
See Also
CursorResultSet
getRowNumberback to summary
public int getRowNumber()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getRowNumber.

Implements org.apache.derby.iapi.sql.ResultSet.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).

Returns:int

the row number, or 0 if not on a row

getTimeSpentback to summary
public long getTimeSpent(int type)

Implements org.apache.derby.iapi.sql.ResultSet.getTimeSpent.

Return the total amount of time spent in this ResultSet

Parameters
type:int

CURRENT_RESULTSET_ONLY - time spent only in this ResultSet ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.

Returns:long

long The total amount of time spent (in milliseconds).

isDeletedback to summary
public boolean isDeleted() throws StandardException

Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSE

Returns:boolean

True if the row has been deleted, otherwise false

Exceptions
StandardException:
on error
isForUpdateback to summary
public boolean isForUpdate()

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.isForUpdate.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.isForUpdate.

Doc from org.apache.derby.impl.sql.execute.NoPutResultSetImpl.isForUpdate.

Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is true

Returns:boolean

Whether or not the result set is for update.

isUpdatedback to summary
public boolean isUpdated() throws StandardException

Returns TRUE if the row was been updated within the transaction, otherwise returns FALSE

Returns:boolean

True if the row has been deleted, otherwise false

Exceptions
StandardException:
on error
markRowAsDeletedback to summary
public void markRowAsDeleted() throws StandardException

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.markRowAsDeleted.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.markRowAsDeleted.

Doc from org.apache.derby.iapi.sql.execute.NoPutResultSet.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.

Exceptions
StandardException:
thrown on failure.
See Also
Sets the deleted column of the hash table to true in the current row.
openCoreback to summary
public void openCore() throws StandardException

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.openCore.

open a scan on the source. scan parameters are evaluated at each open, so there is probably some way of altering their values...

Exceptions
StandardException:
thrown on failure
positionInLastFetchedRowback to summary
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.

reopenCoreback to summary
public void reopenCore() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.reopenCore.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.reopenCore.

reopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...

Exceptions
StandardException:
thrown if cursor finished.
setAfterLastRowback to summary
public ExecRow setAfterLastRow() throws StandardException

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.setAfterLastRow.

Implements org.apache.derby.iapi.sql.ResultSet.setAfterLastRow.

Sets the current position to after the last row and returns NULL because there is no current row.

Returns:ExecRow

NULL.

Exceptions
StandardException:
Thrown on failure
See Also
org.apache.derby.iapi.sql.Row
setBeforeFirstRowback to summary
public ExecRow setBeforeFirstRow()

Overrides org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.setBeforeFirstRow.

Implements org.apache.derby.iapi.sql.ResultSet.setBeforeFirstRow.

Sets the current position to before the first row and returns NULL because there is no current row.

Returns:ExecRow

NULL.

See Also
org.apache.derby.iapi.sql.Row
updateRowback to summary
public void updateRow(ExecRow row, RowChanger rowChanger) throws StandardException

Overrides org.apache.derby.impl.sql.execute.NoPutResultSetImpl.updateRow.

Implements org.apache.derby.iapi.sql.execute.NoPutResultSet.updateRow.

Doc from org.apache.derby.iapi.sql.execute.NoPutResultSet.updateRow.

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.

Parameters
row:ExecRow

new values for the currentRow

rowChanger:RowChanger

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.

Exceptions
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.