Top Description Fields Constructors Methods
org.apache.derby.impl.store.access.btree

public abstract Class BTreeScan

extends OpenBTree
implements ScanManager
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.access.conglomerate.ScanManager, org.apache.derby.iapi.store.access.GroupFetchScanController, org.apache.derby.iapi.store.access.GenericScanController, org.apache.derby.iapi.store.access.RowCountable, org.apache.derby.iapi.store.access.ScanController
Known Direct Subclasses
org.apache.derby.impl.store.access.btree.BTreeForwardScan, org.apache.derby.impl.store.access.btree.BTreeMaxScan
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo, .ScanManager, .TransactionManager, org.apache.derby.iapi.store.access.ConglomerateController, .DynamicCompiledOpenConglomInfo, .Qualifier, .RowUtil, .ScanController, .ScanInfo, .StaticCompiledOpenConglomInfo, .BackingStoreHashtable, org.apache.derby.iapi.store.raw.ContainerHandle, .FetchDescriptor, .LockingPolicy, .Page, .RecordHandle, .Transaction, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation, org.apache.derby.impl.store.access.conglomerate.TemplateRow, org.apache.derby.iapi.services.io.FormatableBitSet

A b-tree scan controller corresponds to an instance of an open b-tree scan.

Concurrency Notes

The concurrency rules are derived from OpenBTree.

See Also
OpenBTree

Field Summary

Modifier and TypeField and Description
protected DataValueDescriptor[][]
fetchNext_one_slot_array

A 1 element array to turn fetchNext and fetch calls into fetchNextGroup calls.

protected FetchDescriptor
init_fetchDesc

The fetch descriptor which describes the row to be returned by the scan.

protected boolean
protected boolean
protected FetchDescriptor
init_lock_fetch_desc

A constant FetchDescriptor which describes the position of the RowLocation field within the btree, currently always the last column).

protected Qualifier[][]
protected Transaction
init_rawtran

Hides org.apache.derby.impl.store.access.btree.OpenBTree.init_rawtran.

init_startKeyValue, init_qualifier, and init_stopKeyValue all are used to store * references to the values passed in when ScanController.init() is called.
protected FormatableBitSet
protected DataValueDescriptor[]
protected int
protected DataValueDescriptor[]
protected int
protected DataValueDescriptor[]
protected boolean
init_useUpdateLocks

Whether the scan should requests UPDATE locks which then will be converted to X locks when the actual operation is performed.

protected int
lock_operation

What kind of row locks to get during the scan.

protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
pack-priv BTreeRowPosition
protected int
scan_state

Delay positioning the table at the start position until the first next() call.

protected int
protected int
stat_numpages_visited

Performance counters ...

protected int
protected int
Inherited from org.apache.derby.impl.store.access.btree.OpenBTree:
btree_undocontainererr_containeridinit_lock_levelinit_open_user_scansruntime_mem

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
closeForEndTransaction(boolean
If true, means to close scan even if it has been opened to be kept opened across commit. This is used to close these scans on abort.
closeHeldScan
)

Implements org.apache.derby.iapi.store.access.conglomerate.ScanManager.closeForEndTransaction.

Close the scan, a commit or abort is about to happen.

public boolean
delete()

Implements org.apache.derby.iapi.store.access.ScanController.delete.

Delete the row at the current position of the scan.

public void
didNotQualify()

Implements org.apache.derby.iapi.store.access.ScanController.didNotQualify.

A call to allow client to indicate that current row does not qualify.

public boolean
doesCurrentPositionQualify()

Implements org.apache.derby.iapi.store.access.ScanController.doesCurrentPositionQualify.

Returns true if the current position of the scan still qualifies under the set of qualifiers passed to the openScan().

private void
fetch(DataValueDescriptor[]
The row into which the value of the current position in the scan is to be stored.
row
,
boolean
indicates whether the qualifiers should be applied.
qualify
)

Fetch the row at the current position of the Scan.

public void
fetch(DataValueDescriptor[]
The row into which the value of the current position in the scan is to be stored.
row
)

Implements org.apache.derby.iapi.store.access.ScanController.fetch.

Fetch the row at the current position of the Scan.

public void
fetchLocation(RowLocation templateLocation)

Implements org.apache.derby.iapi.store.access.ScanController.fetchLocation.

Fetch the location of the current position in the scan.

