Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / jdbc / BrokeredConnection40.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection40.java
new file mode 100644 (file)
index 0000000..a263c65
--- /dev/null
@@ -0,0 +1,346 @@
+/*\r
\r
+   Derby - Class org.apache.derby.iapi.jdbc.BrokeredConnection40\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.jdbc;\r
+\r
+import java.sql.Array;\r
+import java.sql.Blob;\r
+import java.sql.Clob;\r
+import java.sql.Connection;\r
+import java.sql.SQLClientInfoException;\r
+import java.sql.NClob;\r
+import java.sql.SQLException;\r
+import java.sql.SQLXML;\r
+import java.sql.Struct;\r
+import java.util.Properties;\r
+import org.apache.derby.impl.jdbc.Util;\r
+//import org.apache.derby.impl.jdbc.EmbedConnection40;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+\r
+public class BrokeredConnection40 extends BrokeredConnection30 {\r
+    \r
+    /** Creates a new instance of BrokeredConnection40 */\r
+    public BrokeredConnection40(BrokeredConnectionControl control) {\r
+        super(control);\r
+    }\r
+    \r
+    public Array createArrayOf(String typeName, Object[] elements)\r
+          throws SQLException {    \r
+         try {\r
+             return getRealConnection().createArrayOf (typeName, elements);\r
+         } catch (SQLException sqle) {\r
+             notifyException(sqle);\r
+             throw sqle;\r
+         }\r
+    }\r
+    \r
+    /**\r
+     *\r
+     * Constructs an object that implements the <code>Blob</code> interface. The object\r
+     * returned initially contains no data.  The <code>setBinaryStream</code> and\r
+     * <code>setBytes</code> methods of the <code>Blob</code> interface may be used to add data to\r
+     * the <code>Blob</code>.\r
+     *\r
+     * @return  An object that implements the <code>Blob</code> interface\r
+     * @throws SQLException if an object that implements the\r
+     * <code>Blob</code> interface can not be constructed, this method is \r
+     * called on a closed connection or a database access error occurs.\r
+     *\r
+     */\r
+    public Blob createBlob() throws SQLException {\r
+        // Forward the createBlob call to the physical connection\r
+        try {\r
+            return getRealConnection().createBlob();\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+\r
+    /**\r
+     *\r
+     * Constructs an object that implements the <code>Clob</code> interface. The object\r
+     * returned initially contains no data.  The <code>setAsciiStream</code>,\r
+     * <code>setCharacterStream</code> and <code>setString</code> methods of \r
+     * the <code>Clob</code> interface may be used to add data to the <code>Clob</code>.\r
+     *\r
+     * @return An object that implements the <code>Clob</code> interface\r
+     * @throws SQLException if an object that implements the\r
+     * <code>Clob</code> interface can not be constructed, this method is \r
+     * called on a closed connection or a database access error occurs.\r
+     *\r
+     */\r
+    public Clob createClob() throws SQLException{\r
+        // Forward the createClob call to the physical connection\r
+        try {\r
+            return getRealConnection().createClob();\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    \r
+    \r
+    public NClob createNClob() throws SQLException{\r
+         try {\r
+             return getRealConnection().createNClob();\r
+         } catch (SQLException sqle) {\r
+             notifyException(sqle);\r
+             throw sqle;\r
+         }\r
+    }\r
+    \r
+    public SQLXML createSQLXML() throws SQLException{\r
+         try {\r
+             return getRealConnection().createSQLXML ();\r
+         } catch (SQLException sqle) {\r
+             notifyException(sqle);\r
+             throw sqle;\r
+         }\r
+    }\r
+    \r
+    public Struct createStruct(String typeName, Object[] attributes)\r
+          throws SQLException {\r
+         try {\r
+             return getRealConnection().createStruct (typeName, attributes);\r
+         } catch (SQLException sqle) {\r
+             notifyException(sqle);\r
+             throw sqle;\r
+         }\r
+    }\r
+\r
+\r
+    /**\r
+     * Checks if the connection has not been closed and is still valid. \r
+     * The validity is checked by running a simple query against the \r
+     * database.\r
+     *\r
+     * @param timeout The time in seconds to wait for the database\r
+     * operation used to validate the connection to complete. If the \r
+     * timeout period expires before the operation completes, this \r
+     * method returns false. A value of 0 indicates a timeout is not \r
+     * applied to the database operation.\r
+     * @return true if the connection is valid, false otherwise\r
+     * @throws SQLException if the call on the physical connection throws an\r
+     * exception.\r
+     */\r
+    public final boolean isValid(int timeout) throws SQLException{\r
+        // Check first if the Brokered connection is closed\r
+        if (isClosed()) {\r
+            return false;\r
+        }\r
+\r
+        // Forward the isValid call to the physical connection\r
+        try {\r
+            return getRealConnection().isValid(timeout);\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    \r
+    \r
+    /**\r
+     * <code>setClientInfo</code> forwards to the real connection.\r
+     *\r
+     * @param name the property key <code>String</code>\r
+     * @param value the property value <code>String</code>\r
+     * @exception SQLClientInfoException if the property is not\r
+     * supported or the real connection could not be obtained.\r
+     */\r
+    public void setClientInfo(String name, String value)\r
+    throws SQLClientInfoException{        \r
+        try {\r
+            getRealConnection().setClientInfo(name, value);\r
+        } catch (SQLClientInfoException se) {\r
+            notifyException(se);\r
+            throw se;\r
+        }\r
+        catch (SQLException se) {\r
+            notifyException(se);\r
+            throw new SQLClientInfoException\r
+                (se.getMessage(), se.getSQLState(), \r
+                               se.getErrorCode(),\r
+                (new FailedProperties40\r
+                 (FailedProperties40.makeProperties(name,value))).\r
+                getProperties());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * <code>setClientInfo</code> forwards to the real connection.  If\r
+     * the call to <code>getRealConnection</code> fails the resulting\r
+     * <code>SQLException</code> is wrapped in a\r
+     * <code>SQLClientInfoException</code> to satisfy the specified\r
+     * signature.\r
+     * @param properties a <code>Properties</code> object with the\r
+     * properties to set.\r
+     * @exception SQLClientInfoException if the properties are not\r
+     * supported or the real connection could not be obtained.\r
+     */    \r
+    public void setClientInfo(Properties properties)\r
+    throws SQLClientInfoException{\r
+        try {\r
+            getRealConnection().setClientInfo(properties);\r
+        } catch (SQLClientInfoException cie) {\r
+            notifyException(cie);\r
+            throw cie;\r
+        }\r
+        catch (SQLException se) {\r
+            notifyException(se);\r
+            throw new SQLClientInfoException\r
+                (se.getMessage(), se.getSQLState(),\r
+                               se.getErrorCode(),\r
+                (new FailedProperties40(properties)).getProperties());\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * <code>getClientInfo</code> forwards to the real connection.\r
+     *\r
+     * @param name a <code>String</code> that is the property key to get.\r
+     * @return a <code>String</code> that is returned from the real connection.\r
+     * @exception SQLException if a database access error occurs.\r
+     */\r
+    public String getClientInfo(String name)\r
+    throws SQLException{\r
+        try {\r
+            return getRealConnection().getClientInfo(name);\r
+        } catch (SQLException se) {\r
+            notifyException(se);\r
+            throw se;\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * <code>getClientInfo</code> forwards to the real connection.\r
+     *\r
+     * @return a <code>Properties</code> object\r
+     * from the real connection.\r
+     * @exception SQLException if a database access error occurs.\r
+     */\r
+    public Properties getClientInfo()\r
+    throws SQLException{\r
+        try {\r
+            return getRealConnection().getClientInfo();\r
+        } catch (SQLException se) {\r
+            notifyException(se);\r
+            throw se;\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * returns an instance of JDBC4.0 speccific class BrokeredStatement40\r
+     * @param  statementControl BrokeredStatementControl\r
+     * @return an instance of BrokeredStatement40 \r
+     * throws java.sql.SQLException\r
+     */\r
+    public final BrokeredStatement newBrokeredStatement\r
+            (BrokeredStatementControl statementControl) throws SQLException {\r
+        try {\r
+            return new BrokeredStatement40(statementControl);\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    public final BrokeredPreparedStatement newBrokeredStatement(BrokeredStatementControl statementControl, String sql, Object generatedKeys) throws SQLException {\r
+        try {\r
+            return new BrokeredPreparedStatement40(statementControl, sql, generatedKeys);\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    public final BrokeredCallableStatement newBrokeredStatement(BrokeredStatementControl statementControl, String sql) throws SQLException {\r
+        try {\r
+            return new BrokeredCallableStatement40(statementControl, sql);\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Returns the type map for this connection.\r
+     *\r
+     * @return type map for this connection\r
+     * @exception SQLException if a database access error occurs\r
+     */\r
+    public final java.util.Map<String,Class<?>> getTypeMap() throws SQLException {\r
+        try {\r
+            return getRealConnection().getTypeMap();\r
+        } catch (SQLException se) {\r
+            notifyException(se);\r
+            throw se;\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Returns false unless <code>interfaces</code> is implemented \r
+     * \r
+     * @param  interfaces             a Class defining an interface.\r
+     * @return true                   if this implements the interface or \r
+     *                                directly or indirectly wraps an object \r
+     *                                that does.\r
+     * @throws java.sql.SQLException  if an error occurs while determining \r
+     *                                whether this is a wrapper for an object \r
+     *                                with the given interface.\r
+     */\r
+    public final boolean isWrapperFor(Class<?> interfaces) throws SQLException {\r
+        try {\r
+            if (getRealConnection().isClosed())\r
+                throw Util.noCurrentConnection();\r
+            return interfaces.isInstance(this);\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }\r
+    \r
+    /**\r
+     * Returns <code>this</code> if this class implements the interface\r
+     *\r
+     * @param  interfaces a Class defining an interface\r
+     * @return an object that implements the interface\r
+     * @throws java.sql.SQLExption if no object if found that implements the \r
+     * interface\r
+     */\r
+    public final <T> T unwrap(java.lang.Class<T> interfaces) \r
+                            throws SQLException{\r
+        try {\r
+            if (getRealConnection().isClosed())\r
+                throw Util.noCurrentConnection();\r
+            //Derby does not implement non-standard methods on \r
+            //JDBC objects\r
+            try {\r
+                return interfaces.cast(this);\r
+            } catch (ClassCastException cce) {\r
+                throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP,\r
+                        interfaces);\r
+            }\r
+        } catch (SQLException sqle) {\r
+            notifyException(sqle);\r
+            throw sqle;\r
+        }\r
+    }    \r
+}\r