commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1096543 - in /commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src: changes/changes.xml java/org/apache/commons/dbcp/BasicDataSource.java test/org/apache/commons/dbcp/TestBasicDataSource.java test/org/apache/commons/dbcp/TesterClassLoader.java
Date Mon, 25 Apr 2011 17:58:19 GMT
Author: psteitz
Date: Mon Apr 25 17:58:19 2011
New Revision: 1096543

URL: http://svn.apache.org/viewvc?rev=1096543&view=rev
Log:
Backported fix for DBCP-333.  JIRA: DBCP-333.

Added:
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TesterClassLoader.java
      - copied unchanged from r1096214, commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TesterClassLoader.java
Modified:
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
    commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSource.java

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml?rev=1096543&r1=1096542&r2=1096543&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml (original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/changes/changes.xml Mon Apr 25 17:58:19
2011
@@ -50,6 +50,10 @@ The <action> type attribute can be add,u
         a statement is used, the lastUsed property of its parent connection is
         updated.
       </action>
+      <action dev="markt" issue="DBCP-333" type="fix">
+        Correctly implemented the option to configure the class loader used to load
+        the JDBC driver.
+      </action>
       <action dev="psteitz" issue="DBCP-346" type="update" due-to="Ken Tatsushita">
         LIFO configuration option has been added to BasicDataSource.  When set
         to true (the default), the pool acts as a LIFO queue; setting to false

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java?rev=1096543&r1=1096542&r2=1096543&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/java/org/apache/commons/dbcp/BasicDataSource.java
Mon Apr 25 17:58:19 2011
@@ -287,7 +287,7 @@ public class BasicDataSource implements 
      *  
      */    
     public synchronized void setLifo(boolean lifo) {
-        this.lifo = lifo;	
+        this.lifo = lifo;
         if (connectionPool != null) {
             connectionPool.setLifo(lifo);
         }
@@ -1475,8 +1475,20 @@ public class BasicDataSource implements 
     }
 
     /**
-     * Creates a JDBC connection factory for this datasource.  This method only
-     * exists so subclasses can replace the implementation class.
+     * Creates a JDBC connection factory for this datasource.  The JDBC driver
+     * is loaded using the following algorithm:
+     * <ol>
+     * <li>If {@link #driverClassName} is specified that class is loaded using
+     * the {@link ClassLoader} of this class or, if {@link #driverClassLoader}
+     * is set, {@link #driverClassName} is loaded with the specified
+     * {@link ClassLoader}.</li>
+     * <li>If {@link #driverClassName} is specified and the previous attempt
+     * fails, the class is loaded using the context class loader of the current
+     * thread.</li>
+     * <li>If a driver still isn't loaded one is loaded via the
+     * {@link DriverManager} using the specified {@link #url}.
+     * </ol>
+     * This method exists so subclasses can replace the implementation class.
      */
     protected ConnectionFactory createConnectionFactory() throws SQLException {
         // Load the JDBC driver class
@@ -1485,9 +1497,10 @@ public class BasicDataSource implements 
             try {
                 try {
                     if (driverClassLoader == null) {
-                        Class.forName(driverClassName);
+                        driverFromCCL = Class.forName(driverClassName);
                     } else {
-                        Class.forName(driverClassName, true, driverClassLoader);
+                        driverFromCCL = Class.forName(
+                                driverClassName, true, driverClassLoader);
                     }
                 } catch (ClassNotFoundException cnfe) {
                     driverFromCCL = Thread.currentThread(

Modified: commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSource.java?rev=1096543&r1=1096542&r2=1096543&view=diff
==============================================================================
--- commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
(original)
+++ commons/proper/dbcp/branches/DBCP_1_4_x_BRANCH/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
Mon Apr 25 17:58:19 2011
@@ -62,6 +62,7 @@ public class TestBasicDataSource extends
         ds.setPassword("password");
         ds.setValidationQuery("SELECT DUMMY FROM DUAL");
         ds.setConnectionInitSqls(Arrays.asList(new String[] { "SELECT 1", "SELECT 2"}));
+        ds.setDriverClassLoader(new TesterClassLoader());
     }
 
     protected BasicDataSource createDataSource() throws Exception {
@@ -500,4 +501,16 @@ public class TestBasicDataSource extends
         // Allow one extra thread for JRockit compatibility
         assertTrue(Thread.activeCount() <= threadCount + 1);
     }
+    
+    /**
+     * JIRA DBCP-333: Check that a custom class loader is used.
+     * @throws Exception 
+     */
+    public void testDriverClassLoader() throws Exception {
+        getConnection();
+        ClassLoader cl = ds.getDriverClassLoader();
+        assertNotNull(cl);
+        assertTrue(cl instanceof TesterClassLoader);
+        assertTrue(((TesterClassLoader) cl).didLoad(ds.getDriverClassName()));
+    }
 }



Mime
View raw message