Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / jdbc / EmbedConnection30.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection30.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection30.java
new file mode 100644 (file)
index 0000000..90fd28e
--- /dev/null
@@ -0,0 +1,336 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.jdbc.EmbedConnection30\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.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.conn.StatementContext;\r
+import org.apache.derby.impl.jdbc.EmbedConnection;\r
+import org.apache.derby.impl.jdbc.Util;\r
+import org.apache.derby.jdbc.InternalDriver;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.reference.Limits;\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+\r
+import java.sql.Array;\r
+import java.sql.NClob;\r
+import java.sql.SQLClientInfoException;\r
+import java.sql.SQLXML;\r
+import java.sql.Savepoint;\r
+import java.sql.SQLException;\r
+import java.sql.Struct;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+import java.util.Vector;\r
+import java.util.concurrent.Executor;\r
+\r
+\r
+/**\r
+ * This class extends the EmbedConnection20 class in order to support new\r
+ * methods and classes that come with JDBC 3.0.\r
+\r
+   <P><B>Supports</B>\r
+   <UL>\r
+   <LI> JSR169 - Subsetting only removes getTypeMap and setTypeMap, which references\r
+        java.util.Map which exists in Foundation and ee.miniumum. Thus the methods can\r
+               safely be left in the implementation for JSR169.\r
+\r
+  <LI> JDBC 3.0 - Separate from JDBC 2.0 implementation as JDBC 3.0 introduces\r
+        a new class java.sql.Savepoint, which is referenced by java.sql.Connection.\r
+   </UL>\r
+ *\r
+ * @see org.apache.derby.impl.jdbc.EmbedConnection\r
+ *\r
+ */\r
+public class EmbedConnection30 extends EmbedConnection\r
+{\r
+\r
+       //////////////////////////////////////////////////////////\r
+       // CONSTRUCTORS\r
+       //////////////////////////////////////////////////////////\r
+\r
+       public EmbedConnection30(\r
+                       InternalDriver driver,\r
+                       String url,\r
+                       Properties info)\r
+               throws SQLException\r
+       {\r
+               super(driver, url, info);\r
+       }\r
+\r
+       public EmbedConnection30(\r
+                       EmbedConnection inputConnection)\r
+       {\r
+               super(inputConnection);\r
+       }\r
+\r
+       /////////////////////////////////////////////////////////////////////////\r
+       //\r
+       //      JDBC 3.0        -       New public methods\r
+       //\r
+       /////////////////////////////////////////////////////////////////////////\r
+\r
+       /**\r
+        * Creates an unnamed savepoint in the current transaction and\r
+        * returns the new Savepoint object that represents it.\r
+        *\r
+        *\r
+        * @return  The new Savepoint object\r
+        *\r
+        * @exception SQLException if a database access error occurs or\r
+        * this Connection object is currently in auto-commit mode\r
+        */\r
+       public Savepoint setSavepoint()\r
+               throws SQLException\r
+       {\r
+               return commonSetSavepointCode(null, false);\r
+       }\r
+\r
+       /**\r
+        * Creates a savepoint with the given name in the current transaction and\r
+        * returns the new Savepoint object that represents it.\r
+        *\r
+        *\r
+        * @param name  A String containing the name of the savepoint\r
+        *\r
+        * @return  The new Savepoint object\r
+        *\r
+        * @exception SQLException if a database access error occurs or\r
+        * this Connection object is currently in auto-commit mode\r
+        */\r
+       public Savepoint setSavepoint(\r
+                       String name)\r
+               throws SQLException\r
+       {\r
+               return commonSetSavepointCode(name, true);\r
+       }\r
+\r
+       /**\r
+        * Creates a savepoint with the given name(if it is a named savepoint else we will generate a name\r
+        * because Derby only supports named savepoints internally) in the current transaction and\r
+        * returns the new Savepoint object that represents it.\r
+        *\r
+        * @param name  A String containing the name of the savepoint. Will be null if this is an unnamed savepoint\r
+        * @param userSuppliedSavepointName  If true means it's a named user defined savepoint.\r
+        *\r
+        * @return  The new Savepoint object\r
+        */\r
+       private Savepoint commonSetSavepointCode(String name, boolean userSuppliedSavepointName) throws SQLException\r
+       {\r
+               synchronized (getConnectionSynchronization()) {\r
+                       setupContextStack();\r
+                       try {\r
+                               verifySavepointCommandIsAllowed();\r
+                               if (userSuppliedSavepointName && (name == null))//make sure that if it is a named savepoint then supplied name is not null\r
+                                       throw newSQLException(SQLState.NULL_NAME_FOR_SAVEPOINT);\r
+                               //make sure that if it is a named savepoint then supplied name length is not > 128\r
+                               if (userSuppliedSavepointName && (name.length() > Limits.MAX_IDENTIFIER_LENGTH))\r
+                                       throw newSQLException(SQLState.LANG_IDENTIFIER_TOO_LONG, name, String.valueOf(Limits.MAX_IDENTIFIER_LENGTH));\r
+                               if (userSuppliedSavepointName && name.startsWith("SYS")) //to enforce DB2 restriction which is savepoint name can't start with SYS\r
+                                       throw newSQLException(SQLState.INVALID_SCHEMA_SYS, "SYS");\r
+                               Savepoint savePt = new EmbedSavepoint30(this, name);\r
+                               return savePt;\r
+                       } catch (StandardException e) {\r
+                               throw handleException(e);\r
+                       } finally {\r
+                           restoreContextStack();\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Undoes all changes made after the given Savepoint object was set.\r
+        * This method should be used only when auto-commit has been disabled.\r
+        *\r
+        *\r
+        * @param savepoint  The Savepoint object to rollback to\r
+        *\r
+        * @exception SQLException  if a database access error occurs,\r
+        * the Savepoint object is no longer valid, or this Connection\r
+        * object is currently in auto-commit mode\r
+        */\r
+       public void rollback(\r
+                       Savepoint savepoint)\r
+               throws SQLException\r
+       {\r
+               synchronized (getConnectionSynchronization()) {\r
+                       setupContextStack();\r
+                       try {\r
+                               verifySavepointCommandIsAllowed();\r
+                               verifySavepointArg(savepoint);\r
+                               //Need to cast and get the name because JDBC3 spec doesn't support names for\r
+                               //unnamed savepoints but Derby keeps names for named & unnamed savepoints.\r
+                               getLanguageConnection().internalRollbackToSavepoint(((EmbedSavepoint30)savepoint).getInternalName(),true, savepoint);\r
+                       } catch (StandardException e) {\r
+                               throw handleException(e);\r
+                       } finally {\r
+                           restoreContextStack();\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Removes the given Savepoint object from the current transaction.\r
+        * Any reference to the savepoint after it has been removed will cause\r
+        * an SQLException to be thrown\r
+        *\r
+        *\r
+        * @param savepoint  The Savepoint object to be removed\r
+        *\r
+        * @exception SQLException  if a database access error occurs or the\r
+        * given Savepoint object is not a valid savepoint in the current transaction\r
+        */\r
+       public void releaseSavepoint(\r
+                       Savepoint savepoint)\r
+               throws SQLException\r
+       {\r
+               synchronized (getConnectionSynchronization()) {\r
+                       setupContextStack();\r
+                       try {\r
+                               verifySavepointCommandIsAllowed();\r
+                               verifySavepointArg(savepoint);\r
+                               //Need to cast and get the name because JDBC3 spec doesn't support names for\r
+                               //unnamed savepoints but Derby keeps name for named & unnamed savepoints.\r
+                               getLanguageConnection().releaseSavePoint(((EmbedSavepoint30)savepoint).getInternalName(), savepoint);\r
+                       } catch (StandardException e) {\r
+                               throw handleException(e);\r
+                       } finally {\r
+                           restoreContextStack();\r
+                       }\r
+               }\r
+       }\r
+\r
+       // used by setSavepoint to check autocommit is false and not inside the trigger code\r
+       private void verifySavepointCommandIsAllowed() throws SQLException\r
+       {\r
+               if (autoCommit)\r
+                       throw newSQLException(SQLState.NO_SAVEPOINT_WHEN_AUTO);\r
+\r
+               //Bug 4507 - savepoint not allowed inside trigger\r
+               StatementContext stmtCtxt = getLanguageConnection().getStatementContext();\r
+               if (stmtCtxt!= null && stmtCtxt.inTrigger())\r
+                       throw newSQLException(SQLState.NO_SAVEPOINT_IN_TRIGGER);\r
+       }\r
+\r
+       // used by release/rollback to check savepoint argument\r
+       private void verifySavepointArg(Savepoint savepoint) throws SQLException\r
+       {\r
+               //bug 4451 - Check for null savepoint\r
+               EmbedSavepoint30 lsv = (EmbedSavepoint30) savepoint;\r
+           // bug 4451 need to throw error for null Savepoint\r
+           if (lsv == null)\r
+               throw\r
+                   Util.generateCsSQLException(SQLState.XACT_SAVEPOINT_NOT_FOUND, "null");\r
+\r
+               //bug 4468 - verify that savepoint rollback is for a savepoint from the current\r
+               // connection\r
+               if (!lsv.sameConnection(this))\r
+                       throw newSQLException(SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL);\r
+      \r
+               return;\r
+       }\r
+\r
+       public Array createArrayOf(String typeName, Object[] elements)\r
+                       throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public NClob createNClob() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public SQLXML createSQLXML() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public Struct createStruct(String typeName, Object[] attributes)\r
+                       throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public Properties getClientInfo() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public String getClientInfo(String name) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public boolean isValid(int timeout) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return false;\r
+       }\r
+\r
+       public void setClientInfo(Properties properties)\r
+                       throws SQLClientInfoException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       public void setClientInfo(String name, String value)\r
+                       throws SQLClientInfoException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+\r
+       public boolean isWrapperFor(Class<?> iface) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return false;\r
+       }\r
+\r
+       public <T> T unwrap(Class<T> iface) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public void setSchema(String schema) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       public String getSchema() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       public void abort(Executor executor) throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       public void setNetworkTimeout(Executor executor, int milliseconds)\r
+                       throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       public int getNetworkTimeout() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return 0;\r
+       }\r
+}\r