harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r548559 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/DriverManager.java test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
Date Tue, 19 Jun 2007 02:20:02 GMT
Author: tonywu
Date: Mon Jun 18 19:20:01 2007
New Revision: 548559

URL: http://svn.apache.org/viewvc?view=rev&rev=548559
Log:
Apply patch HARMONY-4205 ([classlib][sql] java.sql.DriverManager cannot deregister a driver
as many times a registering it)

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java?view=diff&rev=548559&r1=548558&r2=548559
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
Mon Jun 18 19:20:01 2007
@@ -17,6 +17,8 @@
 
 package java.sql;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -51,7 +53,7 @@
      * Set to hold Registered Drivers - initial capacity 10 drivers (will expand
      * automatically if necessary.
      */
-    private static final Set<Driver> theDriverSet = new HashSet<Driver>(10);
+    private static final List<Driver> theDrivers = new ArrayList<Driver>(10);
 
     // Permission for setting log
     private static final SQLPermission logPermission = new SQLPermission("setLog"); //$NON-NLS-1$
@@ -121,8 +123,8 @@
             // sql.1=DriverManager: calling class not authorized to deregister JDBC driver
             throw new SecurityException(Messages.getString("sql.1")); //$NON-NLS-1$
         } // end if
-        synchronized (theDriverSet) {
-            theDriverSet.remove(driver);
+        synchronized (theDrivers) {
+            theDrivers.remove(driver);
         }
     }
 
@@ -168,13 +170,13 @@
             // sql.5=The url cannot be null
             throw new SQLException(Messages.getString("sql.5"), sqlState); //$NON-NLS-1$
         }
-        synchronized (theDriverSet) {
+        synchronized (theDrivers) {
             /*
              * Loop over the drivers in the DriverSet checking to see if one can
              * open a connection to the supplied URL - return the first
              * connection which is returned
              */
-            for (Driver theDriver : theDriverSet) {
+            for (Driver theDriver : theDrivers) {
                 Connection theConnection = theDriver.connect(url, info);
                 if (theConnection != null) {
                     return theConnection;
@@ -226,13 +228,13 @@
     public static Driver getDriver(String url) throws SQLException {
         ClassLoader callerClassLoader = VM.callerClassLoader();
 
-        synchronized (theDriverSet) {
+        synchronized (theDrivers) {
             /*
              * Loop over the drivers in the DriverSet checking to see if one
              * does understand the supplied URL - return the first driver which
              * does understand the URL
              */
-            Iterator<Driver> theIterator = theDriverSet.iterator();
+            Iterator<Driver> theIterator = theDrivers.iterator();
             while (theIterator.hasNext()) {
                 Driver theDriver = theIterator.next();
                 if (theDriver.acceptsURL(url)
@@ -261,13 +263,13 @@
          * Synchronize to avoid clashes with additions and removals of drivers
          * in the DriverSet
          */
-        synchronized (theDriverSet) {
+        synchronized (theDrivers) {
             /*
              * Create the Enumeration by building a Vector from the elements of
              * the DriverSet
              */
             Vector<Driver> theVector = new Vector<Driver>();
-            Iterator<Driver> theIterator = theDriverSet.iterator();
+            Iterator<Driver> theIterator = theDrivers.iterator();
             while (theIterator.hasNext()) {
                 Driver theDriver = theIterator.next();
                 if (DriverManager.isClassFromClassLoader(theDriver,
@@ -345,8 +347,8 @@
         if (driver == null) {
             throw new NullPointerException();
         }
-        synchronized (theDriverSet) {
-            theDriverSet.add(driver);
+        synchronized (theDrivers) {
+            theDrivers.add(driver);
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java?view=diff&rev=548559&r1=548558&r2=548559
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
Mon Jun 18 19:20:01 2007
@@ -25,6 +25,7 @@
 import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
 import java.sql.SQLException;
 import java.sql.SQLPermission;
 import java.util.Enumeration;
@@ -576,7 +577,68 @@
 		} // end method checkPermission( Permission )
 
 	} // end class TestSecurityManager
+    
+    
+    /**
+     * @tests {@link java.sql.DriverManager#registerDriver(Driver)}
+     * 
+     * Registers a driver for multiple times and deregisters it only once.
+     * 
+     * Regression for
+     */
+    public void test_registerDriver_MultiTimes() throws SQLException {
+        int register_count = 10;
+        int deregister_count = 1;
+
+        Driver dummy = new DummyDriver();
+        DriverManager.registerDriver(new BadDummyDriver());
+        for (int i = 0; i < register_count; i++) {
+            DriverManager.registerDriver(dummy);
+        }
+        DriverManager.registerDriver(new BadDummyDriver());
+        for (int i = 0; i < deregister_count; i++) {
+            DriverManager.deregisterDriver(dummy);
+        }
+        Driver d = DriverManager.getDriver("jdbc:dummy_protocol:dummy_subname");
+        assertNotNull(d);
+    }
+    
+    private static class BadDummyDriver extends DummyDriver {
+        public boolean acceptsURL(String url) {
+            return false;
+        }
+    }
+
+    private static class DummyDriver implements Driver {
+
+        String goodurl = "jdbc:dummy_protocol:dummy_subname";
+
+        public boolean acceptsURL(String url) {
+            return url.equals(goodurl);
+        }
+
+        public Connection connect(String url, Properties info) {
+            return null;
+        }
+
+        public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
+            return null;
+        }
+
+        public int getMajorVersion() {
+            return 0;
+        }
 
+        public int getMinorVersion() {
+            return 0;
+        }
+
+        public boolean jdbcCompliant() {
+            return true;
+        }
+
+    }
+    
 } // end class DriverManagerTest
 
 



Mime
View raw message