db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lily...@apache.org
Subject svn commit: r1068842 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/jdbc/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/maste...
Date Wed, 09 Feb 2011 11:03:36 GMT
Author: lilywei
Date: Wed Feb  9 11:03:36 2011
New Revision: 1068842

URL: http://svn.apache.org/viewvc?rev=1068842&view=rev
Log:
DERBY-2905 Check-in deregister attribute option with shutdown. After shutdown and reloading
the engine via Class.forName(...).newInstance(), AutoloadedDriver will get registered to DriverManager
even if AutoloadedDriver40 was the original driver.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/GetPropertyInfoTest.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Attribute.java Wed Feb
 9 11:03:36 2011
@@ -158,6 +158,11 @@ public interface Attribute {
 	*/
 	String SHUTDOWN_ATTR = "shutdown";
 
+    /**
+     * The attribute that is to keep autoloading idiom for driver
+     */
+    String DEREGISTER_ATTR = "deregister";
+
 	/**
 		The attribute that is used to request a database create.
 	*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java Wed Feb  9
11:03:36 2011
@@ -60,12 +60,13 @@ public class AutoloadedDriver implements
 	// This flag is set if the engine is forcibly brought down.
 	private	static	boolean	_engineForcedDown = false;
 	
-    // This flag is set if AutoloadedDriver exists
-    private static boolean activeautoloadeddriver = false;
 
     //This is the driver that memorizes the autoloadeddriver (DERBY-2905)
     private static Driver _autoloadedDriver;
 
+    //This flag is set is deregister attribute is set by user, 
+    //default is true (DERBY-2905)
+    private static boolean deregister = true;
 	//
 	// This is the driver that's specific to the JDBC level we're running at.
 	// It's the module which boots the whole Derby engine.
@@ -93,7 +94,6 @@ public class AutoloadedDriver implements
 		try {
             _autoloadedDriver = me;
             DriverManager.registerDriver( _autoloadedDriver );
-            activeautoloadeddriver = true;
 		}
 		catch (SQLException se)
 		{
@@ -227,8 +227,10 @@ public class AutoloadedDriver implements
 		_engineForcedDown = false;
 		
         try {
-            if (!activeautoloadeddriver)
-                DriverManager.registerDriver(_driverModule);
+            if (_autoloadedDriver == null) {
+                _autoloadedDriver = new AutoloadedDriver();
+                DriverManager.registerDriver(_autoloadedDriver);
+            }
         } catch (SQLException e) {
             if (SanityManager.DEBUG)
                 SanityManager.THROWASSERT(e);
@@ -244,9 +246,9 @@ public class AutoloadedDriver implements
 	{
 		_engineForcedDown = true;
         try {
-            if (activeautoloadeddriver) {
+            // deregister is false if user set deregister=false attribute (DERBY-2905)
+            if (deregister && _autoloadedDriver != null) {
                 DriverManager.deregisterDriver(_autoloadedDriver);
-                activeautoloadeddriver = false;
                 _autoloadedDriver = null;
             } else {
                 DriverManager.deregisterDriver(_driverModule);
@@ -267,5 +269,19 @@ public class AutoloadedDriver implements
 		return ( _driverModule != null );
 	}
 	
+    /**
+     * @param theValue set the deregister value
+     */
+    public static void setDeregister(boolean theValue) {
+        AutoloadedDriver.deregister = theValue;
+    }
+
+    /**
+     * @return the deregister value
+     */
+    public static boolean getDeregister() {
+        return deregister;
+    }
+
 }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/Driver20.java Wed Feb  9 11:03:36
2011
@@ -159,6 +159,7 @@ public abstract class Driver20 extends I
 
 			String[][] connBooleanAttributes = {
 				{Attribute.SHUTDOWN_ATTR, MessageId.CONN_SHUT_DOWN_CLOUDSCAPE},
+                {Attribute.DEREGISTER_ATTR, MessageId.CONN_DEREGISTER_AUTOLOADEDDRIVER},
 				{Attribute.CREATE_ATTR, MessageId.CONN_CREATE_DATABASE},
 				{Attribute.DATA_ENCRYPTION, MessageId.CONN_DATA_ENCRYPTION},
 				{Attribute.UPGRADE_ATTR, MessageId.CONN_UPGRADE_DATABASE},

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java Wed Feb  9 11:03:36
2011
@@ -223,6 +223,15 @@ public abstract class InternalDriver imp
                                     getTextMessage(MessageId.AUTH_INVALID));
 					}
 
