use of org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource in project derby by apache.
the class MergeSort method openSortRowSource.
/**
* Open a row source to get rows out of the sorter.
* @see Sort#openSortRowSource
*/
public ScanControllerRowSource openSortRowSource(TransactionManager tran) throws StandardException {
if (SanityManager.DEBUG)
SanityManager.ASSERT(state == STATE_DONE_INSERTING);
ScanControllerRowSource rowSource = null;
if (mergeRuns == null || mergeRuns.size() == 0) {
// There were no merge runs so we can just return
// the rows from the sort buffer.
scan = new SortBufferRowSource(sortBuffer, tran, sortObserver, false, sortBufferMax);
rowSource = (ScanControllerRowSource) scan;
// The scan now owns the sort buffer
sortBuffer = null;
} else {
// Dump the rows in the sort buffer to a merge run.
long containerId = createMergeRun(tran, sortBuffer);
mergeRuns.addElement(containerId);
// the number of merge runs
if (mergeRuns.size() > ExternalSortFactory.DEFAULT_MAX_MERGE_RUN || mergeRuns.size() > sortBuffer.capacity())
multiStageMerge(tran);
// There are now few enough merge runs to sort
// at once, so create a rowSource for them.
MergeScanRowSource msRowSource = new MergeScanRowSource(this, tran, sortBuffer, mergeRuns, sortObserver, false);
if (!msRowSource.init(tran)) {
throw StandardException.newException(SQLState.SORT_COULD_NOT_INIT);
}
scan = msRowSource;
rowSource = msRowSource;
// The scan now owns the sort buffer and merge runs.
sortBuffer = null;
mergeRuns = null;
}
// Ready to start retrieving rows.
this.state = STATE_SCANNING;
return rowSource;
}
use of org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource in project derby by apache.
the class RAMTransaction method openSortRowSource.
/**
* @see TransactionController#openSortRowSource
* @exception StandardException Standard error policy.
*/
public RowLocationRetRowSource openSortRowSource(long id) throws StandardException {
Sort sort;
// if it doesn't exist.
if (sorts == null || id >= sorts.size() || (sort = (sorts.get((int) id))) == null) {
throw StandardException.newException(SQLState.AM_NO_SUCH_SORT, id);
}
// Open a scan row source on it.
ScanControllerRowSource sc = sort.openSortRowSource(this);
// Keep track of it so we can release on close.
scanControllers.add((ScanManager) sc);
return sc;
}
Aggregations