Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 56669 invoked from network); 27 May 2008 07:00:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 May 2008 07:00:35 -0000 Received: (qmail 53084 invoked by uid 500); 27 May 2008 07:00:37 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 53011 invoked by uid 500); 27 May 2008 07:00:37 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 53002 invoked by uid 99); 27 May 2008 07:00:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 May 2008 00:00:37 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 May 2008 06:59:50 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 96BC32388A76; Tue, 27 May 2008 00:00:11 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r660408 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/sql/conn/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/junit/ Date: Tue, 27 May 2008 07:00:11 -0000 To: derby-commits@db.apache.org From: kristwaa@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080527070011.96BC32388A76@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kristwaa Date: Tue May 27 00:00:10 2008 New Revision: 660408 URL: http://svn.apache.org/viewvc?rev=660408&view=rev Log: DERBY-3690: EmbedPooledConnection doesn't reset schema when creating a new logical connection. Merged revision 660404 (derby-3690-1b-reset_schema.diff) from trunk. Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/JDBC.java Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=660408&r1=660407&r2=660408&view=diff ============================================================================== --- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java (original) +++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java Tue May 27 00:00:10 2008 @@ -583,6 +583,9 @@ // drop all temp tables. dropAllDeclaredGlobalTempTables(); + + // Reset the current schema (see DERBY-3690). + setDefaultSchema(null); } /** Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=660408&r1=660407&r2=660408&view=diff ============================================================================== --- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original) +++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Tue May 27 00:00:10 2008 @@ -144,6 +144,8 @@ suite.addTest(new J2EEDataSourceTest("testClosedXADSConnection")); suite.addTest(new J2EEDataSourceTest("testSetSchemaInXAConnection")); suite.addTest(new J2EEDataSourceTest("testPooledReuseOnClose")); + suite.addTest(new J2EEDataSourceTest("testSchemaIsReset")); + suite.addTest(new J2EEDataSourceTest("testSchemaIsResetWhenDeleted")); return suite; } @@ -1696,7 +1698,105 @@ conn3.close(); xac3.close(); } - + + /** + * Verifies that the schema is reset when creating a new logical connection. + *

+ * The test is run in a non-statement pooling configuration first, + * and then with statement pooling enabled if the environment supports it. + *

+ * Relevant Jira issue: DERBY-3690. + * + * @throws SQLException if something goes wrong + */ + public void testSchemaIsReset() + throws SQLException { + final String userSchema = "USERSCHEMA"; + ConnectionPoolDataSource cpDs = + J2EEDataSource.getConnectionPoolDataSource(); + J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create"); + // Connect with a user specified, which should cause the schema to be + // set to the user name. + // Test without statement pooling first. + doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"), + userSchema); + + // Try to enable statement pooling. + // This is currently only implemented in the client driver. + if (usingDerbyNetClient()) { + J2EEDataSource.setBeanProperty( + cpDs, "maxStatements",new Integer(7)); + doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"), + userSchema); + } + } + + /** + * Executes a test sequence to make sure the schema is reset between + * logical connections. + * + * @param pc pooled connection to get logical connections from + * @param userSchema name of the default schema for the connection (user) + * @throws SQLException if something goes wrong... + */ + private void doTestSchemaIsReset(PooledConnection pc, String userSchema) + throws SQLException { + Connection con1 = pc.getConnection(); + JDBC.assertCurrentSchema(con1, userSchema); + Statement stmt1 = con1.createStatement(); + // Change the schema. + stmt1.execute("set schema APP"); + stmt1.close(); + JDBC.assertCurrentSchema(con1, "APP"); + // Close the logical connection and get a new one. + con1.close(); + Connection con2 = pc.getConnection(); + // Make sure the schema has been reset from APP to the user name. + JDBC.assertCurrentSchema(con2, userSchema); + con2.close(); + // Try a third time, but don't change the schema now. + Connection con3 = pc.getConnection(); + JDBC.assertCurrentSchema(con3, userSchema); + con3.close(); + pc.close(); + } + + /** + * Tests that deleting the current / default schema doesn't cause the next + * logical connection to fail. + *

+ * Relevant Jira issue: DERBY-3690. + * + * @throws SQLException if something goes wrong + */ + public void testSchemaIsResetWhenDeleted() + throws SQLException { + final String userSchema = "AUSER"; + ConnectionPoolDataSource cpDs = + J2EEDataSource.getConnectionPoolDataSource(); + J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create"); + PooledConnection pc = cpDs.getPooledConnection(userSchema, "secret"); + // Get first connection, create a table, then drop schema. + Connection con = pc.getConnection(); + JDBC.assertCurrentSchema(con, userSchema); + Statement stmt = con.createStatement(); + stmt.executeUpdate("create table schematest (id int)"); + stmt.executeUpdate("drop table schematest"); + stmt.executeUpdate("drop schema " + userSchema + " restrict"); + stmt.close(); + con.close(); + // Get second connection. + con = pc.getConnection(); + JDBC.assertCurrentSchema(con, userSchema); + stmt = con.createStatement(); + stmt.executeUpdate("create table schematest (id int)"); + stmt.executeUpdate("drop table schematest"); + stmt.close(); + JDBC.assertCurrentSchema(con, userSchema); + con.close(); + pc.close(); + } + // test that an xastart in auto commit mode commits the existing work. // test fix of a bug ('beetle 5178') wherein XAresource.start() when // auto-commit is true did not implictly commit any transaction Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/JDBC.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=660408&r1=660407&r2=660408&view=diff ============================================================================== --- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/JDBC.java (original) +++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/junit/JDBC.java Tue May 27 00:00:10 2008 @@ -1237,6 +1237,24 @@ } /** + * Asserts that the current schema is the same as the one specified. + * + * @param con connection to check schema in + * @param schema expected schema name + * @throws SQLException if something goes wrong + */ + public static void assertCurrentSchema(Connection con, String schema) + throws SQLException { + Statement stmt = con.createStatement(); + try { + JDBC.assertSingleValueResultSet( + stmt.executeQuery("VALUES CURRENT SCHEMA"), schema); + } finally { + stmt.close(); + } + } + + /** * Convert byte array to String. * Each byte is converted to a hexadecimal string representation. *