You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/03 12:40:53 UTC

[commons-dbcp] branch master updated (67d2c666 -> c56a6a49)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git


    from 67d2c666 Replace Exception with SQLException in some method signatures (preserves binary compatibility, not source).
     new 344234a7 Refactor duplicate pattern
     new fac1a917 Refactor duplicate pattern
     new ad18ca91 Call addObjects(int) instead of looping over addObject()
     new c56a6a49 Bump maven-surefire-plugin 2.22.2 to 3.0.0-M7

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |   1 +
 src/changes/changes.xml                            |   3 +
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 139 ++++++---------------
 3 files changed, 43 insertions(+), 100 deletions(-)


[commons-dbcp] 01/04: Refactor duplicate pattern

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit 344234a758da62aa422f6f67c6e7b1f37329c9c0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 3 07:53:52 2022 -0400

    Refactor duplicate pattern
---
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 73 ++++++----------------
 1 file changed, 18 insertions(+), 55 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 3763d1d1..5aad39d7 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -36,6 +36,7 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Properties;
 import java.util.Set;
+import java.util.function.BiConsumer;
 import java.util.logging.Logger;
 
 import javax.management.MBeanRegistration;
@@ -1711,22 +1712,26 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         start();
     }
 
-    /**
-     * Sets the print writer to be used by this configuration to log information on abandoned objects.
-     *
-     * @param logWriter The new log writer
-     */
-    public void setAbandonedLogWriter(final PrintWriter logWriter) {
+    private <T> void setAbandoned(final T object, BiConsumer<AbandonedConfig, T> consumer) {
         if (abandonedConfig == null) {
             abandonedConfig = new AbandonedConfig();
         }
-        abandonedConfig.setLogWriter(logWriter);
+        consumer.accept(abandonedConfig, object);
         final GenericObjectPool<?> gop = this.connectionPool;
         if (gop != null) {
             gop.setAbandonedConfig(abandonedConfig);
         }
     }
 
+    /**
+     * Sets the print writer to be used by this configuration to log information on abandoned objects.
+     *
+     * @param logWriter The new log writer
+     */
+    public void setAbandonedLogWriter(final PrintWriter logWriter) {
+        setAbandoned(logWriter, AbandonedConfig::setLogWriter);
+    }
+
     /**
      * If the connection pool implements {@link org.apache.commons.pool2.UsageTracking UsageTracking}, configure whether
      * the connection pool should record a stack trace every time a method is called on a pooled connection and retain
@@ -1736,14 +1741,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      *                      pooled connection
      */
     public void setAbandonedUsageTracking(final boolean usageTracking) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setUseUsageTracking(usageTracking);
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(usageTracking, AbandonedConfig::setUseUsageTracking);
     }
 
     /**
@@ -2125,14 +2123,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @param logAbandoned new logAbandoned property value
      */
     public void setLogAbandoned(final boolean logAbandoned) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setLogAbandoned(logAbandoned);
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(logAbandoned, AbandonedConfig::setLogAbandoned);
     }
 
     /**
@@ -2373,14 +2364,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @see #getRemoveAbandonedOnBorrow()
      */
     public void setRemoveAbandonedOnBorrow(final boolean removeAbandonedOnBorrow) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setRemoveAbandonedOnBorrow(removeAbandonedOnBorrow);
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(removeAbandonedOnBorrow, AbandonedConfig::setRemoveAbandonedOnBorrow);
     }
 
     /**
@@ -2388,14 +2372,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @see #getRemoveAbandonedOnMaintenance()
      */
     public void setRemoveAbandonedOnMaintenance(final boolean removeAbandonedOnMaintenance) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setRemoveAbandonedOnMaintenance(removeAbandonedOnMaintenance);
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(removeAbandonedOnMaintenance, AbandonedConfig::setRemoveAbandonedOnMaintenance);
     }
 
     /**
@@ -2412,14 +2389,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @since 2.10.0
      */
     public void setRemoveAbandonedTimeout(final Duration removeAbandonedTimeout) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setRemoveAbandonedTimeout(removeAbandonedTimeout);
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(removeAbandonedTimeout, AbandonedConfig::setRemoveAbandonedTimeout);
     }
 
     /**
@@ -2437,14 +2407,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     @Deprecated
     public void setRemoveAbandonedTimeout(final int removeAbandonedTimeout) {
-        if (abandonedConfig == null) {
-            abandonedConfig = new AbandonedConfig();
-        }
-        abandonedConfig.setRemoveAbandonedTimeout(Duration.ofSeconds(removeAbandonedTimeout));
-        final GenericObjectPool<?> gop = this.connectionPool;
-        if (gop != null) {
-            gop.setAbandonedConfig(abandonedConfig);
-        }
+        setAbandoned(Duration.ofSeconds(removeAbandonedTimeout), AbandonedConfig::setRemoveAbandonedTimeout);
     }
 
     /**


[commons-dbcp] 02/04: Refactor duplicate pattern

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit fac1a9174d99ddd51b043fed190dae20bb5573d1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 3 08:10:16 2022 -0400

    Refactor duplicate pattern
---
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 78 ++++++++--------------
 1 file changed, 28 insertions(+), 50 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 5aad39d7..ef359318 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -1712,7 +1712,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         start();
     }
 
-    private <T> void setAbandoned(final T object, BiConsumer<AbandonedConfig, T> consumer) {
+    private <T> void setAbandoned(BiConsumer<AbandonedConfig, T> consumer, final T object) {
         if (abandonedConfig == null) {
             abandonedConfig = new AbandonedConfig();
         }
@@ -1723,13 +1723,19 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
+    private <T> void setConnectionPool(BiConsumer<GenericObjectPool<PoolableConnection>, T> consumer, final T object) {
+        if (connectionPool != null) {
+            consumer.accept(connectionPool, object);
+        }
+    }
+    
     /**
      * Sets the print writer to be used by this configuration to log information on abandoned objects.
      *
      * @param logWriter The new log writer
      */
     public void setAbandonedLogWriter(final PrintWriter logWriter) {
-        setAbandoned(logWriter, AbandonedConfig::setLogWriter);
+        setAbandoned(AbandonedConfig::setLogWriter, logWriter);
     }
 
     /**
@@ -1741,7 +1747,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      *                      pooled connection
      */
     public void setAbandonedUsageTracking(final boolean usageTracking) {
-        setAbandoned(usageTracking, AbandonedConfig::setUseUsageTracking);
+        setAbandoned(AbandonedConfig::setUseUsageTracking, usageTracking);
     }
 
     /**
@@ -2056,9 +2062,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @param evictionPolicyClassName The fully qualified class name of the EvictionPolicy implementation
      */
     public synchronized void setEvictionPolicyClassName(final String evictionPolicyClassName) {
-        if (connectionPool != null) {
-            connectionPool.setEvictionPolicyClassName(evictionPolicyClassName);
-        }
+        setConnectionPool(GenericObjectPool::setEvictionPolicyClassName, evictionPolicyClassName);
         this.evictionPolicyClassName = evictionPolicyClassName;
     }
 