+                    // DERBY-2905, allow users to provide deregister attribute to 
+                    // left AutoloadedDriver in DriverManager, default value is true
+                    if (finfo.getProperty(Attribute.DEREGISTER_ATTR) != null) {
+                        boolean deregister = Boolean.valueOf(
+                                finfo.getProperty(Attribute.DEREGISTER_ATTR))
+                                .booleanValue();
+                        AutoloadedDriver.setDeregister(deregister);
+                    }
+
 					// check for shutdown privileges
 					// DERBY-3495: uncomment to enable system privileges checks
 					//final String user = IdUtil.getUserNameFromURLProps(finfo);
@@ -383,6 +392,7 @@ public abstract class InternalDriver imp
 		checkBoolean(finfo, Attribute.DATA_ENCRYPTION);
 		checkBoolean(finfo, Attribute.CREATE_ATTR);
 		checkBoolean(finfo, Attribute.SHUTDOWN_ATTR);
+        checkBoolean(finfo, Attribute.DEREGISTER_ATTR);
 		checkBoolean(finfo, Attribute.UPGRADE_ATTR);
 
 		return finfo;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Wed Feb  9 11:03:36
2011
@@ -7655,6 +7655,11 @@ Shutting down instance {0} on database d
             </msg>
 
             <msg>
+	        <name>J006</name>
+		<text>deregister AutoloadedDriver</text>
+            </msg>
+
+            <msg>
                 <name>J007</name>
                 <text>create database</text>
             </msg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
Wed Feb  9 11:03:36 2011
@@ -114,6 +114,7 @@ public interface MessageId {
 	String CONN_SHUT_DOWN_ENGINE		    = "J003"; // shutting down Derby Engine
 	String CONN_DATABASE_IDENTITY			= "J004"; // database identity
 	String CONN_SHUT_DOWN_CLOUDSCAPE		= "J005"; // shut down Derby
+    String CONN_DEREGISTER_AUTOLOADEDDRIVER = "J006"; // remove registered AutoloadedDriver
 	String CONN_CREATE_DATABASE				= "J007"; // create database
 	String CONN_NO_DETAILS					= "J008"; // no details
     String CONN_DATA_ENCRYPTION             = "J010"; // encrypt database on disk

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/GetPropertyInfoTest.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/GetPropertyInfoTest.out?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/GetPropertyInfoTest.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/GetPropertyInfoTest.out
Wed Feb  9 11:03:36 2011
@@ -14,6 +14,7 @@ restoreFrom - value: null - description:
 bootPassword - value:  - description: secret cryptographic key - required false - choices
null 
 password - value:  - description: user password - required false - choices null 
 shutdown - value: false - description: shut down Derby - required false     - choices [0]
: false     - choices [1] : true
+deregister - value: false - description: deregister AutoloadedDriver - required false   
 - choices [0] : false     - choices [1] : true
 create - value: true - description: create database - required false     - choices [0] :
false     - choices [1] : true
 dataEncryption - value: true - description: encrypt database on disk - required false   
 - choices [0] : false     - choices [1] : true
 upgrade - value: false - description: upgrade database - required false     - choices [0]
: false     - choices [1] : true
@@ -32,6 +33,7 @@ restoreFrom - value: null - description:
 bootPassword - value: **** - description: secret cryptographic key - required false - choices
null 
 password - value:  - description: user password - required false - choices null 
 shutdown - value: false - description: shut down Derby - required false     - choices [0]
: false     - choices [1] : true
+deregister - value: false - description: deregister AutoloadedDriver - required false   
 - choices [0] : false     - choices [1] : true
 create - value: true - description: create database - required false     - choices [0] :
false     - choices [1] : true
 dataEncryption - value: true - description: encrypt database on disk - required false   
 - choices [0] : false     - choices [1] : true
 upgrade - value: false - description: upgrade database - required false     - choices [0]
: false     - choices [1] : true

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java?rev=1068842&r1=1068841&r2=1068842&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoloadTest.java
Wed Feb  9 11:03:36 2011
@@ -25,6 +25,8 @@ import java.sql.Driver;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.sql.Statement;
+
 import javax.sql.DataSource;
 import java.util.Enumeration;
 
@@ -123,6 +125,7 @@ public class AutoloadTest extends BaseJD
                 // left registered in the driver manager
                 // and that after a shutdown, an explicit load
                 // can restart the engine.
+                suite.addTest(new AutoloadTest("testAssertShutdownOK"));
                 suite.addTest(new AutoloadTest("testShutdownDeRegister"));
                 suite.addTest(new AutoloadTest("testExplicitReload"));
             }
