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

public Class SortBufferRowSource

extends Scan
implements ScanControllerRowSource
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource, org.apache.derby.iapi.store.access.RowLocationRetRowSource, org.apache.derby.iapi.store.access.RowSource, org.apache.derby.iapi.store.access.ScanController, org.apache.derby.iapi.store.access.GenericScanController, org.apache.derby.iapi.store.access.RowCountable
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.SortObserver, org.apache.derby.iapi.types.RowLocation, .DataValueDescriptor, org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource, .TransactionManager, org.apache.derby.iapi.services.io.FormatableBitSet

Wrapping the output of a SortBuffer in a RowSource for the benefit of the createAndLoadConglomerate and loadConglomerate interface. Scan implements ScanController, this class just implements the RowSource interface.

Field Summary

Modifier and TypeField and Description
private int
pack-priv SortBuffer
sortBuffer

The Sort buffer where rows come from

private SortObserver
protected TransactionManager
tran

The TransactionManager that opened this scan.

private boolean

Constructor Summary

AccessConstructor and Description
pack-priv
SortBufferRowSource(SortBuffer sortBuffer, TransactionManager tran, SortObserver sortObserver, boolean writingToDisk, int maxFreeListSize)

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

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

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

Fetch the row at the current position of the Scan.

public final boolean
fetchNext(DataValueDescriptor[]
The destRow 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 (partial) row at the next position of the Scan.

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

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

Fetch the row at the current position of the Scan and does not apply the qualifiers.

public DataValueDescriptor[]
getNextRowFromRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Get the next row as an array of column objects.

public FormatableBitSet
getValidColumns()

Implements org.apache.derby.iapi.store.access.RowSource.getValidColumns.

All columns are always set from a sorter

public boolean
needsRowLocation()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.

public boolean
public boolean
needsToClone()

Implements org.apache.derby.iapi.store.access.RowSource.needsToClone.

Does the caller of getNextRowFromRowSource() need to clone the row in order to keep a reference to the row past the getNextRowFromRowSource() call which returned the row.

public boolean
public void
public void
rowLocation(RowLocation rl)

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

rowLocation is a callback for the drainer of the row source to return the rowLocation of the current row, i.e, the row that is being returned by getNextRowFromRowSource.

Inherited from org.apache.derby.impl.store.access.sort.Scan:
deletedidNotQualifydoesCurrentPositionQualifyfetchLocationfetchNextGroupfetchNextGroupfetchSetgetAllScanInfogetEstimatedRowCountgetScanInfoisCurrentPositionDeletedisHeldAfterCommitisKeyedisTableLockednewRowLocationTemplatepositionAtRowLocationreopenScanreopenScanByRowLocationreplacesetEstimatedRowCount

Field Detail

maxFreeListSizeback to summary
private int maxFreeListSize
sortBufferback to summary
pack-priv SortBuffer sortBuffer

The Sort buffer where rows come from

sortObserverback to summary
private SortObserver sortObserver
tranback to summary
protected TransactionManager tran

The TransactionManager that opened this scan.

writingToDiskback to summary
private boolean writingToDisk

Constructor Detail

SortBufferRowSourceback to summary
pack-priv SortBufferRowSource(SortBuffer sortBuffer, TransactionManager tran, SortObserver sortObserver, boolean writingToDisk, int maxFreeListSize)

Method Detail

closeback to summary
public void close()

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

Close the scan

closeForEndTransactionback to summary
public boolean closeForEndTransaction(boolean closeHeldScan)

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

Close the scan

Parameters
closeHeldScan:boolean

Doc from org.apache.derby.iapi.store.access.conglomerate.ScanManager.closeForEndTransaction.

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.

Returns:boolean

Doc from org.apache.derby.iapi.store.access.conglomerate.ScanManager.closeForEndTransaction.

boolean indicating that the close has resulted in a real close of the scan. A held scan will return false if called by closeForEndTransaction(false), otherwise it will return true. A non-held scan will always return true.

closeRowSourceback to summary
public void closeRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.closeRowSource.

Close the rowSource

fetchback to summary
public void fetch(DataValueDescriptor[] result) throws StandardException

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

Fetch the row at the current position of the Scan.

Parameters
result:DataValueDescriptor[]

Doc from org.apache.derby.iapi.store.access.ScanController.fetch.

The row into which the value of the current position in the scan is to be stored.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.store.access.ScanController.fetch.

Standard exception policy.

See Also
org.apache.derby.iapi.store.access.ScanController#fetch
fetchNextback to summary
public final boolean fetchNext(DataValueDescriptor[] row) throws StandardException

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

Doc from org.apache.derby.iapi.store.access.ScanController.fetchNext.

Fetch the (partial) row at the next position of the Scan. If there is a valid next position in the scan then the value in the destRow storable row is replaced with the value of the row at the current scan position. The columns of the destRow row must be of the same type as the actual columns in the underlying conglomerate. The resulting contents of destRow after a fetchNext() which returns false is undefined. The result of calling fetchNext(row) is exactly logically equivalent to making a next() call followed by a fetch(row) call. This interface allows implementations to optimize the 2 calls if possible.

Parameters
row:DataValueDescriptor[]

The destRow row into which the value of the next position in the scan is to be stored.

Returns:boolean

True if there is a next position in the scan, false if there isn't.

Exceptions
StandardException:
Standard exception policy.
fetchWithoutQualifyback to summary
public void fetchWithoutQualify(DataValueDescriptor[] result) throws StandardException

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

Fetch the row at the current position of the Scan and does not apply the qualifiers. This method will always throw an exception. (SQLState.SORT_IMPROPER_SCAN_METHOD)

Parameters
result:DataValueDescriptor[]

Doc from org.apache.derby.iapi.store.access.ScanController.fetchWithoutQualify.

The row into which the value of the current position in the scan is to be stored.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.store.access.ScanController.fetchWithoutQualify.

Standard exception policy.

See Also
org.apache.derby.iapi.store.access.ScanController#fetchWithoutQualify
getNextRowFromRowSourceback to summary
public DataValueDescriptor[] getNextRowFromRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Doc from org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Get the next row as an array of column objects. The column objects can be a JBMS Storable or any Serializable/Externalizable/Formattable/Streaming type.
A return of null indicates that the complete set of rows has been read.

A null column can be specified by leaving the object null, or indicated by returning a non-null getValidColumns. On streaming columns, it can be indicated by returning a non-null get FieldStates.

If RowSource.needToClone() is true then the returned row (the DataValueDescriptor[]) is guaranteed not to be modified by drainer of the RowSource (except that the input stream will be read, of course) and drainer will keep no reference to it before making the subsequent nextRow call. So it is safe to return the same DataValueDescriptor[] in subsequent nextRow calls if that is desirable for performance reasons.

If RowSource.needToClone() is false then the returned row (the DataValueDescriptor[]) may be be modified by drainer of the RowSource, and the drainer may keep a reference to it after making the subsequent nextRow call. In this case the client should severe all references to the row after returning it from getNextRowFromRowSource().

getValidColumnsback to summary
public FormatableBitSet getValidColumns()

Implements org.apache.derby.iapi.store.access.RowSource.getValidColumns.

All columns are always set from a sorter

needsRowLocationback to summary
public boolean needsRowLocation()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

Doc from org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.

Returns:boolean

true iff this row source expects some row location to be returned

needsRowLocationForDeferredCheckConstraintsback to summary
public boolean needsRowLocationForDeferredCheckConstraints()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocationForDeferredCheckConstraints.

needsToCloneback to summary
public boolean needsToClone()

Implements org.apache.derby.iapi.store.access.RowSource.needsToClone.

Doc from org.apache.derby.iapi.store.access.RowSource.needsToClone.

Does the caller of getNextRowFromRowSource() need to clone the row in order to keep a reference to the row past the getNextRowFromRowSource() call which returned the row. This call must always return the same for all rows in a RowSource (ie. the caller will call this once per scan from a RowSource and assume the behavior is true for all rows in the RowSource).

See Also
org.apache.derby.iapi.store.access.RowSource#needsToClone
nextback to summary
public boolean next() throws StandardException

Implements org.apache.derby.iapi.store.access.ScanController.next, org.apache.derby.iapi.store.access.GroupFetchScanController.next.

Doc from org.apache.derby.iapi.store.access.ScanController.next.

Move to the next position in the scan. If this is the first call to next(), the position is set to the first row. Returns false if there is not a next row to move to. It is possible, but not guaranteed, that this method could return true again, after returning false, if some other operation in the same transaction appended a row to the underlying conglomerate.

Returns:boolean

True if there is a next position in the scan, false if there isn't.

Exceptions
StandardException:
Standard exception policy.
offendingRowLocationback to summary
public void offendingRowLocation(RowLocation rl, long containdId) throws StandardException

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.offendingRowLocation.

rowLocationback to summary
public void rowLocation(RowLocation rl)

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

Doc from org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

rowLocation is a callback for the drainer of the row source to return the rowLocation of the current row, i.e, the row that is being returned by getNextRowFromRowSource. This interface is for the purpose of loading a base table with index. In that case, the indices can be built at the same time the base table is laid down once the row location of the base row is known. This is an example pseudo code on how this call is expected to be used:

		boolean needsRL = rowSource.needsRowLocation();
		DataValueDescriptor[] row;
		while((row = rowSource.getNextRowFromRowSource()) != null)
		{
			RowLocation rl = heapConglomerate.insertRow(row);
			if (needsRL)
				rowSource.rowLocation(rl);
		}
		

NeedsRowLocation and rowLocation will ONLY be called by a drainer of the row source which CAN return a row location. Drainer of row source which cannot return rowLocation will guarantee to not call either callbacks. Conversely, if NeedsRowLocation is called and it returns true, then for every row return by getNextRowFromRowSource, a rowLocation callback must also be issued with the row location of the row. Implementor of both the source and the drain of the row source must be aware of this protocol.
The RowLocation object is own by the caller of rowLocation, in other words, the drainer of the RowSource. This is so that we don't need to new a row location for every row. If the Row Source wants to keep the row location, it needs to clone it (RowLocation is a ClonableObject).