1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.impl.store.raw.data.RecordId; 25 import org.apache.derby.impl.store.raw.data.BasePage; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo; 30 31 import org.apache.derby.iapi.store.raw.ContainerHandle; 32 import org.apache.derby.iapi.store.raw.Compensation; 33 import org.apache.derby.iapi.store.raw.LogicalUndoable; 34 import org.apache.derby.iapi.store.raw.LockingPolicy; 35 import org.apache.derby.iapi.store.raw.Page; 36 import org.apache.derby.iapi.store.raw.RecordHandle; 37 import org.apache.derby.iapi.store.raw.Transaction; 38 import org.apache.derby.iapi.store.raw.Undoable; 39 40 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 41 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 42 import org.apache.derby.iapi.store.raw.log.LogInstant; 43 44 import org.apache.derby.iapi.error.StandardException; 45 46 import org.apache.derby.iapi.types.DataValueDescriptor; 47 48 import org.apache.derby.iapi.services.io.CompressedNumber; 49 50 import java.io.ObjectOutput ; 51 import java.io.ObjectInput ; 52 import java.io.IOException ; 53 import org.apache.derby.iapi.services.io.LimitObjectInput; 54 55 74 public abstract class LogicalPageOperation 75 extends PageBasicOperation implements LogicalUndoable 76 { 77 78 protected LogicalUndo undo; 83 protected int recordId; 88 public LogicalPageOperation() { super(); } 90 91 protected LogicalPageOperation(BasePage page, LogicalUndo undo, int recordId) 92 { 93 super(page); 94 this.undo = undo; 95 this.recordId = recordId; 96 } 97 98 101 102 103 public void writeExternal(ObjectOutput out) throws IOException 104 { 105 super.writeExternal(out); 106 CompressedNumber.writeInt(out, recordId); 107 out.writeObject(undo); 108 } 109 110 115 public void readExternal(ObjectInput in) 116 throws IOException , ClassNotFoundException 117 { 118 super.readExternal(in); 119 recordId = CompressedNumber.readInt(in); 120 undo = (LogicalUndo)in.readObject(); 121 } 122 123 124 127 128 137 138 public Compensation generateUndo(Transaction xact, LimitObjectInput in) 139 throws StandardException, IOException 140 { 141 if (undo == null) 143 { 144 BasePage undoPage = findpage(xact); 145 146 undoPage.preDirty(); 151 152 return new LogicalUndoOperation(undoPage, recordId, this); 153 } 154 else 155 { 156 if (SanityManager.DEBUG) 157 { 158 RawTransaction rtran = (RawTransaction)xact; 161 rtran.checkLogicalOperationOk(); 162 } 163 164 BasePage logicalUndoPage = findLogicalPage(xact, undo, in); 165 166 logicalUndoPage.preDirty(); 171 172 return new LogicalUndoOperation(logicalUndoPage, recordId, this); 179 180 } 181 } 182 183 184 189 190 193 public ContainerHandle getContainer() 194 { 195 if (SanityManager.DEBUG) { 196 SanityManager.ASSERT(containerHdl != null, "accessing null container handle"); 197 } 198 199 return containerHdl; 200 } 201 202 206 public void resetRecordHandle(RecordHandle rh) 207 { 208 resetPageNumber(rh.getPageNumber()); 209 recordId = rh.getId(); 210 } 211 212 213 218 public RecordHandle getRecordHandle() 219 { 220 return new RecordId(getPageId(), recordId); 221 } 222 223 227 228 236 public void reclaimPrepareLocks( 237 Transaction t, 238 LockingPolicy locking_policy) 239 throws StandardException 240 { 241 if (SanityManager.DEBUG) 242 { 243 SanityManager.DEBUG_PRINT("", "reclaimPrepareLocks()."); 244 SanityManager.ASSERT(getRecordHandle() != null); 245 } 246 247 ContainerHandle ch = t.openContainer( 248 getPageId().getContainerId(), locking_policy, 249 (ContainerHandle.MODE_FORUPDATE | 250 ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY | 251 ContainerHandle.MODE_LOCK_NOWAIT)); 252 253 if (SanityManager.DEBUG) 254 { 255 SanityManager.ASSERT(ch != null); 256 } 257 258 if (ch != null) 259 ch.close(); 260 261 278 boolean lock_granted = 280 locking_policy.lockRecordForWrite( 281 t, 282 getRecordHandle(), 283 false, false); 288 releaseResource(t); 289 290 if (SanityManager.DEBUG) 291 { 292 SanityManager.ASSERT(lock_granted); 293 } 294 } 295 296 299 300 330 private BasePage findLogicalPage(Transaction xact, LogicalUndo undo, 331 LimitObjectInput in) 332 throws StandardException, IOException 333 { 334 releaseResource(xact); 335 336 if (SanityManager.DEBUG) { 337 SanityManager.ASSERT(containerHdl == null); 339 SanityManager.ASSERT(page == null); 340 } 341 342 boolean okExit = false; 343 344 try { 345 346 RawTransaction rtran = (RawTransaction)xact; 348 349 containerHdl = rtran.openDroppedContainer 350 (getPageId().getContainerId(), (LockingPolicy) null); 351 352 if (SanityManager.DEBUG) { 353 SanityManager.ASSERT(containerHdl != null, "cannot open container"); 354 SanityManager.ASSERT(containerHdl.getContainerStatus() != RawContainerHandle.COMMITTED_DROP, 355 "finding a page for undo in a committed dropped container"); 356 } 357 358 page = (BasePage)(undo.findUndo(xact, this, in)); 359 360 if (SanityManager.DEBUG) { 361 SanityManager.ASSERT(page != null, "findUndo returns null page"); 362 SanityManager.ASSERT(page.getPageNumber() == getPageId().getPageNumber(), 363 "undo.findUndo did not reset the log op's recordHandle"); 364 } 365 366 369 okExit = true; 370 } finally { 371 372 if (!okExit) { 373 374 if (containerHdl != null) { 375 containerHdl.close(); 376 containerHdl = null; 377 } 378 } 379 380 } 383 384 foundHere = true; 385 return page; 386 } 387 388 389 414 abstract public void undoMe(Transaction xact, BasePage undoPage, int undoRecordId, 415 LogInstant CLRinstant, LimitObjectInput in) 416 throws StandardException, IOException ; 417 418 419 } 420 | Popular Tags |