Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / jdbc / EmbedSavepoint30.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/EmbedSavepoint30.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/jdbc/EmbedSavepoint30.java
new file mode 100644 (file)
index 0000000..b4842a3
--- /dev/null
@@ -0,0 +1,125 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.jdbc.EmbedSavepoint30\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.jdbc;\r
+\r
+import org.apache.derby.impl.jdbc.EmbedConnection;\r
+import org.apache.derby.impl.jdbc.ConnectionChild;\r
+import org.apache.derby.impl.jdbc.Util;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import java.sql.Savepoint;\r
+import java.sql.SQLException;\r
+\r
+/**\r
+ * This class implements the Savepoint interface from JDBC3.0\r
+ * This allows to set, release, or rollback a transaction to\r
+ * designated Savepoints. Savepoints provide finer-grained\r
+ * control of transactions by marking intermediate points within\r
+ * a transaction. Once a savepoint has been set, the transaction\r
+ * can be rolled back to that savepoint without affecting preceding work.\r
+   <P><B>Supports</B>\r
+   <UL>\r
+   <LI> JSR169 - no subsetting for java.sql.Savepoint\r
+   <LI> JDBC 3.0 - class introduced in JDBC 3.0\r
+   </UL>\r
+ *\r
+ * @see java.sql.Savepoint\r
+ *\r
+ */\r
+final class EmbedSavepoint30 extends ConnectionChild\r
+    implements Savepoint {\r
+\r
+    //In order to avoid name conflict, the external names are prepanded\r
+    //with "e." and internal names always start with "i." This is for bug 4467\r
+    private final String savepointName;\r
+    private final int savepointID;\r
+\r
+       //////////////////////////////////////////////////////////////\r
+       //\r
+       // CONSTRUCTORS\r
+       //\r
+       //////////////////////////////////////////////////////////////\r
+       /*\r
+               Constructor assumes caller will setup context stack\r
+               and restore it.\r
+           @exception SQLException on error\r
+        */\r
+    EmbedSavepoint30(EmbedConnection conn, String name)\r
+    throws StandardException {\r
+               super(conn);\r
+               if (name == null) //this is an unnamed savepoint\r
+               {\r
+                               //Generating a unique internal name for unnamed savepoints\r
+                               savepointName = "i." + conn.getLanguageConnection().getUniqueSavepointName();\r
+                               savepointID = conn.getLanguageConnection().getUniqueSavepointID();\r
+               } else\r
+               {\r
+                               savepointName = "e." + name;\r
+                               savepointID = -1;\r
+               }\r
+               conn.getLanguageConnection().languageSetSavePoint(savepointName, this);\r
+    }\r
+\r
+       /**\r
+    *\r
+    * Retrieves the generated ID for the savepoint that this Savepoint object\r
+    * represents.\r
+    *\r
+    * @return the numeric ID of this savepoint\r
+    * @exception SQLException if this is a named savepoint\r
+    */\r
+    public int getSavepointId() throws SQLException {\r
+               if (savepointID == -1)\r
+                       throw newSQLException(SQLState.NO_ID_FOR_NAMED_SAVEPOINT);\r
+               return savepointID;\r
+    }\r
+\r
+       /**\r
+    *\r
+    * Retrieves the name of the savepoint that this Savepoint object\r
+    * represents.\r
+    *\r
+    * @return the name of this savepoint\r
+    * @exception SQLException if this is an un-named savepoint\r
+    */\r
+    public String getSavepointName() throws SQLException {\r
+               if (savepointID != -1)\r
+                       throw newSQLException(SQLState.NO_NAME_FOR_UNNAMED_SAVEPOINT);\r
+               return savepointName.substring(2);\r
+    }\r
+\r
+    // Derby internally keeps name for both named and unnamed savepoints\r
+    String getInternalName() {\r
+               return savepointName;\r
+    }\r
+\r
+\r
+    //bug 4468 - verify that savepoint rollback/release is for a savepoint from\r
+    //the current connection\r
+    boolean sameConnection(EmbedConnection con) {\r
+               return (getEmbedConnection().getLanguageConnection() == con.getLanguageConnection());\r
+    }\r
+}\r
+\r