You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2016/06/16 11:46:03 UTC

svn commit: r1748689 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java

Author: jleroux
Date: Thu Jun 16 11:46:03 2016
New Revision: 1748689

URL: http://svn.apache.org/viewvc?rev=1748689&view=rev
Log:
Fixes "The Connection Pool Status feature in webtools is broken" - https://issues.apache.org/jira/browse/OFBIZ-7363

The Connection Pool Status feature was introduced by OFBIZ-4864 hence 1st in R13.07 where it still work well (see demo), as the connection pooling. But has been broken since, with the pooling.
Fortunately, it's easy to fix and has no implications has long has you don't enable verbose logging (the DebugManagedDataSource only extends ManagedDataSource for verbose logging and to generate the info needed for the Connection Pool Status feature).

I fixed it by using directly the DebugManagedDataSource. It's not an issue as long as you don't set the logging level to verbose which is anyway not something you would do in production. In case you do so and don't want to be disturbed in the log (focusing on something else), it's still easy to comment out the line from DebugManagedDataSource. I also fixed some type warnings while at it.

I also removed this old comment
        // Hmm... then how do we close the JDBC connections?
Because "we" don't close JDBC connections, DBPC takes care of that (or at least should, I did not check).

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1748689&r1=1748688&r2=1748689&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java Thu Jun 16 11:46:03 2016
@@ -31,7 +31,6 @@ import javax.transaction.TransactionMana
 import org.apache.commons.dbcp2.DriverConnectionFactory;
 import org.apache.commons.dbcp2.PoolableConnectionFactory;
 import org.apache.commons.dbcp2.managed.LocalXAConnectionFactory;
-import org.apache.commons.dbcp2.managed.ManagedDataSource;
 import org.apache.commons.dbcp2.managed.PoolableManagedConnectionFactory;
 import org.apache.commons.dbcp2.managed.XAConnectionFactory;
 import org.apache.commons.pool2.impl.GenericObjectPool;
@@ -54,11 +53,11 @@ import org.ofbiz.entity.transaction.Tran
 public class DBCPConnectionFactory implements ConnectionFactory {
 
     public static final String module = DBCPConnectionFactory.class.getName();
-    protected static final ConcurrentHashMap<String, ManagedDataSource> dsCache = new ConcurrentHashMap<String, ManagedDataSource>();
+    protected static final ConcurrentHashMap<String, DebugManagedDataSource> dsCache = new ConcurrentHashMap<String, DebugManagedDataSource>();
 
     public Connection getConnection(GenericHelperInfo helperInfo, JdbcElement abstractJdbc) throws SQLException, GenericEntityException {
         String cacheKey = helperInfo.getHelperFullName();
-        ManagedDataSource mds = dsCache.get(cacheKey);
+        DebugManagedDataSource mds = dsCache.get(cacheKey);
         if (mds != null) {
             return TransactionUtil.getCursorConnection(helperInfo, mds.getConnection());
         }
@@ -144,7 +143,7 @@ public class DBCPConnectionFactory imple
         GenericObjectPool pool = new GenericObjectPool(factory, poolConfig);
         factory.setPool(pool);
 
-        mds = new ManagedDataSource(pool, xacf.getTransactionRegistry());
+        mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry());
         //mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry()); // Useful to debug the usage of connections in the pool
         mds.setAccessToUnderlyingConnectionAllowed(true);
 
@@ -163,9 +162,9 @@ public class DBCPConnectionFactory imple
 
     public static Map<String, Object> getDataSourceInfo(String helperName) {
         Map<String, Object> dataSourceInfo = new HashMap<String, Object>();
-        ManagedDataSource mds = dsCache.get(helperName);
+        DebugManagedDataSource mds = dsCache.get(helperName);
         if (mds instanceof DebugManagedDataSource) {
-            dataSourceInfo = ((DebugManagedDataSource)mds).getInfo();
+            dataSourceInfo = mds.getInfo();
         }
         return dataSourceInfo;
     }