1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.access.sort.SortBufferScan |
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.services.sanity.SanityManager; |
24 | |
25 | import org.apache.derby.iapi.error.StandardException; |
26 | import org.apache.derby.iapi.store.access.ScanController; |
27 | import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; |
28 | |
29 | /** |
30 | |
31 | A sort scan that just reads rows out of a sorter. |
32 | |
33 | **/ |
34 | |
35 | public class SortBufferScan extends SortScan |
36 | { |
37 | /** |
38 | The sorter we're returning rows from. |
39 | **/ |
40 | protected SortBuffer sortBuffer; |
41 | |
42 | /* |
43 | * Constructors. |
44 | */ |
45 | |
46 | SortBufferScan( |
47 | MergeSort sort, |
48 | TransactionManager tran, |
49 | SortBuffer sortBuffer, |
50 | boolean hold) |
51 | { |
52 | super(sort, tran, hold); |
53 | |
54 | if (SanityManager.DEBUG) |
55 | SanityManager.ASSERT(sortBuffer != null); |
56 | |
57 | this.sortBuffer = sortBuffer; |
58 | } |
59 | |
60 | /* |
61 | * Methods of MergeSortScan |
62 | */ |
63 | |
64 | /** |
65 | Move to the next position in the scan. |
66 | @see ScanController#next |
67 | **/ |
68 | public boolean next() |
69 | throws StandardException |
70 | { |
71 | if (SanityManager.DEBUG) |
72 | { |
73 | SanityManager.ASSERT( |
74 | sortBuffer != null, |
75 | "next() called on scan after scan was closed."); |
76 | } |
77 | |
78 | super.current = sortBuffer.removeFirst(); |
79 | return (super.current != null); |
80 | } |
81 | |
82 | /** |
83 | Close the scan. |
84 | **/ |
85 | public boolean closeForEndTransaction(boolean closeHeldScan) |
86 | { |
87 | if (closeHeldScan || !hold) |
88 | { |
89 | close(); |
90 | return(true); |
91 | } |
92 | else |
93 | { |
94 | return(false); |
95 | } |
96 | |
97 | } |
98 | |
99 | /** |
100 | Close the scan. |
101 | @see ScanController#close |
102 | **/ |
103 | public void close() |
104 | { |
105 | if (super.sort != null) |
106 | { |
107 | sort.doneScanning(this, sortBuffer); |
108 | sortBuffer = null; |
109 | } |
110 | super.close(); |
111 | } |
112 | |
113 | } |