org.apache.derby.impl.sql.execute
Class ScrollInsensitiveResultSet

java.lang.Object
  extended by org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
      extended by org.apache.derby.impl.sql.execute.NoPutResultSetImpl
          extended by 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.


Field Summary
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  int 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.ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
 
Fields inherited from interface org.apache.derby.iapi.sql.execute.NoPutResultSet
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE
 
Constructor Summary
ScrollInsensitiveResultSet(NoPutResultSet source, Activation activation, int resultSetNumber, int sourceRowWidth, double optimizerEstimatedRowCount, double optimizerEstimatedCost)
          Constructor for a ScrollInsensitiveResultSet
 
Method Summary
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.
 ExecRow 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 ResultSet
 boolean isDeleted()
          Returns TRUE if the row was been deleted within the transaction, otherwise returns FALSE
 boolean 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
 boolean isUpdated()
          Returns TRUE if the row was been updated within the transaction, otherwise returns FALSE
 void 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, needsToClone, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan
 
Methods inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
addWarning, attachStatementContext, checkCancellationFlag, cleanUp, dumpTimeStats, finishAndRTS, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentTimeMillis, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getLanguageConnectionContext, getNextRow, getPointOfAttachment, getScanIsolationLevel, getSubqueryTrackingArray, getTransactionController, getWarnings, isClosed, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, requiresRelocking, returnsRows, setCompactRow, setCompatRow
 
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
cleanUp, clearCurrentRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getNextRow, getResultDescription, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows
 

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 int 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 through
activation - The activation for this execution
resultSetNumber - The resultSetNumber
sourceRowWidth - # 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 interface NoPutResultSet
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 interface NoPutResultSet
Overrides:
reopenCore in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getAbsoluteRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getRelativeRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
setBeforeFirstRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getFirstRow in class BasicNoPutResultSetImpl
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 interface NoPutResultSet
Specified by:
getNextRowCore in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getPreviousRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getLastRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
setAfterLastRow in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
checkRowPosition in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
getRowNumber in class BasicNoPutResultSetImpl
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 interface ResultSet
Overrides:
close in class NoPutResultSetImpl
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 interface ResultSet
Overrides:
finish in class BasicNoPutResultSetImpl
Throws:
StandardException - on error

getTimeSpent

public long getTimeSpent(int type)
Return the total amount of time spent in this ResultSet

Specified by:
getTimeSpent in interface ResultSet
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 interface CursorResultSet
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 interface CursorResultSet
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 key
rowLoc - 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 interface NoPutResultSet
Overrides:
updateRow in class NoPutResultSetImpl
Parameters:
row - new values for the currentRow
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.
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 interface NoPutResultSet
Overrides:
markRowAsDeleted in class NoPutResultSetImpl
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 interface NoPutResultSet
Overrides:
isForUpdate in class NoPutResultSetImpl
Returns:
Whether or not the result set is for update.

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.