Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / store / raw / data / SetReservedSpaceOperation.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/SetReservedSpaceOperation.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/SetReservedSpaceOperation.java
new file mode 100644 (file)
index 0000000..207515f
--- /dev/null
@@ -0,0 +1,185 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.SetReservedSpaceOperation\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.store.raw.data;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.impl.store.raw.data.BasePage;\r
+\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.store.raw.Page;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction; \r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.io.CompressedNumber;\r
+import org.apache.derby.iapi.util.ByteArray;\r
+import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;\r
+import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;\r
+\r
+import java.io.OutputStream;\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+import org.apache.derby.iapi.services.io.LimitObjectInput;\r
+\r
+/**\r
+       Represents shrinking of the reserved space of a particular row on a page.\r
+       This operation is not undoable.\r
+*/\r
+public class SetReservedSpaceOperation extends PageBasicOperation {\r
+\r
+       protected int   doMeSlot;       // slot where record is at\r
+       protected int   recordId;       // recordId\r
+       protected int   newValue;       // the new reserved space value\r
+       protected int   oldValue;       // the old reserved space value (for BI_logging)\r
+\r
+       public SetReservedSpaceOperation(BasePage page, int slot, \r
+                                                                        int recordId, int newValue, int oldValue)\r
+       {\r
+               super(page);\r
+               doMeSlot = slot;\r
+               this.recordId = recordId;\r
+               this.newValue = newValue;\r
+               this.oldValue = oldValue;\r
+\r
+               if (SanityManager.DEBUG) // we only use this for shrinking\r
+                       SanityManager.ASSERT(oldValue > newValue);\r
+       }\r
+\r
+       /*\r
+        * Formatable methods\r
+        */\r
+       // no-arg constructor, required by Formatable \r
+       public SetReservedSpaceOperation() { super(); }\r
+\r
+       /**\r
+               Return my format identifier.\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.LOGOP_SET_RESERVED_SPACE;\r
+       }\r
+\r
+       public void writeExternal(ObjectOutput out) throws IOException \r
+       {\r
+               super.writeExternal(out);\r
+\r
+               CompressedNumber.writeInt(out, doMeSlot);\r
+               CompressedNumber.writeInt(out, recordId);\r
+               CompressedNumber.writeInt(out, newValue);\r
+               CompressedNumber.writeInt(out, oldValue);\r
+       }\r
+\r
+       /**\r
+               Read this in\r
+               @exception IOException error reading from log stream\r
+               @exception ClassNotFoundException log stream corrupted\r
+       */\r
+       public void readExternal(ObjectInput in) \r
+                throws IOException, ClassNotFoundException\r
+       {\r
+               super.readExternal(in);\r
+               doMeSlot = CompressedNumber.readInt(in);\r
+               recordId = CompressedNumber.readInt(in);\r
+               newValue = CompressedNumber.readInt(in);\r
+               oldValue = CompressedNumber.readInt(in);\r
+       }\r
+\r
+       /*\r
+        * Loggable methods\r
+        */\r
+       /**\r
+               @exception IOException Can be thrown by any of the methods of ObjectInput.\r
+               @exception StandardException Standard Derby policy.             \r
+         \r
+               @see org.apache.derby.iapi.store.raw.Loggable#doMe\r
+       */\r
+       public void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)\r
+                throws StandardException, IOException \r
+       {\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       SanityManager.ASSERT(oldValue ==\r
+                                                                this.page.getReservedCount(doMeSlot));\r
+                       SanityManager.ASSERT(newValue < oldValue,\r
+                               "cannot set reserved space to be bigger than before"); \r
+               }\r
+\r
+               page.setReservedSpace(instant, doMeSlot, newValue);\r
+       }\r
+\r
+       /*\r
+        * method to support BeforeImageLogging - This log operation is not\r
+        * undoable in the logical sense , but all log operations that touch a page\r
+        * must support physical undo during RRR transaction.\r
+        */\r
+\r
+       /**\r
+        * restore the before image of the page\r
+        *\r
+        * @exception StandardException Standard Derby Error Policy\r
+        * @exception IOException problem reading the complete log record from the\r
+        * input stream\r
+        */\r
+\r
+       public void restoreMe(Transaction xact, BasePage undoPage, LogInstant CLRinstant, LimitObjectInput in)\r
+                throws StandardException, IOException\r
+       {\r
+               int slot = undoPage.findRecordById(recordId,Page.FIRST_SLOT_NUMBER);\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       if ( ! getPageId().equals(undoPage.getPageId()))\r
+                               SanityManager.THROWASSERT(\r
+                                                               "restoreMe cannot restore to a different page. "\r
+                                                                + "doMe page:" + getPageId() + " undoPage:" + \r
+                                                                undoPage.getPageId());\r
+                       if (slot != doMeSlot)\r
+                               SanityManager.THROWASSERT(\r
+                                                               "restoreMe cannot restore to a different slot. "\r
+                                                                + "doMe slot:" + doMeSlot + " undoMe slot: " +\r
+                                                                slot + " recordId:" + recordId);\r
+\r
+               }\r
+\r
+               page.setReservedSpace(CLRinstant, slot, oldValue);\r
+\r
+       }\r
+\r
+       /**\r
+         DEBUG: Print self.\r
+       */\r
+       public String toString()\r
+       {\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       return super.toString() +\r
+                               "Set Reserved space of recordId " + recordId + " from " + oldValue + " to " + newValue;\r
+               }\r
+               return null;\r
+       }\r
+}\r