Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / raw / data / ContainerUndoOperation.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/data/ContainerUndoOperation.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/data/ContainerUndoOperation.java
new file mode 100644 (file)
index 0000000..b044f90
--- /dev/null
@@ -0,0 +1,156 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.ContainerUndoOperation\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.services.sanity.SanityManager;\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.Compensation;\r
+import org.apache.derby.iapi.store.raw.ContainerHandle;\r
+import org.apache.derby.iapi.store.raw.Loggable;\r
+import org.apache.derby.iapi.store.raw.Transaction;\r
+import org.apache.derby.iapi.store.raw.Undoable;\r
+\r
+import org.apache.derby.iapi.store.raw.data.RawContainerHandle;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import java.io.InputStream;\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
+/** A Container undo operation rolls back the change of a Container operation */\r
+public class ContainerUndoOperation extends ContainerBasicOperation \r
+               implements Compensation \r
+{\r
+       // the operation to rollback \r
+       transient private       ContainerOperation undoOp;\r
+\r
+       /** During redo, the whole operation will be reconstituted from the log */\r
+\r
+       /** \r
+               Set up a Container undo operation during run time rollback\r
+               @exception StandardException container Handle is not active\r
+       */\r
+       public ContainerUndoOperation(RawContainerHandle hdl, ContainerOperation op) \r
+                throws StandardException\r
+       {\r
+               super(hdl);\r
+               undoOp = op;\r
+       }\r
+\r
+       /*\r
+        * Formatable methods\r
+        */\r
+\r
+       // no-arg constructor, required by Formatable \r
+       public ContainerUndoOperation() { super(); }\r
+\r
+       public void writeExternal(ObjectOutput out) throws IOException \r
+       {\r
+               super.writeExternal(out);\r
+       }\r
+\r
+       /**\r
+               @exception IOException cannot read log record from log stream\r
+               @exception ClassNotFoundException cannot read ByteArray object\r
+        */\r
+       public void readExternal(ObjectInput in) \r
+                throws IOException, ClassNotFoundException\r
+       {\r
+               super.readExternal(in);\r
+       }\r
+\r
+       /**\r
+               Return my format identifier.\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.LOGOP_CONTAINER_UNDO;\r
+       }\r
+\r
+       /** \r
+               Compensation method\r
+       */\r
+\r
+       /** Set up a Container undo operation during recovery redo. */\r
+       public void setUndoOp(Undoable op)\r
+       {\r
+               if (SanityManager.DEBUG) {\r
+                       SanityManager.ASSERT(op instanceof ContainerOperation);\r
+               }\r
+\r
+               undoOp = (ContainerOperation)op;\r
+       }\r
+\r
+       /**\r
+               Loggable methods\r
+       */\r
+\r
+       /** Apply the undo operation, in this implementation of the\r
+               RawStore, it can only call the undoMe method of undoOp\r
+\r
+               @param xact                     the Transaction that is doing the rollback\r
+               @param instant          the log instant of this compenstaion operation\r
+               @param in                       optional data\r
+\r
+               @exception IOException Can be thrown by any of the methods of ObjectInput.\r
+               @exception StandardException Standard Derby error policy.\r
+\r
+               @see ContainerOperation#generateUndo\r
+        */\r
+       public final void doMe(Transaction xact, LogInstant instant, LimitObjectInput in) \r
+                throws StandardException, IOException\r
+       {\r
+               if (SanityManager.DEBUG) {\r
+                       SanityManager.ASSERT(containerHdl != null, "clr has null containerHdl");\r
+               }\r
+\r
+               // if this is called during runtime rollback, generateUndo found\r
+               // the container and have it opened there.\r
+               // if this is called during recovery redo, this.needsRedo found \r
+               // the container and have it opened here.\r
+               //\r
+               // in either case, containerHdl is the opened container handle.\r
+\r
+               undoOp.undoMe(xact, containerHdl, instant, in);\r
+               releaseResource(xact);\r
+       }\r
+\r
+       /* make sure resource found in undoOp is released */\r
+       public void releaseResource(Transaction xact)\r
+       {\r
+               if (undoOp != null)\r
+                       undoOp.releaseResource(xact);\r
+               super.releaseResource(xact);\r
+       }\r
+\r
+       /* Undo operation is a COMPENSATION log operation */\r
+       public int group()\r
+       {\r
+               return super.group() | Loggable.COMPENSATION | Loggable.RAWSTORE;\r
+       }\r
+\r
+}\r