--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.jdbc.EmbedConnectionContext\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
+//depot/main/java/org.apache.derby.impl.jdbc/EmbedConnectionContext.java#24 - edit change 16899 (text)\r
+package org.apache.derby.impl.jdbc;\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
+import org.apache.derby.iapi.sql.conn.StatementContext;\r
+import org.apache.derby.iapi.jdbc.ConnectionContext;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.ResultSet;\r
+\r
+import org.apache.derby.iapi.error.ExceptionSeverity;\r
+import java.sql.SQLException;\r
+import java.util.Vector;\r
+import java.util.Enumeration;\r
+/**\r
+ */\r
+class EmbedConnectionContext extends ContextImpl \r
+ implements ConnectionContext\r
+{\r
+\r
+ /**\r
+ We hold a soft reference to the connection so that when the application\r
+ releases its reference to the Connection without closing it, its finalize\r
+ method will be called, which will then close the connection. If a direct\r
+ reference is used here, such a Connection will never be closed or garbage\r
+ collected as modules hold onto the ContextManager and thus there would\r
+ be a direct reference through this object.\r
+ */\r
+ private java.lang.ref.SoftReference connRef;\r
+\r
+\r
+ EmbedConnectionContext(ContextManager cm, EmbedConnection conn) {\r
+ super(cm, ConnectionContext.CONTEXT_ID);\r
+\r
+ connRef = new java.lang.ref.SoftReference(conn);\r
+ }\r
+\r
+ public void cleanupOnError(Throwable error) {\r
+\r
+ if (connRef == null)\r
+ return;\r
+\r
+ EmbedConnection conn = (EmbedConnection) connRef.get();\r
+\r
+ if (error instanceof StandardException) {\r
+\r
+ StandardException se = (StandardException) error;\r
+ if (se.getSeverity() < ExceptionSeverity.SESSION_SEVERITY) {\r
+\r
+ // any error in auto commit mode that does not close the\r
+ // session will cause a rollback, thus remvoing the need\r
+ // for any commit. We could check this flag under autoCommit\r
+ // being true but the flag is ignored when autoCommit is false\r
+ // so why add the extra check\r
+ if (conn != null) {\r
+ conn.needCommit = false;\r
+ }\r
+ return;\r
+ }\r
+ }\r
+\r
+ // This may be a transaction without connection.\r
+ if (conn != null)\r
+ conn.setInactive(); // make the connection inactive & empty\r
+\r
+ connRef = null;\r
+ popMe();\r
+ }\r
+\r
+ //public java.sql.Connection getEmbedConnection()\r
+ //{\r
+ /// return conn;\r
+ //}\r
+\r
+ /**\r
+ Get a connection equivalent to the call\r
+ <PRE>\r
+ DriverManager.getConnection("jdbc:default:connection");\r
+ </PRE>\r
+ */\r
+ public java.sql.Connection getNestedConnection(boolean internal) throws SQLException {\r
+\r
+ EmbedConnection conn = (EmbedConnection) connRef.get();\r
+\r
+ if ((conn == null) || conn.isClosed())\r
+ throw Util.noCurrentConnection();\r
+\r
+ if (!internal) {\r
+ StatementContext sc = conn.getLanguageConnection().getStatementContext();\r
+ if ((sc == null) || (sc.getSQLAllowed() < org.apache.derby.catalog.types.RoutineAliasInfo.MODIFIES_SQL_DATA))\r
+ throw Util.noCurrentConnection();\r
+ }\r
+\r
+ return conn.getLocalDriver().getNewNestedConnection(conn);\r
+ }\r
+\r
+ /**\r
+ * Get a jdbc ResultSet based on the execution ResultSet.\r
+ *\r
+ * @param executionResultSet a result set as gotten from execution\r
+ * \r
+ */ \r
+ public java.sql.ResultSet getResultSet\r
+ (\r
+ ResultSet executionResultSet\r
+ ) throws SQLException\r
+ {\r
+ EmbedConnection conn = (EmbedConnection) connRef.get();\r
+\r
+ EmbedResultSet rs = conn.getLocalDriver().newEmbedResultSet(conn, executionResultSet, \r
+ false, (EmbedStatement) null, true);\r
+ return rs;\r
+ }\r
+\r
+ /**\r
+ * Process a ResultSet from a procedure to be a dynamic result,\r
+ * but one that will be closed due to it being inaccessible. We cannot simply\r
+ * close the ResultSet as it the nested connection that created\r
+ * it might be closed, leading to its close method being a no-op.\r
+ * This performs all the conversion (linking the ResultSet\r
+ * to a valid connection) required but does not close\r
+ * the ResultSet.\r
+ * \r
+ * @see EmbedStatement#processDynamicResult(EmbedConnection, java.sql.ResultSet, EmbedStatement)\r
+ */\r
+ public boolean processInaccessibleDynamicResult(java.sql.ResultSet resultSet) {\r
+ EmbedConnection conn = (EmbedConnection) connRef.get();\r
+ if (conn == null)\r
+ return false;\r
+ \r
+ // Pass in null as the Statement to own the ResultSet since\r
+ // we don't have one since the dynamic result will be inaccessible.\r
+ return EmbedStatement.processDynamicResult(conn, resultSet, null) != null;\r
+ }\r
+}\r