1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 29 import org.apache.derby.iapi.services.stream.InfoStreams; 30 31 import org.apache.derby.iapi.services.io.Formatable; 32 33 import org.apache.derby.iapi.sql.execute.CursorResultSet; 34 import org.apache.derby.iapi.sql.ResultSet; 35 import org.apache.derby.iapi.sql.execute.ExecRow; 36 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 37 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 38 39 import org.apache.derby.iapi.sql.Activation; 40 41 import org.apache.derby.iapi.store.access.ColumnOrdering; 42 import org.apache.derby.iapi.store.access.SortObserver; 43 import org.apache.derby.iapi.store.access.TransactionController; 44 import org.apache.derby.iapi.store.access.ScanController; 45 46 import org.apache.derby.iapi.jdbc.ConnectionContext; 47 48 import org.apache.derby.iapi.services.loader.GeneratedMethod; 49 import org.apache.derby.iapi.services.loader.ClassFactory; 50 51 import org.apache.derby.iapi.sql.execute.ExecutionContext; 52 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 53 54 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 55 import org.apache.derby.iapi.error.StandardException; 56 57 import org.apache.derby.iapi.types.RowLocation; 58 import org.apache.derby.iapi.reference.SQLState; 59 60 import org.apache.derby.iapi.services.io.FormatableArrayHolder; 61 import org.apache.derby.impl.jdbc.EmbedSQLWarning; 62 63 import java.util.Properties ; 64 import java.util.Vector ; 65 import java.sql.SQLException ; 66 67 72 abstract class GenericAggregateResultSet extends NoPutResultSetImpl 73 { 74 protected GenericAggregator[] aggregates; 75 protected GeneratedMethod rowAllocator; 76 protected AggregatorInfoList aggInfoList; 77 public NoPutResultSet source; 78 protected NoPutResultSet originalSource; 80 91 GenericAggregateResultSet 92 ( 93 NoPutResultSet s, 94 int aggregateItem, 95 Activation a, 96 GeneratedMethod ra, 97 int resultSetNumber, 98 double optimizerEstimatedRowCount, 99 double optimizerEstimatedCost 100 ) 101 throws StandardException 102 { 103 super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost); 104 source = s; 105 originalSource = s; 106 107 108 rowAllocator = ra; 109 110 aggInfoList = (AggregatorInfoList) (a.getPreparedStatement().getSavedObject(aggregateItem)); 111 aggregates = getSortAggregators(aggInfoList, false, 112 a.getLanguageConnectionContext(), s); 113 } 114 115 131 protected final GenericAggregator[] getSortAggregators 132 ( 133 AggregatorInfoList list, 134 boolean eliminateDistincts, 135 LanguageConnectionContext lcc, 136 NoPutResultSet inputResultSet 137 ) throws StandardException 138 { 139 GenericAggregator aggregators[]; 140 Vector tmpAggregators = new Vector (); 141 ClassFactory cf = lcc.getLanguageConnectionFactory().getClassFactory(); 142 143 int count = list.size(); 144 for (int i = 0; i < count; i++) 145 { 146 AggregatorInfo aggInfo = (AggregatorInfo) list.elementAt(i); 147 if (! (eliminateDistincts && aggInfo.isDistinct())) 148 { 150 tmpAggregators.addElement(new GenericAggregator(aggInfo, cf)); 151 } 152 } 153 154 155 156 aggregators = new GenericAggregator[tmpAggregators.size()]; 157 tmpAggregators.copyInto(aggregators); 158 160 return aggregators; 161 } 162 163 180 protected final ExecIndexRow finishAggregation(ExecIndexRow row) 181 throws StandardException 182 { 183 int size = aggregates.length; 184 185 192 if (row == null) 193 { 194 row = getExecutionFactory().getIndexableRow((ExecRow) rowAllocator.invoke(activation)); 195 } 196 197 setCurrentRow(row); 198 currentRow = row; 199 200 boolean eliminatedNulls = false; 201 for (int i = 0; i < size; i++) 202 { 203 GenericAggregator currAggregate = aggregates[i]; 204 if (currAggregate.finish(row)) 205 eliminatedNulls = true; 206 } 207 208 if (eliminatedNulls) 209 addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.LANG_NULL_ELIMINATED_IN_SET_FUNCTION)); 210 211 return row; 212 } 213 214 public void finish() throws StandardException { 215 source.finish(); 216 super.finish(); 217 } 218 219 } 220 | Popular Tags |