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.sanity.SanityManager; 27 import org.apache.derby.iapi.services.io.FormatIdUtil; 28 import org.apache.derby.iapi.services.io.StoredFormatIds; 29 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.store.raw.RecordHandle; 33 import org.apache.derby.iapi.store.raw.Page; 34 import org.apache.derby.iapi.store.raw.Transaction; 35 36 import org.apache.derby.iapi.store.raw.log.LogInstant; 37 38 import org.apache.derby.iapi.services.io.CompressedNumber; 39 40 import java.io.OutputStream ; 41 import java.io.ObjectOutput ; 42 import java.io.ObjectInput ; 43 import java.io.IOException ; 44 import org.apache.derby.iapi.services.io.LimitObjectInput; 45 46 66 public final class InitPageOperation extends PhysicalPageOperation 67 { 68 protected int nextRecordId; protected int initFlag; 70 protected int pageFormatId; 71 protected long pageOffset; 72 73 protected boolean reuse; protected boolean overflowPage; 76 public InitPageOperation(BasePage page, int flag, int formatid, 77 long offset) 78 throws StandardException 79 { 80 super(page); 81 82 initFlag = flag; 83 pageFormatId = formatid; 84 pageOffset = offset; 85 86 if ((initFlag & BasePage.INIT_PAGE_REUSE_RECORDID) == 0) 89 nextRecordId = page.newRecordId(); 90 else 91 nextRecordId = RecordHandle.FIRST_RECORD_ID; 92 } 93 94 97 98 public InitPageOperation() { super(); } 100 101 105 public void writeExternal(ObjectOutput out) throws IOException 106 { 107 super.writeExternal(out); 108 CompressedNumber.writeInt(out, nextRecordId); 109 CompressedNumber.writeInt(out, initFlag); 110 CompressedNumber.writeLong(out, pageOffset); 111 out.writeInt(pageFormatId); 112 } 113 114 119 public void readExternal(ObjectInput in) 120 throws IOException , ClassNotFoundException 121 { 122 super.readExternal(in); 123 nextRecordId = CompressedNumber.readInt(in); 124 initFlag = CompressedNumber.readInt(in); 125 pageOffset = CompressedNumber.readLong(in); 126 pageFormatId = in.readInt(); 127 } 128 129 132 public int getTypeFormatId() { 133 return StoredFormatIds.LOGOP_INIT_PAGE; 134 } 135 138 146 public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) 147 throws StandardException, IOException 148 { 149 boolean overflowPage = ((initFlag & BasePage.INIT_PAGE_OVERFLOW) != 0); 150 boolean reuse = ((initFlag & BasePage.INIT_PAGE_REUSE) != 0); 151 152 this.page.initPage(instant, 153 BasePage.VALID_PAGE, 154 nextRecordId, 155 overflowPage, reuse); 156 } 157 158 161 170 protected BasePage getPageForRedoRecovery(Transaction xact) 171 throws StandardException 172 { 173 BasePage p = super.getPageForRedoRecovery(xact); 174 if (p != null) 175 return p; 176 177 p = (BasePage)containerHdl.reCreatePageForRedoRecovery( 181 pageFormatId, 182 getPageId().getPageNumber(), 183 pageOffset); 184 return p; 185 } 186 187 188 191 192 200 public void undoMe(Transaction xact, BasePage undoPage, LogInstant CLRInstant, 201 LimitObjectInput in) 202 throws StandardException, IOException 203 { 204 undoPage.setPageStatus(CLRInstant, BasePage.INVALID_PAGE); 205 209 undoPage.setAuxObject(null); 210 } 211 212 213 216 217 224 public void restoreMe(Transaction xact, BasePage undoPage, 225 LogInstant CLRInstant, LimitObjectInput in) 226 throws StandardException, IOException 227 { 228 undoMe(xact, undoPage, CLRInstant, in); 229 } 230 231 public String toString() 232 { 233 if (SanityManager.DEBUG) 234 { 235 boolean overflowPage = ((initFlag & BasePage.INIT_PAGE_OVERFLOW) != 0); 236 boolean reuse = ((initFlag & BasePage.INIT_PAGE_REUSE) != 0); 237 238 return super.toString() + "Init Page. Overflow = " 239 + overflowPage + " reuse " + reuse + " nextRecordId " + nextRecordId; 240 } 241 else 242 return null; 243 } 244 245 } 246 | Popular Tags |