commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r829659 - /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
Date Sun, 25 Oct 2009 21:37:11 GMT
Author: markt
Date: Sun Oct 25 21:37:10 2009
New Revision: 829659

URL: http://svn.apache.org/viewvc?rev=829659&view=rev
Log:
Fix DBCP-203. Provide an option to specify the class loader to be used to load the JDBC driver
for a BasicDataSource.
Based on a patch suggested by Mark Grand.

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java?rev=829659&r1=829658&r2=829659&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java Sun Oct
25 21:37:10 2009
@@ -225,8 +225,40 @@
         this.restartNeeded = true;
     }
 
+    /**
+     * The class loader instance to use to load the JDBC driver. If not
+     * specified, {@link Class#forName(String)} is used to load the JDBC driver.
+     * If specified, {@link Class#forName(String, boolean, ClassLoader)} is
+     * used.
+     */
+    protected ClassLoader driverClassLoader = null;
+    
+    /**
+     * Returns the class loader specified for loading the JDBC driver. Returns
+     * <code>null</code> if no class loader has been explicitly specified.
+     */
+    public synchronized ClassLoader getDriverClassLoader() {
+        return this.driverClassLoader;
+    }
 
     /**
+     * <p>Sets the class loader to be used to load the JDBC driver.</p>
+     * <p>
+     * Note: this method currently has no effect once the pool has been
+     * initialized.  The pool is initialized the first time one of the
+     * following methods is invoked: <code>getConnection, setLogwriter,
+     * setLoginTimeout, getLoginTimeout, getLogWriter.</code></p>
+     * 
+     * @param driverClassLoader the class loader with which to load the JDBC
+     *                          driver
+     */
+    public synchronized void setDriverClassLoader(
+            ClassLoader driverClassLoader) {
+        this.driverClassLoader = driverClassLoader;
+        this.restartNeeded = true;
+    }
+    
+    /**
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or negative for no limit.
      */
@@ -1359,7 +1391,11 @@
         if (driverClassName != null) {
             try {
                 try {
-                    Class.forName(driverClassName);
+                    if (driverClassLoader == null) {
+                        Class.forName(driverClassName);
+                    } else {
+                        Class.forName(driverClassName, true, driverClassLoader);
+                    }
                 } catch (ClassNotFoundException cnfe) {
                     driverFromCCL = Thread.currentThread(
                             ).getContextClassLoader().loadClass(



Mime
View raw message