From derby-commits-return-10732-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Mon Sep 01 14:52:12 2008 Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 93876 invoked from network); 1 Sep 2008 14:52:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Sep 2008 14:52:12 -0000 Received: (qmail 61754 invoked by uid 500); 1 Sep 2008 14:52:10 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 61719 invoked by uid 500); 1 Sep 2008 14:52:10 -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 61710 invoked by uid 99); 1 Sep 2008 14:52:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Sep 2008 07:52:10 -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; Mon, 01 Sep 2008 14:51:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8F479238889D; Mon, 1 Sep 2008 07:51:51 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r690983 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/conn/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/functionTests/tests/lang/ Date: Mon, 01 Sep 2008 14:51:50 -0000 To: derby-commits@db.apache.org From: dag@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080901145151.8F479238889D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dag Date: Mon Sep 1 07:51:50 2008 New Revision: 690983 URL: http://svn.apache.org/viewvc?rev=690983&view=rev Log: DERBY-3859 Reset the current role when EmbedPooledConnection creates a new logical connection Patch derby-3859-1, plus fixed a comment type pointed out by Kristian. Makes Derby reset the current role to null in a pooling context when reusing a physical connection, similar to what is done for current schema. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=690983&r1=690982&r2=690983&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java Mon Sep 1 07:51:50 2008 @@ -608,6 +608,9 @@ // Reset the current schema (see DERBY-3690). setDefaultSchema(null); + + // Reset the current role + getCurrentSQLSessionContext().setRole(null); } /** Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=690983&r1=690982&r2=690983&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java Mon Sep 1 07:51:50 2008 @@ -1936,6 +1936,11 @@ * and then with statement pooling enabled if the environment supports it. *

* Relevant Jira issue: DERBY-3690. + *

+ * The current role also needs to be reset, but can't be tested here since + * we need to run with SQL authorization. + * + * @see org.apache.derbyTesting.functionTests.tests.lang.RolesTest#testCurrentRoleIsReset * * @throws SQLException if something goes wrong */ Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java?rev=690983&r1=690982&r2=690983&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RolesTest.java Mon Sep 1 07:51:50 2008 @@ -27,6 +27,8 @@ import java.sql.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; +import javax.sql.PooledConnection; +import javax.sql.ConnectionPoolDataSource; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.derbyTesting.junit.BaseJDBCTestCase; @@ -34,6 +36,7 @@ import org.apache.derbyTesting.junit.DatabasePropertyTestSetup; import org.apache.derbyTesting.junit.JDBC; import org.apache.derbyTesting.junit.TestConfiguration; +import org.apache.derbyTesting.junit.J2EEDataSource; /** * This JUnit tests the SQL roles feature. This feature relies on @@ -640,6 +643,8 @@ assertSysRolesRowCount(0, 4, 4); _stm.close(); + + testCurrentRoleIsReset(); } @@ -684,6 +689,79 @@ } + /** + * Verifies that the current role 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. + *

+ * The test pattern is borrowed from the test case in J2EEDataSourceTest. + * + * @see org.apache.derbyTesting.functionTests.tests.jdbcapi.J2EEDataSourceTest#testSchemaIsReset + * + * @throws SQLException if something goes wrong + */ + private void testCurrentRoleIsReset() + throws SQLException { + + if (_authLevel == SQLAUTHORIZATION && isDbo() /* once is enough */) { + final String user = "DonaldDuck"; + final String passwd = user.concat(pwSuffix); + ConnectionPoolDataSource cpDs = + J2EEDataSource.getConnectionPoolDataSource(); + // Test without statement pooling first. + doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd), + user); + + // Try to enable statement pooling. + // This is currently only implemented in the client driver. + if (usingDerbyNetClient()) { + J2EEDataSource.setBeanProperty( + cpDs, "maxStatements",new Integer(7)); + doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd), + user); + } + } + } + + /** + * Executes a test sequence to make sure the current role is reset between + * logical connections. + * + * @param pc pooled connection to get logical connections from + * @param user name of for the connection + * @throws SQLException if something goes wrong... + */ + private void doTestCurrentRoleIsReset(PooledConnection pc, String user) + throws SQLException { + + Connection con = pc.getConnection(); + Statement stmt = con.createStatement(); + String n_a = null; // auth level not used for this test + + JDBC.assertCurrentSchema(con, user.toUpperCase()); + + // Change the role. + stmt.execute("set role bar"); + ResultSet rs = stmt.executeQuery("values current_role"); + assertRoleInRs(rs, "BAR", n_a); + rs.close(); + stmt.close(); + + // Close the logical connection and get a new one and make sure the + // current role has been reset. + con.close(); + con = pc.getConnection(); + stmt = con.createStatement(); + rs = stmt.executeQuery("values current_role"); + assertRoleInRs(rs, null, n_a); + rs.close(); + stmt.close(); + con.close(); + } + + private void checkGrantCircularity() { if (isDbo()) { // Test circularity in role grant relation given this a