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.sql.execute.CursorResultSet; 32 import org.apache.derby.iapi.sql.execute.ExecRow; 33 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 34 35 import org.apache.derby.iapi.sql.Activation; 36 import org.apache.derby.iapi.sql.ResultDescription; 37 38 import org.apache.derby.iapi.error.StandardException; 39 40 import org.apache.derby.iapi.services.loader.GeneratedMethod; 41 42 import org.apache.derby.iapi.types.RowLocation; 43 44 55 class RowResultSet extends NoPutResultSetImpl 56 implements CursorResultSet { 57 58 59 public int rowsReturned; 60 61 private boolean canCacheRow; 62 private boolean next; 63 private GeneratedMethod row; 64 private ExecRow cachedRow; 65 66 RowResultSet 70 ( 71 Activation activation, 72 GeneratedMethod row, 73 boolean canCacheRow, 74 int resultSetNumber, 75 double optimizerEstimatedRowCount, 76 double optimizerEstimatedCost 77 ) 78 { 79 super(activation, resultSetNumber, 80 optimizerEstimatedRowCount, optimizerEstimatedCost); 81 82 this.row = row; 83 this.canCacheRow = canCacheRow; 84 constructorTime += getElapsedMillis(beginTime); 85 } 86 87 90 RowResultSet 91 ( 92 Activation activation, 93 ExecRow constantRow, 94 boolean canCacheRow, 95 int resultSetNumber, 96 double optimizerEstimatedRowCount, 97 double optimizerEstimatedCost 98 ) 99 { 100 super(activation, resultSetNumber, 101 optimizerEstimatedRowCount, optimizerEstimatedCost); 102 103 beginTime = getCurrentTimeMillis(); 104 this.cachedRow = constantRow; 105 this.canCacheRow = canCacheRow; 106 constructorTime += getElapsedMillis(beginTime); 107 } 108 109 113 118 public void openCore() throws StandardException 119 { 120 next = false; 121 beginTime = getCurrentTimeMillis(); 122 isOpen = true; 123 numOpens++; 124 125 openTime += getElapsedMillis(beginTime); 126 } 127 128 134 public ExecRow getNextRowCore() throws StandardException { 135 136 currentRow = null; 137 beginTime = getCurrentTimeMillis(); 138 if (isOpen) 139 { 140 if (!next) 141 { 142 next = true; 143 if (currentRow == null) 144 { 145 if (cachedRow != null) 146 { 147 currentRow = cachedRow; 148 } 149 else if (row != null) 150 { 151 currentRow = (ExecRow) row.invoke(activation); 152 if (canCacheRow) 153 { 154 cachedRow = currentRow; 155 } 156 } 157 } 158 rowsReturned++; 159 } 160 setCurrentRow(currentRow); 161 162 nextTime += getElapsedMillis(beginTime); 163 } 164 return currentRow; 165 } 166 167 172 public void close() throws StandardException 173 { 174 beginTime = getCurrentTimeMillis(); 175 if (isOpen) { 176 177 clearCurrentRow(); 182 next = false; 183 184 super.close(); 185 } 186 else 187 if (SanityManager.DEBUG) 188 SanityManager.DEBUG("CloseRepeatInfo","Close of RowResultSet repeated"); 189 190 closeTime += getElapsedMillis(beginTime); 191 } 192 193 201 public long getTimeSpent(int type) 202 { 203 long totTime = constructorTime + openTime + nextTime + closeTime; 204 return totTime; 205 } 206 207 211 219 public RowLocation getRowLocation() { 220 if (SanityManager.DEBUG) 221 SanityManager.THROWASSERT("RowResultSet used in positioned update/delete"); 222 return null; 223 } 224 225 233 public ExecRow getCurrentRow() { 234 if (SanityManager.DEBUG) 235 SanityManager.THROWASSERT("RowResultSet used in positioned update/delete"); 236 return null; 237 } 238 } 239 | Popular Tags |