KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > sort > SortScan


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.sort.SortScan
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.access.sort;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.services.io.FormatableBitSet;
27
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.services.io.Storable;
30
31 import org.apache.derby.iapi.error.StandardException;
32
33 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
34 import org.apache.derby.iapi.store.access.RowUtil;
35 import org.apache.derby.iapi.store.access.ScanController;
36
37 import org.apache.derby.iapi.types.DataValueDescriptor;
38
39
40 /**
41
42   Abstract base class for merge sort scans.
43
44 **/

45
46 public abstract class SortScan extends Scan
47 {
48
49     /**
50     The sort that this class is scanning.
51     **/

52     protected MergeSort sort = null;
53
54     /**
55     The transactionManager that opened this scan.
56     **/

57     protected TransactionManager tran = null;
58
59     /**
60     The row at the current position of the scan, from which
61     fetch will return values.
62     **/

63     protected DataValueDescriptor[] current;
64
65     /**
66     The row at the current position of the scan, from which
67     fetch will return values.
68     **/

69     protected boolean hold;
70
71     /*
72      * Constructors
73      */

74     SortScan(MergeSort sort, TransactionManager tran, boolean hold)
75     {
76         super();
77         this.sort = sort;
78         this.tran = tran;
79         this.hold = hold;
80     }
81
82     /*
83      * Abstract methods of Scan
84      */

85
86     /**
87     Fetch the row at the next position of the Scan.
88
89     If there is a valid next position in the scan then
90     the value in the template storable row is replaced
91     with the value of the row at the current scan
92     position. The columns of the template row must
93     be of the same type as the actual columns in the
94     underlying conglomerate.
95
96     The resulting contents of templateRow after a fetchNext()
97     which returns false is undefined.
98
99     The result of calling fetchNext(row) is exactly logically
100     equivalent to making a next() call followed by a fetch(row)
101     call. This interface allows implementations to optimize
102     the 2 calls if possible.
103
104     RESOLVE (mikem - 2/24/98) - come back to this and see if
105     coding this differently saves in sort scans, as did the
106     heap recoding.
107
108     @param row The template row into which the value
109     of the next position in the scan is to be stored.
110
111     @return True if there is a next position in the scan,
112     false if there isn't.
113
114     @exception StandardException Standard exception policy.
115     **/

116     public final boolean fetchNext(DataValueDescriptor[] row)
117         throws StandardException
118     {
119         boolean ret_val = next();
120
121         if (ret_val)
122             fetch(row);
123
124         return(ret_val);
125     }
126
127     /**
128     Fetch the row at the current position of the Scan.
129     @see ScanController#fetch
130     **/

131     public final void fetch(DataValueDescriptor[] result)
132         throws StandardException
133     {
134         if (SanityManager.DEBUG)
135         {
136             SanityManager.ASSERT(sort != null);
137         }
138
139         if (current == null)
140         {
141             throw StandardException.newException(
142                     SQLState.SORT_SCAN_NOT_POSITIONED);
143         }
144
145         // Make sure the passed in template row is of the correct type.
146
sort.checkColumnTypes(result);
147
148         // RESOLVE
149
// Note that fetch() basically throws away the object's passed in.
150
// We should figure out how to allow callers in this situation to
151
// not go through the work of allocating objects in the first place.
152

153         // Sort has allocated objects for this row, and will not
154
// reference them any more. So just pass the objects out
155
// to the caller instead of copying them into the provided
156
// objects.
157
System.arraycopy(current, 0, result, 0, result.length);
158     }
159
160     /**
161     Fetch the row at the current position of the Scan and does not apply the
162     qualifiers.
163     
164     This method will always throw an exception.
165     (SQLState.SORT_IMPROPER_SCAN_METHOD)
166     
167     @see ScanController#fetchWithoutQualify
168     **/

169     public final void fetchWithoutQualify(DataValueDescriptor[] result)
170         throws StandardException
171     {
172         throw StandardException.newException(
173                 SQLState.SORT_IMPROPER_SCAN_METHOD);
174
175     }
176     
177     /**
178     Close the scan. @see ScanController#close
179     **/

180     public void close()
181     {
182         sort = null;
183         current = null;
184
185         tran.closeMe(this);
186     }
187
188     /*
189      * Methods of SortScan. Arranged alphabetically.
190      */

191 }
192
Popular Tags