1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.access.sort.Scan |
4 | |
5 | Copyright 1997, 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.store.access.BackingStoreHashtable; |
26 | import org.apache.derby.iapi.services.io.FormatableBitSet; |
27 | import org.apache.derby.iapi.services.i18n.MessageService; |
28 | |
29 | import org.apache.derby.iapi.services.io.Storable; |
30 | |
31 | import org.apache.derby.iapi.types.Orderable; |
32 | import org.apache.derby.iapi.types.RowLocation; |
33 | |
34 | import org.apache.derby.iapi.error.StandardException; |
35 | |
36 | import org.apache.derby.iapi.store.access.conglomerate.Conglomerate; |
37 | import org.apache.derby.iapi.store.access.conglomerate.ScanManager; |
38 | |
39 | import org.apache.derby.iapi.store.access.Qualifier; |
40 | import org.apache.derby.iapi.store.access.ScanController; |
41 | import org.apache.derby.iapi.store.access.ScanInfo; |
42 | |
43 | import org.apache.derby.iapi.store.raw.Page; |
44 | |
45 | import org.apache.derby.iapi.types.DataValueDescriptor; |
46 | |
47 | import java.util.Properties; |
48 | |
49 | /** |
50 | |
51 | Abstract base class for all sort classes which return rows from the |
52 | sort. Subclasses must implement fetch, next, and close. |
53 | |
54 | **/ |
55 | |
56 | public abstract class Scan implements ScanManager, ScanInfo |
57 | { |
58 | /* |
59 | * Methods of ScanController |
60 | */ |
61 | |
62 | /** |
63 | * A call to allow client to indicate that current row does not qualify. |
64 | * <p> |
65 | * Indicates to the ScanController that the current row does not |
66 | * qualify for the scan. If the isolation level of the scan allows, |
67 | * this may result in the scan releasing the lock on this row. |
68 | * <p> |
69 | * Note that some scan implimentations may not support releasing locks on |
70 | * non-qualifying rows, or may delay releasing the lock until sometime |
71 | * later in the scan (ie. it may be necessary to keep the lock until |
72 | * either the scan is repositioned on the next row or page). |
73 | * <p> |
74 | * This call should only be made while the scan is positioned on a current |
75 | * valid row. |
76 | * <p> |
77 | * This call does not make sense for sort scans. |
78 | * |
79 | * @exception StandardException Standard exception policy. |
80 | **/ |
81 | public void didNotQualify() |
82 | throws StandardException |
83 | { |
84 | } |
85 | |
86 | /** |
87 | * Fetch the next N rows from the table. |
88 | * <p> |
89 | * Currently unimplemented for sorts. |
90 | * <p> |
91 | **/ |
92 | public int fetchNextGroup( |
93 | DataValueDescriptor[][] row_array, |
94 | RowLocation[] rowloc_array) |
95 | throws StandardException |
96 | { |
97 | throw StandardException.newException( |
98 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
99 | } |
100 | |
101 | public int fetchNextGroup( |
102 | DataValueDescriptor[][] row_array, |
103 | RowLocation[] old_rowloc_array, |
104 | RowLocation[] new_rowloc_array) |
105 | throws StandardException |
106 | { |
107 | throw StandardException.newException( |
108 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
109 | } |
110 | |
111 | |
112 | /** |
113 | * Insert all rows that qualify for the current scan into the input |
114 | * Hash table. |
115 | * <p> |
116 | * Currently unimplemented for sorts. |
117 | * <p> |
118 | **/ |
119 | public void fetchSet( |
120 | long max_rowcnt, |
121 | int[] key_column_numbers, |
122 | BackingStoreHashtable hash_table) |
123 | throws StandardException |
124 | { |
125 | throw StandardException.newException( |
126 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
127 | } |
128 | |
129 | /** |
130 | Returns true if the current position of the scan still qualifies |
131 | under the set of qualifiers passed to the openScan(). |
132 | @see ScanController#doesCurrentPositionQualify |
133 | **/ |
134 | public boolean doesCurrentPositionQualify() |
135 | throws StandardException |
136 | { |
137 | return true; |
138 | } |
139 | |
140 | /** |
141 | Fetch the location of the current position in the scan. |
142 | @see ScanController#fetchLocation |
143 | **/ |
144 | public void fetchLocation(RowLocation templateLocation) |
145 | throws StandardException |
146 | { |
147 | throw StandardException.newException( |
148 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
149 | } |
150 | |
151 | /** |
152 | * Return ScanInfo object which describes performance of scan. |
153 | * <p> |
154 | * Return ScanInfo object which contains information about the current |
155 | * scan. |
156 | * <p> |
157 | * Currently the ScanInfo does not have any performance data. |
158 | * |
159 | * @see ScanInfo |
160 | * |
161 | * @return The ScanInfo object which contains info about current scan. |
162 | * |
163 | * @exception StandardException Standard exception policy. |
164 | **/ |
165 | public ScanInfo getScanInfo() |
166 | throws StandardException |
167 | { |
168 | return(this); |
169 | } |
170 | |
171 | /** |
172 | * Get the total estimated number of rows in the container. |
173 | * <p> |
174 | * The number is a rough estimate and may be grossly off. In general |
175 | * the server will cache the row count and then occasionally write |
176 | * the count unlogged to a backing store. If the system happens to |
177 | * shutdown before the store gets a chance to update the row count it |
178 | * may wander from reality. |
179 | * <p> |
180 | * This call is currently only supported on Heap conglomerates, it |
181 | * will throw an exception if called on btree conglomerates. |
182 | * |
183 | * @return The total estimated number of rows in the conglomerate. |
184 | * |
185 | * @exception StandardException Standard exception policy. |
186 | **/ |
187 | public long getEstimatedRowCount() |
188 | throws StandardException |
189 | { |
190 | throw StandardException.newException( |
191 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
192 | } |
193 | |
194 | /** |
195 | * Set the total estimated number of rows in the container. |
196 | * <p> |
197 | * Often, after a scan, the client of RawStore has a much better estimate |
198 | * of the number of rows in the container than what store has. For |
199 | * instance if we implement some sort of update statistics command, or |
200 | * just after a create index a complete scan will have been done of the |
201 | * table. In this case this interface allows the client to set the |
202 | * estimated row count for the container, and store will use that number |
203 | * for all future references. |
204 | * <p> |
205 | * This call is currently only supported on Heap conglomerates, it |
206 | * will throw an exception if called on btree conglomerates. |
207 | * |
208 | * @param count the estimated number of rows in the container. |
209 | * |
210 | * @exception StandardException Standard exception policy. |
211 | **/ |
212 | public void setEstimatedRowCount(long count) |
213 | throws StandardException |
214 | { |
215 | throw StandardException.newException( |
216 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
217 | } |
218 | |
219 | /** |
220 | Returns true if the current position of the scan is at a |
221 | deleted row. |
222 | @see ScanController#isCurrentPositionDeleted |
223 | **/ |
224 | public boolean isCurrentPositionDeleted() |
225 | throws StandardException |
226 | { |
227 | throw StandardException.newException( |
228 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
229 | } |
230 | |
231 | /** |
232 | * Return whether this is a keyed conglomerate. |
233 | * <p> |
234 | * |
235 | * @return whether this is a keyed conglomerate. |
236 | **/ |
237 | public boolean isKeyed() |
238 | { |
239 | return(false); |
240 | } |
241 | |
242 | /** |
243 | * Return whether this scan is table locked. |
244 | * |
245 | * @return whether this is table locked. |
246 | **/ |
247 | public boolean isTableLocked() |
248 | { |
249 | return(true); |
250 | } |
251 | |
252 | /** |
253 | Delete the row at the current position of the scan. |
254 | @see ScanController#delete |
255 | **/ |
256 | public boolean delete() |
257 | throws StandardException |
258 | { |
259 | throw StandardException.newException( |
260 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
261 | } |
262 | |
263 | /** |
264 | Reposition the current scan. |
265 | @see ScanController#reopenScan |
266 | **/ |
267 | public void reopenScan( |
268 | DataValueDescriptor[] startKeyValue, |
269 | int startSearchOperator, |
270 | Qualifier qualifier[][], |
271 | DataValueDescriptor[] stopKeyValue, |
272 | int stopSearchOperator) |
273 | throws StandardException |
274 | { |
275 | throw StandardException.newException( |
276 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
277 | } |
278 | |
279 | /** |
280 | Reposition the current scan. This call is semantically the same as if |
281 | the current scan had been closed and a openScan() had been called instead. |
282 | The scan is reopened against the same conglomerate, and the scan |
283 | is reopened with the same "scan column list", "hold" and "forUpdate" |
284 | parameters passed in the original openScan. |
285 | |
286 | @exception StandardException Standard exception policy. |
287 | **/ |
288 | public void reopenScanByRowLocation( |
289 | RowLocation startRowLocation, |
290 | Qualifier qualifier[][]) |
291 | throws StandardException |
292 | { |
293 | throw StandardException.newException( |
294 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
295 | } |
296 | |
297 | /** |
298 | Replace the entire row at the current position of the scan. |
299 | @see ScanController#replace |
300 | **/ |
301 | public boolean replace( |
302 | DataValueDescriptor[] val, |
303 | FormatableBitSet validColumns) |
304 | throws StandardException |
305 | { |
306 | throw StandardException.newException( |
307 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
308 | } |
309 | |
310 | /** |
311 | Return a row location object of the correct type to be |
312 | used in calls to fetchLocation. |
313 | @see ScanController#newRowLocationTemplate |
314 | **/ |
315 | public RowLocation newRowLocationTemplate() |
316 | throws StandardException |
317 | { |
318 | throw StandardException.newException( |
319 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
320 | } |
321 | |
322 | /** |
323 | *@see ScanController#positionAtRowLocation |
324 | */ |
325 | public boolean positionAtRowLocation(RowLocation rl) |
326 | throws StandardException |
327 | { |
328 | throw StandardException.newException( |
329 | SQLState.SORT_IMPROPER_SCAN_METHOD); |
330 | } |
331 | |
332 | /* |
333 | ** Methods of ScanManager |
334 | */ |
335 | |
336 | /** |
337 | * Do work necessary to maintain the current position in the scan. |
338 | * <p> |
339 | * The latched page in the conglomerate "congomid" is changing, do |
340 | * whatever is necessary to maintain the current position of the scan. |
341 | * For some conglomerates this may be a no-op. |
342 | * <p> |
343 | * |
344 | * @param conglom Conglomerate object of the conglomerate being changed. |
345 | * @param page Page in the conglomerate being changed. |
346 | * |
347 | * @exception StandardException Standard exception policy. |
348 | **/ |
349 | public void savePosition(Conglomerate conglom, Page page) |
350 | throws StandardException |
351 | { |
352 | // RESOLVE (mikem), under the current implementation all scans within |
353 | // a transaction are called rather than just the ones with the right |
354 | // conglomid. For now just have sort scans ignore the call. |
355 | |
356 | return; |
357 | } |
358 | |
359 | /* |
360 | * Methods of ScanInfo |
361 | */ |
362 | |
363 | /** |
364 | * Return all information gathered about the scan. |
365 | * <p> |
366 | * This routine returns a list of properties which contains all information |
367 | * gathered about the scan. If a Property is passed in, then that property |
368 | * list is appeneded to, otherwise a new property object is created and |
369 | * returned. |
370 | * <p> |
371 | * Currently sort scans doesn't track any information. |
372 | * |
373 | * @param prop Property list to fill in. |
374 | * |
375 | * @exception StandardException Standard exception policy. |
376 | **/ |
377 | public Properties getAllScanInfo(Properties prop) |
378 | throws StandardException |
379 | { |
380 | if (prop == null) |
381 | prop = new Properties(); |
382 | |
383 | prop.put( |
384 | MessageService.getTextMessage(SQLState.STORE_RTS_SCAN_TYPE), |
385 | MessageService.getTextMessage(SQLState.STORE_RTS_SORT)); |
386 | |
387 | return(prop); |
388 | } |
389 | } |