You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/10/11 22:03:19 UTC

svn commit: r1021489 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema: AutoDriverDataSource.java DBCPDriverDataSource.java

Author: dwoods
Date: Mon Oct 11 20:03:18 2010
New Revision: 1021489

URL: http://svn.apache.org/viewvc?rev=1021489&view=rev
Log:
OPENJPA-1764 Minor cleanup for static variables and exception messages

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java?rev=1021489&r1=1021488&r2=1021489&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/AutoDriverDataSource.java Mon Oct 11 20:03:18 2010
@@ -51,7 +51,7 @@ public abstract class AutoDriverDataSour
         // if we're using managed transactions, or user specified a DBCP driver
         // or DBCP is not on the classpath, then use SimpleDriver
         if (conf == null || conf.isTransactionModeManaged() || conf.isConnectionFactoryModeManaged() ||
-                !isDBCPLoaded()) {
+                !isDBCPLoaded(getClassLoader())) {
             return getSimpleConnection(props);
         } else {
             // use DBCPDriverDataSource

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java?rev=1021489&r1=1021488&r2=1021489&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java Mon Oct 11 20:03:18 2010
@@ -43,10 +43,11 @@ extends SimpleDriverDataSource implement
 
     private static String DBCPPACKAGENAME = "org.apache.commons.dbcp";
     private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp.BasicDataSource";
+    private static Class<?> _dbcpClass;
+    private static Boolean _dbcpAvail;
+    private static RuntimeException _dbcpEx;
+
     protected JDBCConfiguration conf;
-    private Class<?> _dbcpClass;
-    private Boolean _dbcpAvail;
-    private RuntimeException _dbcpEx;
     private DataSource _ds;
     
     private static final Class<? extends DBCPDriverDataSource> implClass;
@@ -71,7 +72,7 @@ extends SimpleDriverDataSource implement
     public void close() throws SQLException {
         try {
             if (_ds != null) {
-                if (isDBCPLoaded()) {
+                if (isDBCPLoaded(getClassLoader())) {
                     ((org.apache.commons.dbcp.BasicDataSource)_dbcpClass.cast(_ds)).close();
                 }
             }
@@ -92,17 +93,23 @@ extends SimpleDriverDataSource implement
     }
 
     protected DataSource getDBCPDataSource(Properties props) {
-        if (isDBCPLoaded()) {
+        if (isDBCPLoaded(getClassLoader())) {
             if (_ds == null) {
-                Properties dbcpProps = updateDBCPProperties(props);
-                _ds = (DataSource) Configurations.newInstance(DBCPBASICDATASOURCENAME, conf,
-                    dbcpProps, getClassLoader());
+                try {
+                    Properties dbcpProps = updateDBCPProperties(props);
+                    _ds = (DataSource) Configurations.newInstance(DBCPBASICDATASOURCENAME, conf,
+                        dbcpProps, getClassLoader());
+                } catch (Exception e) {
+                    _dbcpEx = new RuntimeException(_eloc.get("driver-null", DBCPBASICDATASOURCENAME).getMessage(), e);
+                }
                 return _ds;
             } else {
                 return _ds;
             }
         } else {
-            // user chose DBCP, so fail if it isn't on the classpath
+            // user choose DBCP, so fail if it isn't on the classpath
+            if (_dbcpEx == null)
+                _dbcpEx = new RuntimeException(_eloc.get("driver-null", DBCPBASICDATASOURCENAME).getMessage());
             throw _dbcpEx;
         }
     }
@@ -125,7 +132,7 @@ extends SimpleDriverDataSource implement
      * based on if org.apache.commons.dbcp.BasicDataSource can be loaded.
      * @return true if Commons DBCP was found on the classpath, otherwise false
      */
-    protected boolean isDBCPLoaded() {
+    static protected boolean isDBCPLoaded(ClassLoader cl) {
         if (Boolean.TRUE.equals(_dbcpAvail) && (_dbcpClass != null)) {
             return true;
         } else if (Boolean.FALSE.equals(_dbcpAvail)) {
@@ -133,7 +140,7 @@ extends SimpleDriverDataSource implement
         } else {
             // first time checking, so try to load it
             try {
-                _dbcpClass = Class.forName(DBCPBASICDATASOURCENAME, true, getClassLoader());
+                _dbcpClass = Class.forName(DBCPBASICDATASOURCENAME, true, cl);
                 _dbcpAvail = Boolean.TRUE;
                 return true;
             } catch (Exception e) {