1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.store.raw.ContainerHandle; 25 import org.apache.derby.iapi.store.raw.ContainerLock; 26 import org.apache.derby.iapi.store.raw.Page; 27 import org.apache.derby.iapi.store.raw.LockingPolicy; 28 import org.apache.derby.iapi.store.raw.RecordHandle; 29 import org.apache.derby.iapi.store.raw.ContainerKey; 30 31 import org.apache.derby.iapi.store.raw.data.RawContainerHandle; 32 import org.apache.derby.iapi.store.raw.log.LogInstant; 33 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 34 35 import org.apache.derby.iapi.services.locks.Lockable; 36 37 import org.apache.derby.catalog.UUID; 38 39 import org.apache.derby.iapi.error.StandardException; 40 41 import org.apache.derby.iapi.services.sanity.SanityManager; 42 43 import java.util.Observable ; 44 45 48 49 public class TruncateOnCommit extends ContainerHandleActionOnCommit { 50 51 54 private boolean commitAsWell; 55 56 public TruncateOnCommit(ContainerKey identity, boolean commitAsWell) { 57 58 super(identity); 59 this.commitAsWell = commitAsWell; 60 61 if (SanityManager.DEBUG) { 62 if (identity.getSegmentId() != ContainerHandle.TEMPORARY_SEGMENT) 63 SanityManager.THROWASSERT("segment id is not temp segment " + identity.getSegmentId()); 64 } 65 } 66 67 public void update(Observable obj, Object arg) { 68 if (SanityManager.DEBUG) { 69 if (arg == null) 70 SanityManager.THROWASSERT("still on observer list " + this); 71 } 72 73 if (arg.equals(RawTransaction.ABORT) || 74 arg.equals(RawTransaction.SAVEPOINT_ROLLBACK) || 75 (commitAsWell && arg.equals(RawTransaction.COMMIT))) { 76 openContainerAndDoIt((RawTransaction) obj); 77 } 78 79 if (arg.equals(RawTransaction.COMMIT) || arg.equals(RawTransaction.ABORT) 81 || arg.equals(identity)) { 82 obj.deleteObserver(this); 83 } 84 } 85 86 89 protected void doIt(BaseContainerHandle handle) 90 throws StandardException { 91 92 handle.container.truncate(handle); 93 } 94 95 public boolean equals(Object other) { 96 97 if (other instanceof TruncateOnCommit) { 98 99 if (((TruncateOnCommit) other).commitAsWell 100 != commitAsWell) 101 return false; 102 103 return super.equals(other); 104 } 105 else 106 return false; 107 } 108 } 109 | Popular Tags |