@@ -182,8 +185,8 @@ public class AutoloadTest extends BaseJD
 	// ///////////////////////////////////////////////////////////
 
     /**
-     * Test DERBY-2905:Shutting down embedded Derby does not remove all code,
-     * the AutoloadDriver is left registered in the DriverManager.
+     * Test DERBY-2905:Shutting down embedded Derby does remove all code,
+     * the AutoloadDriver is dergistered from DriverManager.
      * 
      * @throws Exception
      */
@@ -214,15 +217,21 @@ public class AutoloadTest extends BaseJD
             String driverClass = getTestConfiguration().getJDBCClient()
                     .getJDBCDriverName();
 
+            //Derby should be able to get a connection if AutoloaderDriver is
+            //not in DriverManager. Make a connection to test it. Derby-2905
             Class.forName(driverClass).newInstance();
             url = getTestConfiguration().getJDBCUrl();
             user = getTestConfiguration().getUserName();
             password = getTestConfiguration().getUserPassword();
             DriverManager.getConnection(url, user, password);
+            //newInstance is gettin AutoloadedDriver
+            AutoloadedDriver = "org.apache.derby.jdbc.AutoloadedDriver";
+            assertTrue(getRegisteredDrivers(AutoloadedDriver));
 
             // shut down engine
             TestConfiguration.getCurrent().shutdownEngine();
 
+            assertFalse(getRegisteredDrivers(AutoloadedDriver));
             assertFalse(getRegisteredDrivers(Driver40));
             assertFalse(getRegisteredDrivers(Driver30));
             assertFalse(getRegisteredDrivers(Driver20));
@@ -471,8 +480,8 @@ public class AutoloadTest extends BaseJD
 	return false;
     }
 
-    private void assertShutdownOK() throws SQLException {
-
+    public void testAssertShutdownOK() throws SQLException {
+        String AutoloadedDriver = getAutoloadedDriverName();
         Connection conn = getConnection();
 
         if (usingEmbedded()) {
@@ -488,7 +497,20 @@ public class AutoloadTest extends BaseJD
             assertTrue(conn.isClosed());
         } else if (usingDerbyNetClient()) {
             DataSource ds = JDBCDataSource.getDataSource();
-            JDBCDataSource.setBeanProperty(ds, "connectionAttributes","shutdown=true");
+            //Case 1: Test the deregister attribute error
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                    "shutdown=true;deregiste=false");
+            try {
+                ds.getConnection();
+                fail("expected shutdown to fail");
+            } catch (SQLException e) {
+                // expect 08006 on successful shutdown
+                assertSQLState("08006", e);
+            }
+            //Case 2: Test with deregister=false, AutoloadedDriver should
+            //still be in DriverManager
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                    "shutdown=tru e;deregister=false");
             try {
                 ds.getConnection();
                 fail("expected shutdown to fail");
@@ -496,6 +518,26 @@ public class AutoloadTest extends BaseJD
                 // expect 08006 on successful shutdown
                 assertSQLState("08006", e);
             }
+            //DERBY-2905 deregister=false should keep AutoloadedDriver in
+            //DriverManager
+            assertTrue(getRegisteredDrivers(AutoloadedDriver));
+            //Test getting a connection just right after the shutdown.
+            String url = getTestConfiguration().getJDBCUrl();
+            conn = DriverManager.getConnection(url);
+            Statement stmt = conn.createStatement();
+            stmt.executeUpdate("values 1");
+            JDBCDataSource.setBeanProperty(ds, "connectonAttributes",
+                    "shutdown=true;deregister=true");
+            try {
+                ds.getConnection();
+                fail("expected shutdown to fail");
+            } catch (SQLException e) {
+                // expect 08006 on successful shutdown
+                assertSQLState("08006", e);
+            }
+            //DERBY-2905 deregister=true should deregister AutoloadedDriver in
+            //DriverManager
+            assertFalse(getRegisteredDrivers(AutoloadedDriver));
         }
     }
 



Mime
View raw message