db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r436929 - in /db/derby/code/branches/10.2/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ testing/org/apache/derbyTesting/funct...
Date Fri, 25 Aug 2006 20:26:19 GMT
Author: rhillegas
Date: Fri Aug 25 13:26:17 2006
New Revision: 436929

URL: http://svn.apache.org/viewvc?rev=436929&view=rev
Log:
DERBY-1725: Merge the following patches from trunk to 10.2 branch: No JIRA (436653, 434587,
434586, 434581), DERBY-1708 (434577).

Added:
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
      - copied unchanged from r436654, db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DatabasePropertyTestSetup.java
Modified:
    db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/JDBC.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
(original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
Fri Aug 25 13:26:17 2006
@@ -31,6 +31,8 @@
 
 import org.apache.derby.iapi.sql.compile.CompilerContext;
 
+import org.apache.derby.iapi.sql.conn.Authorizer;
+
 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
@@ -157,6 +159,14 @@
 		/* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
 		cc.createDependency(lockTableDescriptor);
 		cc.createDependency(cd);
+
+		if (isPrivilegeCollectionRequired())
+		{
+			// need SELECT privilege to perform lock table statement.
+			cc.pushCurrentPrivType(Authorizer.SELECT_PRIV);
+			cc.addRequiredTablePriv(lockTableDescriptor);
+			cc.popCurrentPrivType();
+		}
 
 		return this;
 	}

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
Fri Aug 25 13:26:17 2006
@@ -2900,4 +2900,40 @@
 0 rows inserted/updated/deleted
 ij(MAMTA1)> drop function f_abs;
 0 rows inserted/updated/deleted
-ij(MAMTA1)> 
+ij(MAMTA1)> -- DERBY-1708
+-- Test LOCK TABLE statement
+connect 'grantRevokeDDL' user 'user1' as user1;
+WARNING 01J14: SQL authorization is being used without first enabling authentication.
+ij(USER1)> create table t100 (i int);
+0 rows inserted/updated/deleted
+ij(USER1)> connect 'grantRevokeDDL' user 'user2' as user2;
+WARNING 01J14: SQL authorization is being used without first enabling authentication.
+ij(USER2)> autocommit off;
+ij(USER2)> -- expect errors
+lock table user1.t100 in exclusive mode;
+ERROR: Failed with SQLSTATE 28506
+ij(USER2)> lock table user1.t100 in share mode;
+ERROR: Failed with SQLSTATE 28506
+ij(USER2)> commit;
+ij(USER2)> set connection user1;
+ij(USER1)> grant select on t100 to user2;
+0 rows inserted/updated/deleted
+ij(USER1)> set connection user2;
+ij(USER2)> -- ok
+lock table user1.t100 in exclusive mode;
+0 rows inserted/updated/deleted
+ij(USER2)> lock table user1.t100 in share mode;
+0 rows inserted/updated/deleted
+ij(USER2)> commit;
+ij(USER2)> set connection user1;
+ij(USER1)> revoke select on t100 from user2;
+0 rows inserted/updated/deleted
+ij(USER1)> set connection user2;
+ij(USER2)> -- expect errors
+lock table user1.t100 in exclusive mode;
+ERROR: Failed with SQLSTATE 28506
+ij(USER2)> lock table user1.t100 in share mode;
+ERROR: Failed with SQLSTATE 28506
+ij(USER2)> commit;
+ij(USER2)> autocommit on;
+ij(USER2)> 

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadBooting.java
Fri Aug 25 13:26:17 2006
@@ -61,6 +61,7 @@
 	//	STATE
 	//
 	/////////////////////////////////////////////////////////////
+    
 
 	/////////////////////////////////////////////////////////////
 	//
@@ -82,6 +83,18 @@
 	//
 	/////////////////////////////////////////////////////////////
 
+    /**
+     * Only run embedded.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        
+        if (usingEmbedded())
+            suite.addTestSuite(AutoloadBooting.class);
+        
+        return suite;
+    }
+    
 	/////////////////////////////////////////////////////////////
 	//
 	//	TEST ENTRY POINTS
@@ -103,15 +116,6 @@
 		//
 		//CONFIG.setVerbosity( true );
 
-		//
-		// Only run embedded.
-		//
-		if ( !usingEmbedded() )
-		{
-			println( "Not running in the embedded framework. Exitting..." );
-			return;
-		}
-
 		vetInitialization();
 		scenario1_3();
 		scenario2();
@@ -348,16 +352,19 @@
 	private	void	loadNetworkClientDriver()
 		throws Exception
 	{
-		boolean		isAutoloading = !getTestConfiguration().autoloading();
+        // This test is only run in JDBC 4 or higher which means the
+        // drivers will always be auto-loading when the classes are
+        // being loaded from the jars.
+		boolean		isAutoloading = getTestConfiguration().loadingFromJars();
 		
 		//
 		// Forcibly load the network client if we are not autoloading it.
 		//
-		if ( isAutoloading )
+		if ( !isAutoloading )
 		{
 			println( "Not autoloading, so forcibly faulting in the client driver." );
 
-			Class.forName( CLIENT_DRIVER_NAME );
+			Class.forName( CLIENT_DRIVER_NAME ).newInstance();
 		}
 
 		//

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/AutoloadTest.java
Fri Aug 25 13:26:17 2006
@@ -30,12 +30,15 @@
 
 package org.apache.derbyTesting.functionTests.tests.jdbc4;
 
+import java.security.PrivilegedActionException;
 import java.sql.*;
 import java.util.*;
 import junit.framework.*;
 
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
 
 public	class	AutoloadTest	extends	BaseJDBCTestCase
 {
@@ -72,6 +75,55 @@
 	//	JUnit BEHAVIOR
 	//
 	/////////////////////////////////////////////////////////////
+    
+    /**
+     * Only run a test if the driver will be auto-loaded.
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+        
+        // need DriverManager at least and Derby drivers
+        // no interest in testing DB2's client.
+        if (JDBC.vmSupportsJDBC2() &&
+                (usingEmbedded() || usingDerbyNetClient()))
+        {
+
+            boolean autoloadingCurrentDriver = false;
+            
+            // Autoloading if the current driver is defined in the
+            // system property jdbc.drivers, see java.sql.DriverManager.
+            try {
+                String jdbcDrivers = getSystemProperty("jdbc.drivers");
+                if (jdbcDrivers != null)
+                {
+                    // Simple test to see if the driver class is
+                    // in the value. Could get fancy and see if it is
+                    // correctly formatted but not worth it.
+                    String driver =
+                        TestConfiguration.getCurrent().getJDBCClient().getJDBCDriverName();
+                    
+                    if (jdbcDrivers.indexOf(driver) != -1)
+                        autoloadingCurrentDriver = true;
+                }
+                
+            } catch (PrivilegedActionException e) {
+                // can't read property, assume not autoloading.
+            }
+            
+            // Also auto loading if this is JDBC 4 and loading from the
+            // jar files, due to the required manifest entry.
+            if (JDBC.vmSupportsJDBC4() &&
+                    TestConfiguration.getCurrent().loadingFromJars())
+                autoloadingCurrentDriver = true;
+          
+            if (autoloadingCurrentDriver)
+                suite.addTestSuite(AutoloadTest.class);
+
+        }
+        
+        return suite;
+    }
 
 	/////////////////////////////////////////////////////////////
 	//
@@ -101,30 +153,28 @@
 		// We expect that the connection to the database will fail for
 		// one reason or another.
 		//
-		if ( getTestConfiguration().autoloading() )
-		{
-			println( "We ARE autoloading..." );
-
-			//
-			// The DriverManager should have autoloaded the client driver.
-			// This means that the connection request is passed on to the
-			// server. The server then determines that the database does
-			// not exist. This raises a different error depending on whether
-			// we're running embedded or with the Derby client.
-			//
-			if ( usingEmbedded() ) { failToConnect( "XJ004" ); }
-			else { failToConnect( "08004" ); }
-		}
-		else
-		{
-			println( "We are NOT autoloading..." );
-
-			//
-			// We aren't autoloading the driver. The
-			// DriverManager returns the following SQLState.
-			//
-			failToConnect( "08001" );
-		}
+
+		println( "We ARE autoloading..." );
+
+		//
+		// The DriverManager should have autoloaded the client driver.
+		// This means that the connection request is passed on to the
+		// server. The server then determines that the database does
+		// not exist. This raises a different error depending on whether
+		// we're running embedded or with the Derby client.
+		//
+        String expectedError =
+            usingEmbedded() ? "XJ004" : "08004";
+        
+        failToConnect(expectedError);
+       
+        // Test we can connect successfully to a database!
+        String url = getTestConfiguration().getJDBCUrl();
+        url = url.concat(";create=true");
+        String user = getTestConfiguration().getUserName();
+        String password = getTestConfiguration().getUserPassword();
+        DriverManager.getConnection(url, user, password).close();
+
 	}
 
 	/**
@@ -147,6 +197,8 @@
 			println( "Attempting to connect with this URL: '" + connectionURL + "'" );
 			
 			DriverManager.getConnection( connectionURL, properties );
+            
+            fail("Connection succeed, expected to fail.");
 		}
 		catch ( SQLException e ) { se = e; }
 

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
Fri Aug 25 13:26:17 2006
@@ -18,11 +18,18 @@
  * language governing permissions and limitations under the License.
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
-import junit.framework.*;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 
 /**
  * Testing concurrency behaviour in derby when creating the resultsets with
@@ -875,7 +882,7 @@
         final Properties properties = new Properties();
         properties.setProperty("derby.locks.waitTimeout", "4");
         
-        return new SystemPropertyTestSetup(suite, properties);
+        return new DatabasePropertyTestSetup(suite, properties);
     }
     
 }

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
Fri Aug 25 13:26:17 2006
@@ -1830,3 +1830,29 @@
 
 drop table mamta1Table;
 drop function f_abs;
+
+-- DERBY-1708
+-- Test LOCK TABLE statement
+connect 'grantRevokeDDL' user 'user1' as user1;
+create table t100 (i int);
+connect 'grantRevokeDDL' user 'user2' as user2;
+autocommit off;
+-- expect errors
+lock table user1.t100 in exclusive mode;
+lock table user1.t100 in share mode;
+commit;
+set connection user1;
+grant select on t100 to user2;
+set connection user2;
+-- ok
+lock table user1.t100 in exclusive mode;
+lock table user1.t100 in share mode;
+commit;
+set connection user1;
+revoke select on t100 from user2;
+set connection user2;
+-- expect errors
+lock table user1.t100 in exclusive mode;
+lock table user1.t100 in share mode;
+commit;
+autocommit on;
\ No newline at end of file

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/largeCodeGen.java
Fri Aug 25 13:26:17 2006
@@ -116,7 +116,7 @@
             // The top level exception is expected to be
             // the "user-friendly" query is too complex
             // rather than some linkage error.
-            JDBC.assertSQLState("42ZA0", e);
+            assertSQLState("42ZA0", e);
 			return true;
 			
 		}
@@ -298,7 +298,7 @@
             // The top level exception is expected to be
             // the "user-friendly" query is too complex
             // rather than some linkage error.
-            JDBC.assertSQLState("42ZA0", sqle);
+            assertSQLState("42ZA0", sqle);
 
 			return true;
 			
@@ -411,7 +411,7 @@
             // The top level exception is expected to be
             // the "user-friendly" query is too complex
             // rather than some linkage error.
-            JDBC.assertSQLState("42ZA0", e);
+            assertSQLState("42ZA0", e);
         }
 
         return true;

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/JDBC.java Fri Aug
25 13:26:17 2006
@@ -318,16 +318,6 @@
 		}
 		rs.close();
 	}
-    
-    /**
-     * Assert a SQL state is the expected value.
-     * @param expected Expected SQLState.
-     * @param sqle SQLException caught
-     */
-    public static void assertSQLState(String expected, SQLException sqle)
-    {
-        Assert.assertEquals("Unexpected SQL State", expected, sqle.getSQLState());
-    }
 	
 	/**
 	 * Escape a non-qualified name so that it is suitable

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
Fri Aug 25 13:26:17 2006
@@ -34,8 +34,8 @@
  */
 public class SystemPropertyTestSetup extends TestSetup {
 	
-	private final Properties newValues;
-	private final Properties oldValues;
+	private Properties newValues;
+	private Properties oldValues;
 	
 	/**
 	 * Create a test decorator that sets and restores the passed
@@ -78,6 +78,8 @@
        	}
     	// and then reset nay old values
     	setProperties(oldValues);
+        newValues = null;
+        oldValues = null;
     }
     
     private void setProperties(Properties values)
@@ -92,8 +94,12 @@
     		boolean change;
     		if (old != null)
     		{
-    			// set, might need to be changed.
-    			if (change = !old.equals(value))
+                // set, might need to be changed.
+                change = !old.equals(value);
+                
+                // If we are not processing the oldValues
+                // then store in the oldValues. Reference equality is ok here.
+    			if (change && (values != oldValues))
     			   oldValues.setProperty(key, old);
     		}
     		else {

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=436929&r1=436928&r2=436929&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Fri Aug 25 13:26:17 2006
@@ -279,56 +279,6 @@
     public boolean isVerbose() {
         return isVerbose;
     }
-    
-	/**
-	 * <p>
-	 * Return true if we expect that the DriverManager will autoload the client driver.
-	 * </p>
-	 */
-	public	boolean	autoloading()
-		throws Exception
-	{
-		//
-		// DriverManager autoloads the client only as of JDBC4.
-		//
-		if ( !JDBC.vmSupportsJDBC4() )
-		{
-			return false;
-		}
-
-		//
-		// The DriverManager will autoload drivers specified by the jdbc.drivers
-		// property. 
-		//
-		if ( getSystemStartupProperty( DRIVER_LIST ) != null )
-		{
-			return true;
-		}
-
-		//
-		// The DriverManager will also look inside our jar files for
-		// the generated file META-INF/services/java.sql.Driver. This file
-		// will contain the name of the driver to load. So if we are running
-		// this test against Derby jar files, we expect that the driver will
-		// be autoloaded.
-		//
-		// Note that if we run with a security manager, we get permissions
-		// exception at startup when the driver is autoloaded. This exception
-		// is silently swallowed and the result is that the driver is not
-		// loaded even though we expect it to be.
-		//
-		if ( loadingFromJars() )
-		{
-			return true;
-		}
-
-		//
-		// OK, we've run out of options. We do not expect that the driver
-		// will be autoloaded.
-		//
-
-		return false;
-	}
 
 	/**
 	 * <p>
@@ -390,7 +340,6 @@
     private final static String KEY_PORT = "port";
     private final static String KEY_VERBOSE = "derby.tests.debug";    
     private final static String KEY_SINGLE_LEG_XA = "derbyTesting.xa.single";
-	private final static String DRIVER_LIST = "jdbc.drivers";
 
     /**
      * Possible values of system properties.



Mime
View raw message