1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.impl.store.raw.data.BasePage; 25 26 import org.apache.derby.iapi.services.io.FormatIdUtil; 27 import org.apache.derby.iapi.services.io.StoredFormatIds; 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 30 import org.apache.derby.iapi.store.raw.Compensation; 31 import org.apache.derby.iapi.store.raw.Loggable; 32 import org.apache.derby.iapi.store.raw.Transaction; 33 import org.apache.derby.iapi.store.raw.Undoable; 34 35 import org.apache.derby.iapi.store.raw.log.LogInstant; 36 37 import org.apache.derby.iapi.error.StandardException; 38 39 import org.apache.derby.iapi.services.io.CompressedNumber; 40 import org.apache.derby.iapi.util.ByteArray; 41 42 import java.io.OutputStream ; 43 import java.io.ObjectOutput ; 44 import java.io.ObjectInput ; 45 import java.io.IOException ; 46 47 import org.apache.derby.iapi.services.io.LimitObjectInput; 48 49 70 public class LogicalUndoOperation extends PageBasicOperation implements Compensation { 71 72 protected int recordId; 74 75 transient private LogicalPageOperation undoOp = null; 76 77 protected LogicalUndoOperation(BasePage page) 78 { 79 super(page); 80 } 81 82 83 public LogicalUndoOperation(BasePage page, int recordId, LogicalPageOperation op) 84 { 85 super(page); 86 undoOp = op; 87 this.recordId = recordId; 88 } 89 90 93 94 public LogicalUndoOperation() { super(); } 96 97 public int getTypeFormatId() { 98 return StoredFormatIds.LOGOP_PAGE_LOGICAL_UNDO; 99 } 100 101 105 public void writeExternal(ObjectOutput out) throws IOException 106 { 107 super.writeExternal(out); 108 CompressedNumber.writeInt(out, recordId); 109 } 110 111 112 117 public void readExternal(ObjectInput in) 118 throws IOException , ClassNotFoundException 119 { 120 super.readExternal(in); 121 recordId = CompressedNumber.readInt(in); 122 } 123 124 public void restoreMe(Transaction xact, BasePage undoPage, 125 LogInstant CLRinstant, LimitObjectInput in) 126 { 127 if (SanityManager.DEBUG) 129 SanityManager.THROWASSERT("cannot call restore me on PhysicalUndoOperation"); 130 } 131 132 135 136 137 public void setUndoOp(Undoable op) 138 { 139 if (SanityManager.DEBUG) { 140 SanityManager.ASSERT(op instanceof LogicalPageOperation); 141 } 142 143 undoOp = (LogicalPageOperation)op; 144 } 145 146 147 150 151 162 public final void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) 163 throws StandardException, IOException 164 { 165 166 long oldversion = 0; LogInstant oldLogInstant = null; if (SanityManager.DEBUG) 169 { 170 oldLogInstant = this.page.getLastLogInstant(); 171 oldversion = this.page.getPageVersion(); 172 173 SanityManager.ASSERT(oldversion == this.getPageVersion()); 174 SanityManager.ASSERT(oldLogInstant == null || instant == null 175 || oldLogInstant.lessThan(instant)); 176 } 177 178 undoOp.undoMe(xact, this.page, recordId, instant, in); 192 193 if (SanityManager.DEBUG) { 194 SanityManager.ASSERT(oldversion < this.page.getPageVersion()); 195 SanityManager.ASSERT(instant == null || instant.equals(this.page.getLastLogInstant())); 196 } 197 198 releaseResource(xact); 199 } 200 201 202 public void releaseResource(Transaction xact) 203 { 204 if (undoOp != null) 205 undoOp.releaseResource(xact); 206 super.releaseResource(xact); 207 } 208 209 210 public int group() 211 { 212 return super.group() | Loggable.COMPENSATION | Loggable.RAWSTORE; 213 } 214 215 public final ByteArray getPreparedLog() { 216 return (ByteArray) null; 222 } 223 224 227 public String toString() 228 { 229 if (SanityManager.DEBUG) 230 { 231 String str = "CLR : (logical undo) " + super.toString() + 232 " undoRecordId = " + recordId; 233 if (undoOp != null) 234 str += "\n" + undoOp.toString(); 235 else 236 str += " undo Operation not set"; 237 return str; 238 } 239 else 240 return null; 241 } 242 243 } 244 | Popular Tags |