You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2009/10/25 22:37:11 UTC
svn commit: r829659 -
/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/BasicDataSource.java
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(