KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > DistinctScanResultSet


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.DistinctScanResultSet
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.sql.execute;
23
24 import org.apache.derby.iapi.services.loader.GeneratedMethod;
25
26 import org.apache.derby.iapi.services.monitor.Monitor;
27
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import org.apache.derby.iapi.services.io.Storable;
31
32 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
33 import org.apache.derby.iapi.services.stream.InfoStreams;
34
35 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
36
37 import org.apache.derby.iapi.error.StandardException;
38
39
40 import org.apache.derby.iapi.sql.execute.CursorResultSet;
41 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
42 import org.apache.derby.iapi.sql.execute.ExecRow;
43 import org.apache.derby.iapi.sql.execute.ExecutionContext;
44 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
45
46 import org.apache.derby.iapi.sql.Activation;
47 import org.apache.derby.iapi.sql.ResultSet;
48
49 import org.apache.derby.iapi.store.access.ConglomerateController;
50 import org.apache.derby.iapi.store.access.Qualifier;
51 import org.apache.derby.iapi.store.access.ScanController;
52 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
53 import org.apache.derby.iapi.store.access.TransactionController;
54
55 import org.apache.derby.iapi.types.RowLocation;
56
57 import org.apache.derby.iapi.services.io.FormatableBitSet;
58 import org.apache.derby.iapi.services.io.FormatableArrayHolder;
59 import org.apache.derby.iapi.services.io.FormatableIntHolder;
60
61 import java.util.Enumeration JavaDoc;
62 import java.util.Properties JavaDoc;
63 import java.util.Vector JavaDoc;
64
65 /**
66  * Eliminates duplicates while scanning the underlying conglomerate.
67  * (Assumes no predicates, for now.)
68  *
69  * @author jerry
70  */

71 class DistinctScanResultSet extends HashScanResultSet
72 {
73
74     Enumeration JavaDoc element = null;
75
76
77     //
78
// class interface
79
//
80
DistinctScanResultSet(long conglomId,
81         StaticCompiledOpenConglomInfo scoci, Activation activation,
82         GeneratedMethod resultRowAllocator,
83         int resultSetNumber,
84         int hashKeyItem,
85         String JavaDoc tableName,
86         String JavaDoc userSuppliedOptimizerOverrides,
87         String JavaDoc indexName,
88         boolean isConstraint,
89         int colRefItem,
90         int lockMode,
91         boolean tableLocked,
92         int isolationLevel,
93         double optimizerEstimatedRowCount,
94         double optimizerEstimatedCost)
95             throws StandardException
96     {
97         super(conglomId, scoci, activation, resultRowAllocator, resultSetNumber,
98               (GeneratedMethod) null, // startKeyGetter
99
0, // startSearchOperator
100
(GeneratedMethod) null, // stopKeyGetter
101
0, // stopSearchOperator
102
false, // sameStartStopPosition
103
(Qualifier[][]) null, // scanQualifiers
104
(Qualifier[][]) null, // nextQualifiers
105
DEFAULT_INITIAL_CAPACITY, DEFAULT_LOADFACTOR, DEFAULT_MAX_CAPACITY,
106               hashKeyItem, tableName, userSuppliedOptimizerOverrides, indexName, isConstraint,
107               false, // forUpdate
108
colRefItem, lockMode, tableLocked, isolationLevel,
109               false,
110               optimizerEstimatedRowCount, optimizerEstimatedCost);
111
112         // Tell super class to eliminate duplicates
113
eliminateDuplicates = true;
114     }
115
116     //
117
// ResultSet interface (override methods from HashScanResultSet)
118
//
119

120     /**
121      * Return the next row (if any) from the scan (if open).
122      *
123      * @exception StandardException thrown on failure to get next row
124      */

125     public ExecRow getNextRowCore() throws StandardException
126     {
127         ExecRow result = null;
128         Object JavaDoc[] columns = null;
129
130         beginTime = getCurrentTimeMillis();
131         if ( isOpen )
132         {
133             if (firstNext)
134             {
135                 element = hashtable.elements();
136                 firstNext = false;
137             }
138
139             if (element.hasMoreElements())
140             {
141                 columns = (Object JavaDoc[]) element.nextElement();
142
143                 setCompatRow(compactRow, columns);
144
145                 rowsSeen++;
146
147                 result = compactRow;
148             }
149             // else done
150
}
151
152         currentRow = result;
153         setCurrentRow(result);
154
155         nextTime += getElapsedMillis(beginTime);
156         return result;
157     }
158 }
159
Popular Tags