org.apache.derby.impl.store.access.sort
Class MergeScanRowSource

java.lang.Object
  extended byorg.apache.derby.impl.store.access.sort.Scan
      extended byorg.apache.derby.impl.store.access.sort.SortScan
          extended byorg.apache.derby.impl.store.access.sort.MergeScan
              extended byorg.apache.derby.impl.store.access.sort.MergeScanRowSource
All Implemented Interfaces:
GenericScanController, GroupFetchScanController, RowCountable, RowLocationRetRowSource, RowSource, ScanController, ScanControllerRowSource, ScanInfo, ScanManager

public class MergeScanRowSource
extends MergeScan
implements ScanControllerRowSource

Wrapping the output of a MergeScan in a RowSource for the benefit of the createAndLoadConglomerate and loadConglomerate interface. The output of a MergeScan is written to a file when we need more than one level of merge runs. MergeScan implements ScanController, this class just implements the RowSource interface.


Field Summary
 
Fields inherited from class org.apache.derby.impl.store.access.sort.MergeScan
mergeRuns, openScans, sortBuffer
 
Fields inherited from class org.apache.derby.impl.store.access.sort.SortScan
current, hold, sort, tran
 
Fields inherited from interface org.apache.derby.iapi.store.access.ScanController
GE, GT, NA
 
Constructor Summary
(package private) MergeScanRowSource(MergeSort sort, TransactionManager tran, SortBuffer sortBuffer, java.util.Vector mergeRuns, SortObserver sortObserver, boolean hold)
           
 
Method Summary
 void closeRowSource()
          Close the row source - implemented by MergeScan already
 DataValueDescriptor[] getNextRowFromRowSource()
          Get the next row as an array of column objects.
 FormatableBitSet getValidColumns()
          All columns are always set from a sorter
 boolean 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.
 boolean 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.
 boolean next()
          Move to the next position in the scan.
 void rowLocation(RowLocation rl)
          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.
 
Methods inherited from class org.apache.derby.impl.store.access.sort.MergeScan
close, closeForEndTransaction, init, mergeARow
 
Methods inherited from class org.apache.derby.impl.store.access.sort.SortScan
fetch, fetchNext
 
Methods inherited from class org.apache.derby.impl.store.access.sort.Scan
delete, didNotQualify, doesCurrentPositionQualify, fetchLocation, fetchNextGroup, fetchSet, getAllScanInfo, getEstimatedRowCount, getScanInfo, isCurrentPositionDeleted, isKeyed, isTableLocked, newRowLocationTemplate, reopenScan, reopenScanByRowLocation, replace, savePosition, setEstimatedRowCount
 
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.store.access.ScanController
delete, didNotQualify, doesCurrentPositionQualify, fetch, fetchLocation, fetchNext, isCurrentPositionDeleted, replace
 
Methods inherited from interface org.apache.derby.iapi.store.access.GenericScanController
close, getScanInfo, isKeyed, isTableLocked, newRowLocationTemplate, reopenScan, reopenScanByRowLocation
 
Methods inherited from interface org.apache.derby.iapi.store.access.RowCountable
getEstimatedRowCount, setEstimatedRowCount
 

Constructor Detail

MergeScanRowSource

MergeScanRowSource(MergeSort sort,
                   TransactionManager tran,
                   SortBuffer sortBuffer,
                   java.util.Vector mergeRuns,
                   SortObserver sortObserver,
                   boolean hold)
Method Detail

next

public boolean next()
             throws StandardException
Description copied from interface: ScanController
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.

Specified by:
next in interface ScanController
Overrides:
next in class MergeScan
Throws:
StandardException
See Also:
ScanController.next()

getNextRowFromRowSource

public DataValueDescriptor[] getNextRowFromRowSource()
                                              throws StandardException
Description copied from interface: RowSource
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().

Specified by:
getNextRowFromRowSource in interface RowSource
Throws:
StandardException - Cloudscape Standard Error Policy

needsRowLocation

public boolean needsRowLocation()
Description copied from interface: RowLocationRetRowSource
needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.

Specified by:
needsRowLocation in interface RowLocationRetRowSource
Returns:
true iff this row source expects some row location to be returned
See Also:
RowLocationRetRowSource.needsRowLocation()

needsToClone

public boolean needsToClone()
Description copied from interface: RowSource
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).

Specified by:
needsToClone in interface RowSource
See Also:
RowSource.needsToClone()

rowLocation

public void rowLocation(RowLocation rl)
Description copied from interface: RowLocationRetRowSource
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 guarentee 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).

Specified by:
rowLocation in interface RowLocationRetRowSource
See Also:
RowLocationRetRowSource.rowLocation(org.apache.derby.iapi.types.RowLocation)

getValidColumns

public FormatableBitSet getValidColumns()
All columns are always set from a sorter

Specified by:
getValidColumns in interface RowSource

closeRowSource

public void closeRowSource()
Close the row source - implemented by MergeScan already

Specified by:
closeRowSource in interface RowSource


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.