Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / store / raw / Undoable.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/store/raw/Undoable.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/store/raw/Undoable.java
new file mode 100644 (file)
index 0000000..9f291af
--- /dev/null
@@ -0,0 +1,107 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.store.raw.Undoable\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.iapi.store.raw;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.io.LimitObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+       An Undoable operation is an operation that changed the state of the RawStore\r
+       in the context of a transaction and this change can be rolled back.\r
+\r
+       @see Transaction#logAndDo\r
+       @see Compensation\r
+*/\r
+\r
+public interface Undoable extends Loggable {\r
+\r
+\r
+       /**\r
+               Generate a loggable which will undo this change, using the optional\r
+               input if necessary.\r
+\r
+               <P><B>NOTE</B><BR>Any logical undo logic must be hidden behind generateUndo.\r
+               During recovery redo, it should not depend on any logical undo logic.\r
+\r
+               <P>\r
+               There are 3 ways to implement a redo-only log record:\r
+               <NL>\r
+               <LI>Make the log record a Loggable instead of an Undoable, this is the\r
+               cleanest method.\r
+               <LI>If you want to extend a log operation class that is an Undoable,\r
+               you can then either have generateUndo return null - this is preferred -\r
+               (the log operation's undoMe should never be called, so you can put a\r
+               null body there if the super class you are extending does not implement\r
+               a undoMe).\r
+               <LI>Or, have undoMe do nothing - this is least preferred.\r
+               </NL>\r
+\r
+               <P>Any resource (e.g., latched page) that is needed for the\r
+               undoable.undoMe() must be acquired in undoable.generateUndo().\r
+               Moreover, that resource must be identified in the compensation\r
+               operation, and reacquired in the compensation.needsRedo() method during\r
+               recovery redo.\r
+               <BR><B>If you do write your own generateUndo or needsRedo, any\r
+               resource you latch or acquire, you must release them in\r
+               Compensation.doMe() or in Compensation.releaseResource().</B>\r
+\r
+               <P> To write a generateUndo operation, find the object that needs to be\r
+               rolled back.  Assuming that it is a page, latch it, put together a\r
+               Compensation operation with the undoOp set to this operation, and save\r
+               the page number in the compensation operation, then\r
+               return the Compensation operation to the logging system.\r
+\r
+               <P>\r
+               The sequence of events in a rollback of a undoable operation is\r
+               <NL>\r
+               <LI> The logging system calls undoable.generateUndo.  If this returns\r
+               null, then there is nothing to undo.\r
+               <LI> If generateUndo returns a Compensation operation, then the logging\r
+               system will log the Compensation log record and call\r
+               Compenstation.doMe().  (Hopefully, this just calls the undoable's\r
+               undoMe)\r
+               <LI> After the Compensation operation has been applied, the logging\r
+               system will call compensation.releaseResource(). If you do overwrite a\r
+               super class's releaseResource(), it would be prudent to call\r
+               super.releaseResource() first.\r
+               </NL>\r
+\r
+               <P> The available() method of in indicates how much data can be read, i.e.\r
+               how much was originally written.\r
+\r
+               @param xact     the transaction doing the rollback\r
+               @return the compensation operation that will rollback this change, or\r
+               null if nothing to undo. \r
+\r
+               @exception IOException Can be thrown by any of the methods of ObjectInput.\r
+               @exception StandardException Standard Derby policy.\r
+\r
+               @see Loggable#releaseResource\r
+               @see Loggable#needsRedo\r
+\r
+       */\r
+       public Compensation generateUndo(Transaction xact, LimitObjectInput in)\r
+                throws StandardException, IOException;\r
+\r
+}\r