@@ -2114,16 +2118,14 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setLifo(final boolean lifo) {
         this.lifo = lifo;
-        if (connectionPool != null) {
-            connectionPool.setLifo(lifo);
-        }
+        setConnectionPool(GenericObjectPool::setLifo, lifo);
     }
 
     /**
      * @param logAbandoned new logAbandoned property value
      */
     public void setLogAbandoned(final boolean logAbandoned) {
-        setAbandoned(logAbandoned, AbandonedConfig::setLogAbandoned);
+        setAbandoned(AbandonedConfig::setLogAbandoned, logAbandoned);
     }
 
     /**
@@ -2217,9 +2219,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setMaxIdle(final int maxIdle) {
         this.maxIdle = maxIdle;
-        if (connectionPool != null) {
-            connectionPool.setMaxIdle(maxIdle);
-        }
+        setConnectionPool(GenericObjectPool::setMaxIdle, maxIdle);
     }
 
     /**
@@ -2245,9 +2245,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setMaxTotal(final int maxTotal) {
         this.maxTotal = maxTotal;
-        if (connectionPool != null) {
-            connectionPool.setMaxTotal(maxTotal);
-        }
+        setConnectionPool(GenericObjectPool::setMaxTotal, maxTotal);
     }
 
     /**
@@ -2259,9 +2257,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setMaxWait(final Duration maxWaitDuration) {
         this.maxWaitDuration = maxWaitDuration;
-        if (connectionPool != null) {
-            connectionPool.setMaxWait(maxWaitDuration);
-        }
+        setConnectionPool(GenericObjectPool::setMaxWait, maxWaitDuration);
     }
 
     /**
@@ -2285,9 +2281,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setMinEvictableIdle(final Duration minEvictableIdleDuration) {
         this.minEvictableIdleDuration = minEvictableIdleDuration;
-        if (connectionPool != null) {
-            connectionPool.setMinEvictableIdle(minEvictableIdleDuration);
-        }
+        setConnectionPool(GenericObjectPool::setMinEvictableIdle, minEvictableIdleDuration);
     }
 
     /**
@@ -2312,9 +2306,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setMinIdle(final int minIdle) {
         this.minIdle = minIdle;
-        if (connectionPool != null) {
-            connectionPool.setMinIdle(minIdle);
-        }
+        setConnectionPool(GenericObjectPool::setMinIdle, minIdle);
     }
 
     /**
@@ -2325,9 +2317,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
         this.numTestsPerEvictionRun = numTestsPerEvictionRun;
-        if (connectionPool != null) {
-            connectionPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        }
+        setConnectionPool(GenericObjectPool::setNumTestsPerEvictionRun, numTestsPerEvictionRun);
     }
 
     /**
@@ -2364,7 +2354,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @see #getRemoveAbandonedOnBorrow()
      */
     public void setRemoveAbandonedOnBorrow(final boolean removeAbandonedOnBorrow) {
-        setAbandoned(removeAbandonedOnBorrow, AbandonedConfig::setRemoveAbandonedOnBorrow);
+        setAbandoned(AbandonedConfig::setRemoveAbandonedOnBorrow, removeAbandonedOnBorrow);
     }
 
     /**
@@ -2372,7 +2362,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @see #getRemoveAbandonedOnMaintenance()
      */
     public void setRemoveAbandonedOnMaintenance(final boolean removeAbandonedOnMaintenance) {
-        setAbandoned(removeAbandonedOnMaintenance, AbandonedConfig::setRemoveAbandonedOnMaintenance);
+        setAbandoned(AbandonedConfig::setRemoveAbandonedOnMaintenance, removeAbandonedOnMaintenance);
     }
 
     /**
@@ -2389,7 +2379,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @since 2.10.0
      */
     public void setRemoveAbandonedTimeout(final Duration removeAbandonedTimeout) {
-        setAbandoned(removeAbandonedTimeout, AbandonedConfig::setRemoveAbandonedTimeout);
+        setAbandoned(AbandonedConfig::setRemoveAbandonedTimeout, removeAbandonedTimeout);
     }
 
     /**
@@ -2407,7 +2397,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     @Deprecated
     public void setRemoveAbandonedTimeout(final int removeAbandonedTimeout) {
-        setAbandoned(Duration.ofSeconds(removeAbandonedTimeout), AbandonedConfig::setRemoveAbandonedTimeout);
+        setAbandoned(AbandonedConfig::setRemoveAbandonedTimeout, Duration.ofSeconds(removeAbandonedTimeout));
     }
 
     /**
@@ -2432,9 +2422,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setSoftMinEvictableIdle(final Duration softMinEvictableIdleTimeMillis) {
         this.softMinEvictableIdleDuration = softMinEvictableIdleTimeMillis;
-        if (connectionPool != null) {
-            connectionPool.setSoftMinEvictableIdle(softMinEvictableIdleTimeMillis);
-        }
+        setConnectionPool(GenericObjectPool::setSoftMinEvictableIdle, softMinEvictableIdleTimeMillis);
     }
 
     /**
@@ -2460,9 +2448,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setTestOnBorrow(final boolean testOnBorrow) {
         this.testOnBorrow = testOnBorrow;
-        if (connectionPool != null) {
-            connectionPool.setTestOnBorrow(testOnBorrow);
-        }
+        setConnectionPool(GenericObjectPool::setTestOnBorrow, testOnBorrow);
     }
 
     /**
@@ -2473,9 +2459,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setTestOnCreate(final boolean testOnCreate) {
         this.testOnCreate = testOnCreate;
-        if (connectionPool != null) {
-            connectionPool.setTestOnCreate(testOnCreate);
-        }
+        setConnectionPool(GenericObjectPool::setTestOnCreate, testOnCreate);
     }
 
     /**
@@ -2486,9 +2470,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setTestOnReturn(final boolean testOnReturn) {
         this.testOnReturn = testOnReturn;
-        if (connectionPool != null) {
-            connectionPool.setTestOnReturn(testOnReturn);
-        }
+        setConnectionPool(GenericObjectPool::setTestOnReturn, testOnReturn);
     }
 
     /**
@@ -2499,9 +2481,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setTestWhileIdle(final boolean testWhileIdle) {
         this.testWhileIdle = testWhileIdle;
-        if (connectionPool != null) {
-            connectionPool.setTestWhileIdle(testWhileIdle);
-        }
+        setConnectionPool(GenericObjectPool::setTestWhileIdle, testWhileIdle);
     }
 
     /**
@@ -2513,9 +2493,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     public synchronized void setDurationBetweenEvictionRuns(final Duration timeBetweenEvictionRunsMillis) {
         this.durationBetweenEvictionRuns = timeBetweenEvictionRunsMillis;
-        if (connectionPool != null) {
-            connectionPool.setTimeBetweenEvictionRuns(timeBetweenEvictionRunsMillis);
-        }
+        setConnectionPool(GenericObjectPool::setTimeBetweenEvictionRuns, timeBetweenEvictionRunsMillis);
     }
 
     /**


[commons-dbcp] 03/04: Call addObjects(int) instead of looping over addObject()

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit ad18ca916f227b13b92f73108566cb7a01450633
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 3 08:33:55 2022 -0400

    Call addObjects(int) instead of looping over addObject()
---
 src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index ef359318..5ab69d4c 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -567,9 +567,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
 
             // If initialSize > 0, preload the pool
             try {
-                for (int i = 0; i < initialSize; i++) {
-                    connectionPool.addObject();
-                }
+                connectionPool.addObjects(initialSize);
             } catch (final Exception e) {
                 closeConnectionPool();
                 throw new SQLException("Error preloading the connection pool", e);


[commons-dbcp] 04/04: Bump maven-surefire-plugin 2.22.2 to 3.0.0-M7

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit c56a6a4965747f03735969e06f8fc3947b7c1dac
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jul 3 08:40:46 2022 -0400

    Bump maven-surefire-plugin 2.22.2 to 3.0.0-M7
---
 pom.xml                 | 1 +
 src/changes/changes.xml | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/pom.xml b/pom.xml
index 0bf6eac2..cfc76102 100644
--- a/pom.xml
+++ b/pom.xml
@@ -323,6 +323,7 @@
     <commons.jira.id>DBCP</commons.jira.id>
     <commons.jira.pid>12310469</commons.jira.pid>
     <!-- Override CP version until that is updated -->
+    <commons.surefire.version>3.0.0-M7</commons.surefire.version>
     <commons.checkstyle-plugin.version>3.1.2</commons.checkstyle-plugin.version>
     <commons.checkstyle.version>9.3</commons.checkstyle.version>
     <commons.javadoc.version>3.4.0</commons.javadoc.version>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f7c7627f..117256bf 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -166,6 +166,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" due-to="Gary Gregory">
         Bump JaCoCo from 0.8.7 to 0.8.8.
       </action>
+      <action dev="ggregory" type="update" due-to="Gary Gregory">
+        Bump maven-surefire-plugin 2.22.2 to 3.0.0-M7.
+      </action>
     </release>
     <release version="2.9.0" date="2021-07-30" description="This is a minor release, including bug fixes and enhancements.">
       <!-- ADD -->