public boolean

Returns:

True if there is a next position in the scan, false if there isn't.
fetchNext
(DataValueDescriptor[]
The template row into which the value of the next position in the scan is to be stored.
row
)

Implements org.apache.derby.iapi.store.access.ScanController.fetchNext.

Fetch the row at the next position of the Scan.

public int

Returns:

The number of qualifying rows found and copied into the provided array of rows. If 0 then the scan is complete, otherwise the return value will be: 1 <= row_count <= row_array.length
fetchNextGroup
(DataValueDescriptor[][]
The array of rows to copy rows into. row_array[].length must >= 1. This routine assumes that all entries in the array contain complete template rows.
row_array
,
RowLocation[]
If non-null, the array of row locations to copy into. If null, no row locations are retrieved.
rowloc_array
)

Implements org.apache.derby.iapi.store.access.GroupFetchScanController.fetchNextGroup.

Fetch the next N rows from the table.

public int
protected abstract int
fetchRows(BTreeRowPosition pos, DataValueDescriptor[][] row_array, RowLocation[] rowloc_array, BackingStoreHashtable hash_table, long max_rowcnt, int[] key_column_numbers)

Fetch the next N rows from the table.

public void
fetchSet(long
The maximum number of rows to insert into the Hash table. Pass in -1 if there is no maximum.
max_rowcnt
,
int[]
The column numbers of the columns in the scan result row to be the key to the Hashtable. "0" is the first column in the scan result row (which may be different than the first column in the row in the table of the scan).
key_column_numbers
,
BackingStoreHashtable
The java HashTable to load into.
hash_table
)

Implements org.apache.derby.iapi.store.access.conglomerate.ScanManager.fetchSet.

Insert all rows that qualify for the current scan into the input Hash table.

public void
fetchWithoutQualify(DataValueDescriptor[]
The row into which the value of the current position in the scan is to be stored.
row
)

Implements org.apache.derby.iapi.store.access.ScanController.fetchWithoutQualify.

Fetch the row at the current position of the Scan without applying the qualifiers.

public RecordHandle
public ScanInfo

Returns:

The ScanInfo object which contains info about current scan.
getScanInfo
()

Implements org.apache.derby.iapi.store.access.GenericScanController.getScanInfo.

Return ScanInfo object which describes performance of scan.

public void
init(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, BTreeLockingPolicy btree_locking_policy, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, BTree conglomerate, LogicalUndo undo, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info)

Initialize the scan for use.

private void
initScanParams(DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator)

Shared initialization code between init() and reopenScan().

public boolean
isCurrentPositionDeleted()

Implements org.apache.derby.iapi.store.access.ScanController.isCurrentPositionDeleted.

Returns true if the current position of the scan is at a deleted row.

pack-priv static boolean

Returns:

true if the page is empty, false otherwise
isEmpty
(Page
the B-tree page to check
page
)

Check if a B-tree page is empty.

public boolean
isHeldAfterCommit()

Implements org.apache.derby.iapi.store.access.ScanController.isHeldAfterCommit.

Return true is the scan has been closed after a commit, but was opened with holdability and can be reopened using positionAtRowLocation.

public boolean

Returns:

whether this is a keyed conglomerate.
isKeyed
()

Implements org.apache.derby.iapi.store.access.GenericScanController.isKeyed.

Return whether this is a keyed conglomerate.

public RowLocation
newRowLocationTemplate()

Implements org.apache.derby.iapi.store.access.GenericScanController.newRowLocationTemplate.

Return a row location object of the correct type to be used in calls to fetchLocation.

public boolean
protected void
positionAtDoneScan(BTreeRowPosition pos)

Do work necessary to close a scan.

protected void
positionAtDoneScanFromClose(BTreeRowPosition
current row position of the scan.
pos
)

Do any necessary work to complete the scan.

protected void
positionAtNextPage(BTreeRowPosition
current row position of the scan.
pos
)

Position scan to 0 slot on next page.

protected void
positionAtPreviousPage()

Position the scan after the last row on the previous page.

public boolean
positionAtRowLocation(RowLocation
RowLocation for the new position for the scan. The RowLocation submitted should be a RowLocation which has previously been returned by this ScanController.
rLoc
)

Implements org.apache.derby.iapi.store.access.ScanController.positionAtRowLocation.

