1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.sql.execute.CursorResultSet; 25 import org.apache.derby.iapi.error.StandardException; 26 27 import org.apache.derby.iapi.sql.ResultSet; 28 import org.apache.derby.iapi.sql.execute.ExecRow; 29 import org.apache.derby.iapi.sql.execute.ExecIndexRow; 30 import org.apache.derby.iapi.sql.execute.ExecutionContext; 31 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 32 33 import org.apache.derby.iapi.sql.Activation; 34 35 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 36 37 import org.apache.derby.iapi.store.access.ConglomerateController; 38 import org.apache.derby.iapi.store.access.GenericScanController; 39 import org.apache.derby.iapi.store.access.Qualifier; 40 import org.apache.derby.iapi.store.access.ScanController; 41 import org.apache.derby.iapi.store.access.TransactionController; 42 43 import org.apache.derby.iapi.services.sanity.SanityManager; 44 45 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 46 47 import org.apache.derby.iapi.services.loader.GeneratedMethod; 48 49 import org.apache.derby.iapi.services.io.FormatableBitSet; 50 51 import java.util.Properties ; 52 53 59 class LastIndexKeyResultSet extends NoPutResultSetImpl 60 { 61 protected ExecRow candidate; 62 63 protected long conglomId; 66 protected GeneratedMethod resultRowAllocator; 67 protected GeneratedMethod startKeyGetter; 68 protected int startSearchOperator; 69 protected GeneratedMethod stopKeyGetter; 70 protected int stopSearchOperator; 71 protected Qualifier[][] qualifiers; 72 public String tableName; 73 public String userSuppliedOptimizerOverrides; 74 public String indexName; 75 protected boolean runTimeStatisticsOn; 76 protected FormatableBitSet accessedCols; 77 78 public int isolationLevel; 79 public int lockMode; 80 81 public String stopPositionString; 83 public boolean coarserLock; 84 public boolean returnedRow; 85 86 116 public LastIndexKeyResultSet 117 ( 118 Activation activation, 119 int resultSetNumber, 120 GeneratedMethod resultRowAllocator, 121 long conglomId, 122 String tableName, 123 String userSuppliedOptimizerOverrides, 124 String indexName, 125 int colRefItem, 126 int lockMode, 127 boolean tableLocked, 128 int isolationLevel, 129 double optimizerEstimatedRowCount, 130 double optimizerEstimatedCost 131 ) throws StandardException 132 { 133 super(activation, 134 resultSetNumber, 135 optimizerEstimatedRowCount, 136 optimizerEstimatedCost); 137 138 this.conglomId = conglomId; 139 140 if (SanityManager.DEBUG) 141 { 142 SanityManager.ASSERT( activation!=null, "this scan must get activation context"); 143 SanityManager.ASSERT( resultRowAllocator!= null, "this scan must get row allocator"); 144 } 145 146 this.resultRowAllocator = resultRowAllocator; 147 this.tableName = tableName; 148 this.userSuppliedOptimizerOverrides = userSuppliedOptimizerOverrides; 149 this.indexName = indexName; 150 this.lockMode = lockMode; 151 if (colRefItem != -1) 152 { 153 this.accessedCols = (FormatableBitSet)(activation.getPreparedStatement(). 154 getSavedObject(colRefItem)); 155 } 156 157 if (isolationLevel == ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL) 159 { 160 isolationLevel = lcc.getCurrentIsolationLevel(); 161 } 162 163 if (isolationLevel == ExecutionContext.SERIALIZABLE_ISOLATION_LEVEL) 164 { 165 this.isolationLevel = TransactionController.ISOLATION_SERIALIZABLE; 166 } 167 else 168 { 169 177 178 if (! tableLocked) 179 { 180 this.lockMode = TransactionController.MODE_RECORD; 181 } 182 183 if (isolationLevel == 184 ExecutionContext.READ_COMMITTED_ISOLATION_LEVEL) 185 { 186 this.isolationLevel = 187 TransactionController.ISOLATION_READ_COMMITTED_NOHOLDLOCK; 188 } 189 else if (isolationLevel == 190 ExecutionContext.READ_UNCOMMITTED_ISOLATION_LEVEL) 191 { 192 this.isolationLevel = 193 TransactionController.ISOLATION_READ_UNCOMMITTED; 194 } 195 else if (isolationLevel == 196 ExecutionContext.REPEATABLE_READ_ISOLATION_LEVEL) 197 { 198 this.isolationLevel = 199 TransactionController.ISOLATION_REPEATABLE_READ; 200 } 201 } 202 203 if (SanityManager.DEBUG) 204 { 205 SanityManager.ASSERT( 206 ((isolationLevel == 207 ExecutionContext.READ_COMMITTED_ISOLATION_LEVEL) || 208 (isolationLevel == 209 ExecutionContext.READ_UNCOMMITTED_ISOLATION_LEVEL) || 210 (isolationLevel == 211 ExecutionContext.REPEATABLE_READ_ISOLATION_LEVEL) || 212 (isolationLevel == 213 ExecutionContext.SERIALIZABLE_ISOLATION_LEVEL)), 214 215 "Invalid isolation level - " + isolationLevel); 216 } 217 218 runTimeStatisticsOn = getLanguageConnectionContext().getRunTimeStatisticsMode(); 219 220 221 candidate = (ExecRow) resultRowAllocator.invoke(activation); 222 constructorTime += getElapsedMillis(beginTime); 223 224 228 if (SanityManager.DEBUG) 229 { 230 if (SanityManager.DEBUG_ON("ScanTrace")) 231 { 232 } 234 } 235 236 activation.informOfRowCount(this, 1); 237 } 238 239 245 252 public void openCore() throws StandardException 253 { 254 ExecRow candidateCopy = candidate.getClone(); 255 256 beginTime = getCurrentTimeMillis(); 257 if (SanityManager.DEBUG) 258 { 259 SanityManager.ASSERT(!isOpen, "LastIndexKeyResultSet already open"); 260 } 261 262 isOpen = true; 263 TransactionController tc = activation.getTransactionController(); 264 265 271 if (tc.fetchMaxOnBtree( 272 conglomId, 0, lockMode, 275 isolationLevel, 276 accessedCols, 277 candidateCopy.getRowArray())) 278 { 279 currentRow = 280 getCompactRow(candidateCopy, accessedCols, (FormatableBitSet) null, true); 281 setCurrentRow(currentRow); 282 } 283 else 284 { 285 clearCurrentRow(); 286 } 287 288 numOpens++; 289 openTime += getElapsedMillis(beginTime); 290 } 291 292 297 public ExecRow getNextRowCore() throws StandardException 298 { 299 if (returnedRow || !isOpen) 300 { 301 clearCurrentRow(); 302 } 303 else 304 { 305 returnedRow = true; 306 } 307 return currentRow; 308 } 309 310 315 public void close() throws StandardException 316 { 317 beginTime = getCurrentTimeMillis(); 318 if (isOpen) 319 { 320 isOpen = false; 321 clearCurrentRow(); 322 323 super.close(); 324 } 325 else 326 { 327 if (SanityManager.DEBUG) 328 { 329 SanityManager.DEBUG("CloseRepeatInfo","Close of LastIndexKeyResultSet repeated"); 330 } 331 } 332 333 closeTime += getElapsedMillis(beginTime); 334 } 335 336 344 public long getTimeSpent(int type) 345 { 346 long totTime = constructorTime + openTime + nextTime + closeTime; 347 348 349 if (type == NoPutResultSet.CURRENT_RESULTSET_ONLY) 350 { 351 return totTime; 352 } 353 else 354 { 355 return totTime; 356 } 357 } 358 359 360 369 public ExecRow getCurrentRow() throws StandardException 370 { 371 return currentRow; 372 } 373 374 378 400 401 } 402 | Popular Tags |