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 / EncryptContainerUndoOperation.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/EncryptContainerUndoOperation.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/store/raw/data/EncryptContainerUndoOperation.java
new file mode 100644 (file)
index 0000000..48f382d
--- /dev/null
@@ -0,0 +1,182 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.data.EncryptContainerUndoOperation\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.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.store.raw.Compensation;\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
+import org.apache.derby.iapi.util.ByteArray;\r
+import org.apache.derby.iapi.store.raw.log.LogInstant;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\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 Encrypt Container undo operation rolls back the change of a \r
+ *  Encrypt Container operation \r
+ */\r
+public class EncryptContainerUndoOperation implements Compensation \r
+{\r
+       // the operation to rollback \r
+       transient private       EncryptContainerOperation undoOp;\r
+\r
+       /** During redo, the whole operation will be reconstituted from the log */\r
+\r
+       /** \r
+     * Set up a Encrypt Container undo operation during run time rollback\r
+     *  @param op Encrypt contaner operatation that is to be undone. \r
+     */\r
+       public EncryptContainerUndoOperation(EncryptContainerOperation op) \r
+       {\r
+               undoOp = op;\r
+       }\r
+\r
+       /*\r
+        * Formatable methods\r
+        */\r
+\r
+       // no-arg constructor, required by Formatable \r
+       public EncryptContainerUndoOperation() { super(); }\r
+\r
+       public void writeExternal(ObjectOutput out) throws IOException \r
+       {\r
+        // nothing to write.\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
+        // nothing to read.\r
+       }\r
+\r
+       /**\r
+               Return my format identifier.\r
+       */\r
+       public int getTypeFormatId() {\r
+               return StoredFormatIds.LOGOP_ENCRYPT_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 EncryptContainerOperation);\r
+               }\r
+\r
+               undoOp = (EncryptContainerOperation)op;\r
+       }\r
+\r
+       /**\r
+               Loggable methods\r
+       */\r
+\r
+    \r
+    /**\r
+     * Check if this operation needs to be redone during recovery redo. \r
+     * Returns true if this op should be redone during recovery redo,\r
+     * @param xact     the transaction that is doing the rollback\r
+     * @return  true, if this operation needs to be redone during recovery.\r
+     * @exception StandardException Standard Derby error policy\r
+     */\r
+    public boolean needsRedo(Transaction xact)\r
+        throws StandardException\r
+    {\r
+        return true;\r
+    }\r
+\r
+    /**\r
+       the default for prepared log is always null for all the operations\r
+       that don't have optionalData.  If an operation has optional data,\r
+       the operation need to prepare the optional data for this method.\r
+\r
+       Encrypt Conatainer Undo Operation has no optional data to write out\r
+       */\r
+    public ByteArray getPreparedLog()\r
+    {\r
+        return (ByteArray) null;\r
+    }\r
+\r
+\r
+    /** Apply the undo operation, in this implementation of the\r
+        RawStore, it can only call the undoMe method of undoOp\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
+        @exception IOException Can be thrown by any of the methods of ObjectInput.\r
+        @exception StandardException Standard Derby policy.\r
+\r
+        @see EncryptContainerOperation#generateUndo\r
+    */\r
+    public final void doMe(Transaction xact, LogInstant instant, \r
+                           LimitObjectInput in) \r
+        throws StandardException, IOException\r
+       {\r
+        undoOp.undoMe(xact);\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
+    }\r
+\r
+    /* Undo operation is a COMPENSATION log operation */\r
+    public int group()\r
+    {\r
+        return Loggable.COMPENSATION | Loggable.RAWSTORE;\r
+    }\r
+\r
+    /**\r
+         DEBUG: Print self.\r
+       */\r
+    public String toString()\r
+    {\r
+        if (SanityManager.DEBUG)\r
+        {\r
+            String str = "CLR (Encrypt Container Undo): " ;\r
+            if (undoOp != null)\r
+                str += undoOp.toString();\r
+            else\r
+                str += "undo Operation not set";\r
+\r
+            return str;\r
+        }\r
+        else\r
+            return null;\r
+    }\r
+}\r