001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.DistinctScanResultSet
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute;
023:
024: import org.apache.derby.iapi.services.loader.GeneratedMethod;
025:
026: import org.apache.derby.iapi.services.monitor.Monitor;
027:
028: import org.apache.derby.iapi.services.sanity.SanityManager;
029:
030: import org.apache.derby.iapi.services.io.Storable;
031:
032: import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
033: import org.apache.derby.iapi.services.stream.InfoStreams;
034:
035: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
036:
037: import org.apache.derby.iapi.error.StandardException;
038:
039: import org.apache.derby.iapi.sql.execute.CursorResultSet;
040: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
041: import org.apache.derby.iapi.sql.execute.ExecRow;
042: import org.apache.derby.iapi.sql.execute.ExecutionContext;
043: import org.apache.derby.iapi.sql.execute.NoPutResultSet;
044:
045: import org.apache.derby.iapi.sql.Activation;
046: import org.apache.derby.iapi.sql.ResultSet;
047:
048: import org.apache.derby.iapi.store.access.ConglomerateController;
049: import org.apache.derby.iapi.store.access.Qualifier;
050: import org.apache.derby.iapi.store.access.ScanController;
051: import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
052: import org.apache.derby.iapi.store.access.TransactionController;
053:
054: import org.apache.derby.iapi.types.RowLocation;
055:
056: import org.apache.derby.iapi.services.io.FormatableBitSet;
057: import org.apache.derby.iapi.services.io.FormatableArrayHolder;
058: import org.apache.derby.iapi.services.io.FormatableIntHolder;
059:
060: import java.util.Enumeration;
061: import java.util.Properties;
062: import java.util.Vector;
063:
064: /**
065: * Eliminates duplicates while scanning the underlying conglomerate.
066: * (Assumes no predicates, for now.)
067: *
068: * @author jerry
069: */
070: class DistinctScanResultSet extends HashScanResultSet {
071:
072: Enumeration element = null;
073:
074: //
075: // class interface
076: //
077: DistinctScanResultSet(long conglomId,
078: StaticCompiledOpenConglomInfo scoci, Activation activation,
079: GeneratedMethod resultRowAllocator, int resultSetNumber,
080: int hashKeyItem, String tableName,
081: String userSuppliedOptimizerOverrides, String indexName,
082: boolean isConstraint, int colRefItem, int lockMode,
083: boolean tableLocked, int isolationLevel,
084: double optimizerEstimatedRowCount,
085: double optimizerEstimatedCost) throws StandardException {
086: super (
087: conglomId,
088: scoci,
089: activation,
090: resultRowAllocator,
091: resultSetNumber,
092: (GeneratedMethod) null, // startKeyGetter
093: 0, // startSearchOperator
094: (GeneratedMethod) null, // stopKeyGetter
095: 0, // stopSearchOperator
096: false, // sameStartStopPosition
097: (Qualifier[][]) null, // scanQualifiers
098: (Qualifier[][]) null, // nextQualifiers
099: DEFAULT_INITIAL_CAPACITY, DEFAULT_LOADFACTOR,
100: DEFAULT_MAX_CAPACITY, hashKeyItem, tableName,
101: userSuppliedOptimizerOverrides,
102: indexName,
103: isConstraint,
104: false, // forUpdate
105: colRefItem, lockMode, tableLocked, isolationLevel,
106: false, optimizerEstimatedRowCount,
107: optimizerEstimatedCost);
108:
109: // Tell super class to eliminate duplicates
110: eliminateDuplicates = true;
111: }
112:
113: //
114: // ResultSet interface (override methods from HashScanResultSet)
115: //
116:
117: /**
118: * Return the next row (if any) from the scan (if open).
119: *
120: * @exception StandardException thrown on failure to get next row
121: */
122: public ExecRow getNextRowCore() throws StandardException {
123: ExecRow result = null;
124: Object[] columns = null;
125:
126: beginTime = getCurrentTimeMillis();
127: if (isOpen) {
128: if (firstNext) {
129: element = hashtable.elements();
130: firstNext = false;
131: }
132:
133: if (element.hasMoreElements()) {
134: columns = (Object[]) element.nextElement();
135:
136: setCompatRow(compactRow, columns);
137:
138: rowsSeen++;
139:
140: result = compactRow;
141: }
142: // else done
143: }
144:
145: currentRow = result;
146: setCurrentRow(result);
147:
148: nextTime += getElapsedMillis(beginTime);
149: return result;
150: }
151: }
|