1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.access.sort.MergeScanRowSource |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.store.access.sort; |
22 | |
23 | import org.apache.derby.iapi.reference.SQLState; |
24 | |
25 | import org.apache.derby.iapi.services.io.FormatableBitSet; |
26 | import org.apache.derby.iapi.services.sanity.SanityManager; |
27 | |
28 | import org.apache.derby.iapi.error.StandardException; |
29 | import org.apache.derby.iapi.store.access.conglomerate.ScanControllerRowSource; |
30 | import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; |
31 | import org.apache.derby.iapi.store.access.SortObserver; |
32 | import org.apache.derby.iapi.store.access.RowLocationRetRowSource; |
33 | |
34 | import org.apache.derby.iapi.types.DataValueDescriptor; |
35 | |
36 | import org.apache.derby.iapi.types.RowLocation; |
37 | |
38 | import java.util.Vector; |
39 | |
40 | /** |
41 | Wrapping the output of a MergeScan in a RowSource for the benefit of the |
42 | createAndLoadConglomerate and loadConglomerate interface. The output of a |
43 | |
44 | MergeScan is written to a file when we need more than one level of merge |
45 | runs. |
46 | |
47 | MergeScan implements ScanController, this class just implements the |
48 | RowSource interface. |
49 | */ |
50 | public class MergeScanRowSource extends MergeScan implements ScanControllerRowSource |
51 | { |
52 | |
53 | /* Constructors for This class: */ |
54 | MergeScanRowSource( |
55 | MergeSort sort, |
56 | TransactionManager tran, |
57 | SortBuffer sortBuffer, |
58 | Vector mergeRuns, |
59 | SortObserver sortObserver, |
60 | boolean hold) |
61 | { |
62 | super(sort, tran, sortBuffer, mergeRuns, sortObserver, hold); |
63 | } |
64 | |
65 | /* |
66 | * Disable illegal and dangerous scan controller interface call |
67 | * @exception StandardException This is an illegal operation |
68 | */ |
69 | public boolean next() throws StandardException |
70 | { |
71 | throw StandardException.newException( |
72 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
73 | } |
74 | |
75 | /* Private/Protected methods of This class: */ |
76 | /* Public Methods of This class: */ |
77 | /* Public Methods of RowSource class: */ |
78 | |
79 | |
80 | public DataValueDescriptor[] getNextRowFromRowSource() |
81 | throws StandardException |
82 | { |
83 | DataValueDescriptor[] row = sortBuffer.removeFirst(); |
84 | |
85 | if (row != null) |
86 | { |
87 | mergeARow(sortBuffer.getLastAux()); |
88 | } |
89 | |
90 | return row; |
91 | } |
92 | |
93 | /** |
94 | * @see RowLocationRetRowSource#needsRowLocation |
95 | */ |
96 | public boolean needsRowLocation() |
97 | { |
98 | return false; |
99 | } |
100 | |
101 | /** |
102 | * @see org.apache.derby.iapi.store.access.RowSource#needsToClone |
103 | */ |
104 | public boolean needsToClone() |
105 | { |
106 | return false; |
107 | } |
108 | |
109 | |
110 | /** |
111 | * @see RowLocationRetRowSource#rowLocation |
112 | */ |
113 | public void rowLocation(RowLocation rl) |
114 | { |
115 | if (SanityManager.DEBUG) |
116 | SanityManager.THROWASSERT("unexpected call to RowSource.rowLocation"); |
117 | } |
118 | |
119 | |
120 | /** |
121 | All columns are always set from a sorter |
122 | */ |
123 | public FormatableBitSet getValidColumns() |
124 | { |
125 | return null; |
126 | } |
127 | |
128 | /** |
129 | Close the row source - implemented by MergeScan already |
130 | */ |
131 | public void closeRowSource() |
132 | { |
133 | close(); |
134 | } |
135 | |
136 | } |
137 | |