Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / store / raw / xact / XactContext.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/xact/XactContext.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/store/raw/xact/XactContext.java
new file mode 100644 (file)
index 0000000..31a2307
--- /dev/null
@@ -0,0 +1,167 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.store.raw.xact.XactContext\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.xact;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+// This is the recommended super-class for all contexts.\r
+import org.apache.derby.iapi.services.context.ContextImpl;\r
+import org.apache.derby.iapi.services.context.ContextManager;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.store.raw.RawStoreFactory;\r
+import org.apache.derby.iapi.store.raw.xact.RawTransaction;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+\r
+/**\r
+The context associated with the transaction.\r
+\r
+This object stores the context associated with the raw store transaction\r
+on the stack.  It stores info about the transaction opened within a \r
+context manager (ie. typically a single user) for a single RawStoreFactory.\r
+\r
+**/\r
+\r
+final class XactContext extends ContextImpl {\r
+\r
+       private         RawTransaction  xact;\r
+       private     RawStoreFactory factory;\r
+       private         boolean   abortAll; // true if any exception causes this transaction to be aborted.\r
+\r
+       XactContext(ContextManager cm, String name, Xact xact, boolean abortAll, RawStoreFactory factory) {\r
+               super(cm, name);\r
+\r
+               this.xact = xact;\r
+               this.abortAll = abortAll;\r
+               this.factory = factory;\r
+               xact.xc = this; // double link between transaction and myself\r
+       }\r
+\r
+\r
+       /*\r
+       ** Context methods (most are implemented by super-class)\r
+       */\r
+\r
+\r
+       /**\r
+               @exception StandardException Standard Derby error policy\r
+       */\r
+       public void cleanupOnError(Throwable error) throws StandardException {\r
+\r
+        if (SanityManager.DEBUG)\r
+        {\r
+               SanityManager.ASSERT(getContextManager() != null);\r
+       }\r
+\r
+               boolean throwAway = false;\r
+\r
+               if (error instanceof StandardException) {\r
+                       StandardException se = (StandardException) error;\r
+\r
+                       if (abortAll) {\r
+                               // any error aborts an internal/nested xact and its transaction\r
+\r
+                               if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY)\r
+                {\r
+                                       throw StandardException.newException(\r
+                        SQLState.XACT_INTERNAL_TRANSACTION_EXCEPTION, error);\r
+                }\r
+\r
+                               throwAway = true;\r
+\r
+\r
+                       } else {\r
+\r
+                               // If the severity is lower than a transaction error then do nothing.\r
+                               if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY)\r
+                {\r
+                                       return;\r
+                }\r
+                 \r
+\r
+                               // If the session is going to disappear then we want to close this\r
+                               // transaction, not just abort it.\r
+                               if (se.getSeverity() >= ExceptionSeverity.SESSION_SEVERITY)\r
+                                       throwAway = true;\r
+                       }\r
+               } else {\r
+                       // some java* error, throw away the transaction.\r
+                       throwAway = true;\r
+               }\r
+\r
+               try {\r
+\r
+                       if (xact != null) {\r
+                               // abort the transaction\r
+                               xact.abort();\r
+                       }\r
+\r
+               } catch (StandardException se) {\r
+                       // if we get an error during abort then shut the system down\r
+                       throwAway = true;\r
+\r
+                       // if the system was being shut down anyway, do nothing\r
+                       if ((se.getSeverity() <= ExceptionSeverity.SESSION_SEVERITY) &&\r
+                               (se.getSeverity() >= ((StandardException) error).getSeverity())) {\r
+\r
+                               throw factory.markCorrupt(\r
+                    StandardException.newException(\r
+                        SQLState.XACT_ABORT_EXCEPTION, se));\r
+                       }\r
+\r
+               } finally {\r
+\r
+                       if (throwAway) {\r
+                               // xact close will pop this context out of the context\r
+                               // stack \r
+                               xact.close();\r
+                               xact = null;\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       RawTransaction getTransaction() {\r
+               return xact;\r
+       }\r
+\r
+       RawStoreFactory getFactory() {\r
+               return factory;\r
+       }\r
+\r
+       void substituteTransaction(Xact newTran)\r
+       {\r
+               // disengage old tran from this xact context\r
+               Xact oldTran = (Xact)xact;\r
+               if (oldTran.xc == this)\r
+                       oldTran.xc = null;\r
+\r
+               // set up double link between new transaction and myself\r
+               xact = newTran;\r
+               ((Xact)xact).xc = this;\r
+       }\r
+\r
+}\r