001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.sort.MergeScanRowSource
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.access.sort;
023:
024: import org.apache.derby.iapi.reference.SQLState;
025:
026: import org.apache.derby.iapi.services.io.FormatableBitSet;
027: import org.apache.derby.iapi.services.sanity.SanityManager;
028:
029: import org.apache.derby.iapi.error.StandardException;
030: import org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource;
031: import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
032: import org.apache.derby.iapi.store.access.SortObserver;
033: import org.apache.derby.iapi.store.access.RowLocationRetRowSource;
034:
035: import org.apache.derby.iapi.types.DataValueDescriptor;
036:
037: import org.apache.derby.iapi.types.RowLocation;
038:
039: import java.util.Vector;
040:
041: /**
042: Wrapping the output of a MergeScan in a RowSource for the benefit of the
043: createAndLoadConglomerate and loadConglomerate interface. The output of a
044:
045: MergeScan is written to a file when we need more than one level of merge
046: runs.
047:
048: MergeScan implements ScanController, this class just implements the
049: RowSource interface.
050: */
051: public class MergeScanRowSource extends MergeScan implements
052: ScanControllerRowSource {
053:
054: /* Constructors for This class: */
055: MergeScanRowSource(MergeSort sort, TransactionManager tran,
056: SortBuffer sortBuffer, Vector mergeRuns,
057: SortObserver sortObserver, boolean hold) {
058: super (sort, tran, sortBuffer, mergeRuns, sortObserver, hold);
059: }
060:
061: /*
062: * Disable illegal and dangerous scan controller interface call
063: * @exception StandardException This is an illegal operation
064: */
065: public boolean next() throws StandardException {
066: throw StandardException
067: .newException(SQLState.SORT_IMPROPER_SCAN_METHOD);
068: }
069:
070: /* Private/Protected methods of This class: */
071: /* Public Methods of This class: */
072: /* Public Methods of RowSource class: */
073:
074: public DataValueDescriptor[] getNextRowFromRowSource()
075: throws StandardException {
076: DataValueDescriptor[] row = sortBuffer.removeFirst();
077:
078: if (row != null) {
079: mergeARow(sortBuffer.getLastAux());
080: }
081:
082: return row;
083: }
084:
085: /**
086: * @see RowLocationRetRowSource#needsRowLocation
087: */
088: public boolean needsRowLocation() {
089: return false;
090: }
091:
092: /**
093: * @see org.apache.derby.iapi.store.access.RowSource#needsToClone
094: */
095: public boolean needsToClone() {
096: return false;
097: }
098:
099: /**
100: * @see RowLocationRetRowSource#rowLocation
101: */
102: public void rowLocation(RowLocation rl) {
103: if (SanityManager.DEBUG)
104: SanityManager
105: .THROWASSERT("unexpected call to RowSource.rowLocation");
106: }
107:
108: /**
109: All columns are always set from a sorter
110: */
111: public FormatableBitSet getValidColumns() {
112: return null;
113: }
114:
115: /**
116: Close the row source - implemented by MergeScan already
117: */
118: public void closeRowSource() {
119: close();
120: }
121:
122: }
|