db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
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 GMT
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.
      * <p>
      * Relevant Jira issue: DERBY-3690.
+     * <p>
+     * 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.
+     * <p>
+     * The test is run in a non-statement pooling configuration first,
+     * and then with statement pooling enabled if the environment supports it.
+     * <p>
+     * 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



Mime
View raw message