1 21 22 package org.apache.derby.impl.store.raw.data; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.impl.store.raw.data.BasePage; 27 28 import org.apache.derby.iapi.services.io.FormatIdUtil; 29 import org.apache.derby.iapi.services.io.StoredFormatIds; 30 31 import org.apache.derby.iapi.store.raw.Page; 32 import org.apache.derby.iapi.store.raw.Transaction; 33 34 import org.apache.derby.iapi.store.raw.log.LogInstant; 35 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 36 37 import org.apache.derby.iapi.services.sanity.SanityManager; 38 import org.apache.derby.iapi.error.StandardException; 39 40 import org.apache.derby.iapi.services.io.CompressedNumber; 41 import org.apache.derby.iapi.util.ByteArray; 42 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream; 43 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream; 44 45 import java.io.OutputStream ; 46 import java.io.ObjectOutput ; 47 import java.io.ObjectInput ; 48 import java.io.IOException ; 49 import org.apache.derby.iapi.services.io.LimitObjectInput; 50 51 55 public class SetReservedSpaceOperation extends PageBasicOperation { 56 57 protected int doMeSlot; protected int recordId; protected int newValue; protected int oldValue; 62 public SetReservedSpaceOperation(BasePage page, int slot, 63 int recordId, int newValue, int oldValue) 64 { 65 super(page); 66 doMeSlot = slot; 67 this.recordId = recordId; 68 this.newValue = newValue; 69 this.oldValue = oldValue; 70 71 if (SanityManager.DEBUG) SanityManager.ASSERT(oldValue > newValue); 73 } 74 75 78 public SetReservedSpaceOperation() { super(); } 80 81 84 public int getTypeFormatId() { 85 return StoredFormatIds.LOGOP_SET_RESERVED_SPACE; 86 } 87 88 public void writeExternal(ObjectOutput out) throws IOException 89 { 90 super.writeExternal(out); 91 92 CompressedNumber.writeInt(out, doMeSlot); 93 CompressedNumber.writeInt(out, recordId); 94 CompressedNumber.writeInt(out, newValue); 95 CompressedNumber.writeInt(out, oldValue); 96 } 97 98 103 public void readExternal(ObjectInput in) 104 throws IOException , ClassNotFoundException 105 { 106 super.readExternal(in); 107 doMeSlot = CompressedNumber.readInt(in); 108 recordId = CompressedNumber.readInt(in); 109 newValue = CompressedNumber.readInt(in); 110 oldValue = CompressedNumber.readInt(in); 111 } 112 113 116 122 public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) 123 throws StandardException, IOException 124 { 125 if (SanityManager.DEBUG) 126 { 127 SanityManager.ASSERT(oldValue == 128 this.page.getReservedCount(doMeSlot)); 129 SanityManager.ASSERT(newValue < oldValue, 130 "cannot set reserved space to be bigger than before"); 131 } 132 133 page.setReservedSpace(instant, doMeSlot, newValue); 134 } 135 136 141 142 149 150 public void restoreMe(Transaction xact, BasePage undoPage, LogInstant CLRinstant, LimitObjectInput in) 151 throws StandardException, IOException 152 { 153 int slot = undoPage.findRecordById(recordId,Page.FIRST_SLOT_NUMBER); 154 if (SanityManager.DEBUG) 155 { 156 if ( ! getPageId().equals(undoPage.getPageId())) 157 SanityManager.THROWASSERT( 158 "restoreMe cannot restore to a different page. " 159 + "doMe page:" + getPageId() + " undoPage:" + 160 undoPage.getPageId()); 161 if (slot != doMeSlot) 162 SanityManager.THROWASSERT( 163 "restoreMe cannot restore to a different slot. " 164 + "doMe slot:" + doMeSlot + " undoMe slot: " + 165 slot + " recordId:" + recordId); 166 167 } 168 169 page.setReservedSpace(CLRinstant, slot, oldValue); 170 171 } 172 173 176 public String toString() 177 { 178 if (SanityManager.DEBUG) 179 { 180 return super.toString() + 181 "Set Reserved space of recordId " + recordId + " from " + oldValue + " to " + newValue; 182 } 183 return null; 184 } 185 } 186 | Popular Tags |