Positions the scan at row location and locks the row.

protected void
positionAtStartForForwardScan(BTreeRowPosition pos)

Position scan at "start" position for a forward scan.

pack-priv abstract void
positionAtStartPosition(BTreeRowPosition pos)

Position scan at "start" position.

protected boolean
process_qualifier(DataValueDescriptor[]
The row with the same partial column list as the row returned by the current scan.
row
)

process_qualifier - Determine if a row meets all qualifier conditions.

public final void
reopenScan(DataValueDescriptor[]
An indexable row which holds a (partial) key value which, in combination with the startSearchOperator, defines the starting position of the scan. If null, the starting position of the scan is the first row of the conglomerate.
startKeyValue
,
int
an operator which defines how the startKeyValue is to be searched for. If startSearchOperation is ScanController.GE, the scan starts on the first row which is greater than or equal to the startKeyValue. If startSearchOperation is ScanController.GT, the scan starts on the first row whose key is greater than startKeyValue. The startSearchOperation parameter is ignored if the startKeyValue parameter is null.
startSearchOperator
,
Qualifier[][]
An array of qualifiers which, applied to each key, restrict the rows returned by the scan. Rows for which any one of the qualifiers returns false are not returned by the scan. If null, all rows are returned.
qualifier
,
DataValueDescriptor[]
An indexable row which holds a (partial) key value which, in combination with the stopSearchOperator, defines the ending position of the scan. If null, the ending position of the scan is the last row of the conglomerate.
stopKeyValue
,
int
an operator which defines how the stopKeyValue is used to determine the scan stopping position. If stopSearchOperation is ScanController.GE, the scan stops just before the first row which is greater than or equal to the stopKeyValue. If stopSearchOperation is ScanController.GT, the scan stops just before the first row whose key is greater than startKeyValue. The stopSearchOperation parameter is ignored if the stopKeyValue parameter is null.
stopSearchOperator
)

Implements org.apache.derby.iapi.store.access.GenericScanController.reopenScan.

Reposition the current scan.

public void
reopenScanByRowLocation(RowLocation
An existing RowLocation within the conglomerate, at which to position the start of the scan. The scan will begin at this location and continue forward until the end of the conglomerate. Positioning at a non-existent RowLocation (ie. an invalid one or one that had been deleted), will result in an exception being thrown when the first next operation is attempted.
startRowLocation
,
Qualifier[][]
An array of qualifiers which, applied to each key, restrict the rows returned by the scan. Rows for which any one of the qualifiers returns false are not returned by the scan. If null, all rows are returned.
qualifier
)

Implements org.apache.derby.iapi.store.access.GenericScanController.reopenScanByRowLocation.

Reposition the current scan.

public boolean
replace(DataValueDescriptor[] row, FormatableBitSet validColumns)

Implements org.apache.derby.iapi.store.access.ScanController.replace.

Replace the entire row at the current position of the scan.

protected boolean

Returns:

returns true if scan has been repositioned successfully, else returns false if the position key could not be found and missing_row_for_key_ok was false indicating that scan could only be positioned on the exact key match.
reposition
(BTreeRowPosition
position to set the scan to.
pos
,
boolean
if true and exact key is not found then scan is just set to key just left of the key (thus a next will move to the key just after "pos")
missing_row_for_key_ok
)

Reposition the scan leaving and reentering the access layer.

pack-priv void
savePositionAndReleasePage(DataValueDescriptor[]
known parts of the key that should be saved, or null if the entire key is unknown and will have to be fetched from the page
partialKey
,
int[]
an array which tells which columns of the partial key are valid (key columns that have 0 in this array are not valid, and their values must be fetched from the page), or null if all the columns are valid
vcols
)

Save the current scan position by key and release the latch on the leaf that's being scanned.

pack-priv void
savePositionAndReleasePage()

Shortcut for for savePositionAndReleasePage(null,null).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.derby.impl.store.access.btree.OpenBTree:
checkConsistencydebugConglomerategetColumnSortOrderInfogetConglomerategetContainergetContainerHandlegetEstimatedRowCountgetHeightgetHoldgetLockingPolicygetLockLevelgetOpenModegetRawTrangetRuntimeMemgetSpaceInfogetXactMgrinitisClosedisIndexableRowConsistentisTableLockedreopensetEstimatedRowCountsetLockingPolicytest_errors