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 30 import org.apache.derby.iapi.sql.conn.StatementContext; 31 32 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 33 import org.apache.derby.iapi.sql.ResultSet; 34 import org.apache.derby.iapi.sql.execute.ExecRow; 35 import org.apache.derby.iapi.types.DataValueDescriptor; 36 import org.apache.derby.iapi.sql.Activation; 37 38 import org.apache.derby.iapi.services.loader.GeneratedMethod; 39 40 import org.apache.derby.iapi.error.StandardException; 41 42 49 public class AnyResultSet extends NoPutResultSetImpl 50 { 51 52 55 private ExecRow rowWithNulls; 56 57 58 private StatementContext statementContext; 59 60 public final NoPutResultSet source; 63 private GeneratedMethod emptyRowFun; 64 public int subqueryNumber; 65 public int pointOfAttachment; 66 67 public AnyResultSet(NoPutResultSet s, Activation a, GeneratedMethod emptyRowFun, 71 int resultSetNumber, int subqueryNumber, 72 int pointOfAttachment, 73 double optimizerEstimatedRowCount, 74 double optimizerEstimatedCost) 75 { 76 super(a, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost); 77 source = s; 78 this.emptyRowFun = emptyRowFun; 79 this.subqueryNumber = subqueryNumber; 80 this.pointOfAttachment = pointOfAttachment; 81 constructorTime += getElapsedMillis(beginTime); 82 } 83 84 88 95 public void openCore() throws StandardException 96 { 97 102 if (isOpen) 103 { 104 reopenCore(); 105 return; 106 } 107 108 beginTime = getCurrentTimeMillis(); 109 110 source.openCore(); 111 112 115 if (statementContext == null) 116 { 117 statementContext = getLanguageConnectionContext().getStatementContext(); 118 } 119 statementContext.setSubqueryResultSet(subqueryNumber, this, 120 activation.getNumSubqueries()); 121 122 numOpens++; 123 isOpen = true; 124 openTime += getElapsedMillis(beginTime); 125 } 126 127 134 public void reopenCore() throws StandardException 135 { 136 beginTime = getCurrentTimeMillis(); 137 if (SanityManager.DEBUG) 138 SanityManager.ASSERT(isOpen, "AnyResultSet already open"); 139 140 source.reopenCore(); 141 numOpens++; 142 143 openTime += getElapsedMillis(beginTime); 144 } 145 146 public void finish() throws StandardException 147 { 148 source.finish(); 149 finishAndRTS(); 150 } 151 152 157 public ExecRow getNextRowCore() throws StandardException 158 { 159 ExecRow candidateRow = null; 160 ExecRow secondRow = null; 161 ExecRow result = null; 162 163 beginTime = getCurrentTimeMillis(); 164 if (SanityManager.DEBUG) { 167 SanityManager.ASSERT( isOpen, "AnyResultSet not open"); 168 } 169 170 if ( isOpen ) 171 { 172 candidateRow = source.getNextRowCore(); 173 if (candidateRow != null) 174 { 175 result = candidateRow; 176 } 177 else if (rowWithNulls == null) 178 { 179 rowWithNulls = (ExecRow) emptyRowFun.invoke(activation); 180 result = rowWithNulls; 181 } 182 else 183 { 184 result = rowWithNulls; 185 } 186 } 187 188 currentRow = result; 189 setCurrentRow(result); 190 rowsSeen++; 191 192 nextTime += getElapsedMillis(beginTime); 193 return result; 194 } 195 196 202 public void close() throws StandardException 203 { 204 beginTime = getCurrentTimeMillis(); 205 if ( isOpen ) 206 { 207 clearCurrentRow(); 212 213 source.close(); 214 215 super.close(); 216 } 217 else 218 if (SanityManager.DEBUG) 219 SanityManager.DEBUG("CloseRepeatInfo","Close of AnyResultSet repeated"); 220 221 closeTime += getElapsedMillis(beginTime); 222 } 223 224 227 public int getPointOfAttachment() 228 { 229 return pointOfAttachment; 230 } 231 232 240 public long getTimeSpent(int type) 241 { 242 long totTime = constructorTime + openTime + nextTime + closeTime; 243 244 if (type == NoPutResultSet.CURRENT_RESULTSET_ONLY) 245 { 246 return totTime - source.getTimeSpent(ENTIRE_RESULTSET_TREE); 247 } 248 else 249 { 250 return totTime; 251 } 252 } 253 } 254 | Popular Tags |