1 21 22 package org.apache.derby.impl.store.access.heap; 23 24 25 30 31 import org.apache.derby.iapi.reference.SQLState; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 35 import org.apache.derby.iapi.services.io.Storable; 36 37 import org.apache.derby.iapi.error.StandardException; 38 39 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate; 40 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo; 41 import org.apache.derby.iapi.store.access.conglomerate.ScanManager; 42 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager; 43 44 import org.apache.derby.iapi.store.access.ConglomerateController; 45 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo; 46 import org.apache.derby.iapi.store.access.Qualifier; 47 import org.apache.derby.iapi.store.access.RowUtil; 48 import org.apache.derby.iapi.store.access.ScanInfo; 49 import org.apache.derby.iapi.store.access.ScanController; 50 51 import org.apache.derby.iapi.types.RowLocation; 52 53 import org.apache.derby.iapi.store.raw.ContainerHandle; 54 import org.apache.derby.iapi.store.raw.LockingPolicy; 55 import org.apache.derby.iapi.store.raw.Transaction; 56 import org.apache.derby.iapi.store.raw.Page; 57 import org.apache.derby.iapi.store.raw.RecordHandle; 58 59 import org.apache.derby.iapi.types.DataValueDescriptor; 60 61 import org.apache.derby.impl.store.access.conglomerate.ConglomerateUtil; 62 import org.apache.derby.impl.store.access.conglomerate.GenericScanController; 63 import org.apache.derby.impl.store.access.conglomerate.RowPosition; 64 65 import org.apache.derby.iapi.store.access.BackingStoreHashtable; 66 import org.apache.derby.iapi.services.io.FormatableBitSet; 67 68 import java.util.Hashtable ; 69 import java.util.Vector ; 70 71 class HeapScan 72 extends GenericScanController implements ScanManager 73 { 74 75 79 80 84 85 89 private DataValueDescriptor[][] fetchNext_one_slot_array = 90 new DataValueDescriptor[1][]; 91 92 93 97 98 102 103 public HeapScan() 104 { 105 } 106 107 112 protected void queueDeletePostCommitWork( 113 RowPosition pos) 114 throws StandardException 115 { 116 TransactionManager xact_mgr = open_conglom.getXactMgr(); 117 118 xact_mgr.addPostCommitWork( 119 new HeapPostCommit( 120 xact_mgr.getAccessManager(), 121 (Heap) open_conglom.getConglomerate(), 122 pos.current_page.getPageNumber())); 123 } 124 125 129 protected void setRowLocationArray( 130 RowLocation[] rowloc_array, 131 int index, 132 RowPosition pos) 133 throws StandardException 134 { 135 if (rowloc_array[index] == null) 136 { 137 rowloc_array[index] = new HeapRowLocation(pos.current_rh); 138 } 139 else 140 { 141 if (SanityManager.DEBUG) 142 { 143 SanityManager.ASSERT( 144 rowloc_array[index] instanceof HeapRowLocation); 145 } 146 147 ((HeapRowLocation)rowloc_array[index]).setFrom(pos.current_rh); 148 } 149 } 150 151 protected void setRowLocationArray( 152 RowLocation[] rowloc_array, 153 int index, 154 RecordHandle rh) 155 throws StandardException 156 { 157 if (rowloc_array[index] == null) 158 { 159 rowloc_array[index] = new HeapRowLocation(rh); 160 } 161 else 162 { 163 if (SanityManager.DEBUG) 164 { 165 SanityManager.ASSERT( 166 rowloc_array[index] instanceof HeapRowLocation); 167 } 168 169 ((HeapRowLocation)rowloc_array[index]).setFrom(rh); 170 } 171 } 172 173 186 private boolean reopenScanByRecordHandleAndSetLocks (RecordHandle rh) 187 throws StandardException 188 { 189 if (rh == null) 190 { 191 return (false); 192 } 193 194 if (scan_position.current_rh != null) 196 { 197 open_conglom.unlockPositionAfterRead(scan_position); 198 } 199 200 scan_position.current_rh = rh; 202 scan_position.current_rh_qualified = false; 203 204 final boolean rowLocationDisappeared = 206 open_conglom.latchPageAndRepositionScan(scan_position); 207 208 if (!rowLocationDisappeared) 209 { 210 setScanState(SCAN_INPROGRESS); 211 open_conglom.lockPositionForRead 212 (scan_position, null, true, true); 213 } 214 215 scan_position.unlatch(); 217 218 return (!rowLocationDisappeared); 219 } 220 221 247 public boolean fetchNext(DataValueDescriptor[] fetch_row) 248 throws StandardException 249 { 250 if (fetch_row == null) 252 fetchNext_one_slot_array[0] = RowUtil.EMPTY_ROW; 253 else 254 fetchNext_one_slot_array[0] = fetch_row; 255 256 boolean ret_val = 257 fetchRows( 258 fetchNext_one_slot_array, 259 (RowLocation[]) null, 260 (BackingStoreHashtable) null, 261 1, 262 (int[]) null) == 1; 263 264 return(ret_val); 265 } 266 267 268 271 public boolean next() 272 throws StandardException 273 { 274 fetchNext_one_slot_array[0] = open_conglom.getRuntimeMem().get_scratch_row(); 280 281 boolean ret_val = 282 fetchRows( 283 fetchNext_one_slot_array, 284 (RowLocation[]) null, 285 (BackingStoreHashtable) null, 286 1, 287 (int[]) null) == 1; 288 289 return(ret_val); 290 } 291 292 295 public boolean positionAtRowLocation(RowLocation rl) throws StandardException { 296 if (open_conglom.isClosed() && !rowLocationsInvalidated) 297 { 298 reopenAfterEndTransaction(); 299 } 300 301 if (rowLocationsInvalidated) 302 { 303 return(false); 304 305 } else { 306 return(reopenScanByRecordHandleAndSetLocks 307 (((HeapRowLocation)rl). 308 getRecordHandle(open_conglom.getContainer()))); 309 } 310 } 311 312 316 317 320 public void fetchLocation(RowLocation templateLocation) 321 throws StandardException 322 { 323 if (open_conglom.getContainer() == null || 324 scan_position.current_rh == null) 325 { 326 throw StandardException.newException( 327 SQLState.HEAP_SCAN_NOT_POSITIONED); 328 } 329 HeapRowLocation hrl = (HeapRowLocation) templateLocation; 330 hrl.setFrom(scan_position.current_rh); 331 } 332 333 public int fetchNextGroup( 334 DataValueDescriptor[][] row_array, 335 RowLocation[] rowloc_array) 336 throws StandardException 337 { 338 return( 339 fetchRows( 340 row_array, 341 rowloc_array, 342 (BackingStoreHashtable) null, 343 row_array.length, 344 (int[]) null)); 345 } 346 347 public int fetchNextGroup( 348 DataValueDescriptor[][] row_array, 349 RowLocation[] old_rowloc_array, 350 RowLocation[] new_rowloc_array) 351 throws StandardException 352 { 353 throw(StandardException.newException( 354 SQLState.HEAP_UNIMPLEMENTED_FEATURE)); 355 } 356 357 358 371 public ScanInfo getScanInfo() 372 throws StandardException 373 { 374 return(new HeapScanInfo(this)); 375 } 376 377 407 public void reopenScanByRowLocation( 408 RowLocation startRowLocation, 409 Qualifier qualifier[][]) 410 throws StandardException 411 { 412 reopenScanByRecordHandle( 413 ((HeapRowLocation) startRowLocation).getRecordHandle( 414 open_conglom.getContainer()), 415 qualifier); 416 } 417 418 419 422 423 436 public void savePosition(Conglomerate conglom, Page page) 437 throws StandardException 438 { 439 443 return; 445 } 446 } 447 | Popular Tags |