commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject commons-dbcp git commit: Fix DBCP-458
Date Thu, 03 Nov 2016 09:10:15 GMT
Repository: commons-dbcp
Updated Branches:
  refs/heads/master 861879edc -> 6641cc08d


Fix DBCP-458

Make it simpler to extend BasicDataSource to allow sub-classes to
provide custom GenericObjectPool implementations.

Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/6641cc08
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/6641cc08
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/6641cc08

Branch: refs/heads/master
Commit: 6641cc08d9568fcd6a291cab8cb0a7c4860e43b6
Parents: 861879e
Author: Mark Thomas <markt@apache.org>
Authored: Thu Nov 3 09:08:41 2016 +0000
Committer: Mark Thomas <markt@apache.org>
Committed: Thu Nov 3 09:08:41 2016 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                         |  4 +++
 .../apache/commons/dbcp2/BasicDataSource.java   | 33 ++++++++++++++------
 2 files changed, 28 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/6641cc08/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 538819d..c1b5d68 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -118,6 +118,10 @@ The <action> type attribute can be add,update,fix,remove.
          thread is interrupted during a call to
          PoolingDataSource.getConnection().
        </action>
+       <action dev="markt" type="add" issue="DBCP-458" due-to="Adrian Tarau">
+         Make it simpler to extend BasicDataSource to allow sub-classes to
+         provide custom GenericObjectPool implementations.
+       </action>
     </release>
     <release version="2.1.1" date="6 Aug 2015" description=
 "This is a patch release, including bug fixes only.">

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/6641cc08/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 2d6fcad..250dfd9 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -2190,15 +2190,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean,
MBean
         final GenericObjectPoolConfig config = new GenericObjectPoolConfig();
         updateJmxName(config);
         config.setJmxEnabled(registeredJmxName != null);  // Disable JMX on the underlying
pool if the DS is not registered.
-        GenericObjectPool<PoolableConnection> gop;
-        if (abandonedConfig != null &&
-                (abandonedConfig.getRemoveAbandonedOnBorrow() ||
-                 abandonedConfig.getRemoveAbandonedOnMaintenance())) {
-            gop = new GenericObjectPool<>(factory, config, abandonedConfig);
-        }
-        else {
-            gop = new GenericObjectPool<>(factory, config);
-        }
+        GenericObjectPool<PoolableConnection> gop = createObjectPool(factory, config,
abandonedConfig);
         gop.setMaxTotal(maxTotal);
         gop.setMaxIdle(maxIdle);
         gop.setMinIdle(minIdle);
@@ -2218,6 +2210,29 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean,
MBean
     }
 
     /**
+     * Creates an object pool used to provide pooling support for {@link Connection JDBC
connections}.
+     *
+     * @param factory         the object factory
+     * @param poolConfig      the object pool configuration
+     * @param abandonedConfig the abandoned objects configuration
+     * @return a non-null instance
+     */
+    protected  GenericObjectPool<PoolableConnection> createObjectPool(
+            final PoolableConnectionFactory factory, final GenericObjectPoolConfig poolConfig,
+            final AbandonedConfig abandonedConfig) {
+        GenericObjectPool<PoolableConnection> gop;
+        if (abandonedConfig != null &&
+                (abandonedConfig.getRemoveAbandonedOnBorrow() ||
+                        abandonedConfig.getRemoveAbandonedOnMaintenance())) {
+            gop = new GenericObjectPool<>(factory, poolConfig, abandonedConfig);
+        }
+        else {
+            gop = new GenericObjectPool<>(factory, poolConfig);
+        }
+        return gop;
+    }
+
+    /**
      * Closes the connection pool, silently swallowing any exception that occurs.
      */
     private void closeConnectionPool() {


Mime
View raw message