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 2024/12/15 19:24:34 UTC

(commons-dbcp) branch master updated (ec41eeda -> 27fc0941)

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 ec41eeda [DBCP-597] Validation query not timing out on connections managed by SharedPoolDataSource
     new 40fb3bce Better parameter name
     new 1cb710b8 KeyedCPDSConnectionFactory.validateObject(UserPassKey, PooledObject) does ignores timeouts less than 1 second when there is no validation query
     new 20bead44 Remove constructor from package private class
     new 163ce7cd Remove constructor from package private class
     new 4b3ce8f3 Remove method from package private class
     new cc5e6066 Remove method from package private class
     new 27fc0941 Removed two constructors and two methods from the package-private class CPDSConnectionFactory; this is binary compatible

The 7 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:
 src/changes/changes.xml                            |  3 +
 .../dbcp2/datasources/CPDSConnectionFactory.java   | 93 ++--------------------
 .../datasources/KeyedCPDSConnectionFactory.java    | 27 +++++--
 .../datasources/TestCPDSConnectionFactory.java     | 25 ------
 4 files changed, 27 insertions(+), 121 deletions(-)


(commons-dbcp) 04/07: Remove constructor from package private class

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 163ce7cdbb0322855ff57e8078701b0f17edf58c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:19:42 2024 -0500

    Remove constructor from package private class
    
    - This change is binary compatible since the class is package-private
    - Removed CPDSConnectionFactory(final ConnectionPoolDataSource cpds,
    final String validationQuery, inal int validationQueryTimeoutSeconds,
    final boolean rollbackAfterValidation, final String userName, final
    char[] userPassword)
---
 .../dbcp2/datasources/CPDSConnectionFactory.java   | 31 ----------------------
 1 file changed, 31 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
index 2d4e86cd..8f0fb460 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
@@ -118,37 +118,6 @@ final class CPDSConnectionFactory
         this(cpds, validationQuery, validationQueryTimeoutDuration, rollbackAfterValidation, userName, Utils.toCharArray(userPassword));
     }
 
-    /**
-     * Creates a new {@code PoolableConnectionFactory}.
-     *
-     * @param cpds
-     *            the ConnectionPoolDataSource from which to obtain PooledConnection's
-     * @param validationQuery
-     *            a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one
-     *            row. May be {@code null} in which case {@link Connection#isValid(int)} will be used to validate
-     *            connections.
-     * @param validationQueryTimeoutSeconds
-     *            Timeout in seconds before validation fails
-     * @param rollbackAfterValidation
-     *            whether a rollback should be issued after {@link #validateObject validating} {@link Connection}s.
-     * @param userName
-     *            The user name to use to create connections
-     * @param userPassword
-     *            The password to use to create connections
-     * @since 2.4.0
-     * @deprecated Use {@link #CPDSConnectionFactory(ConnectionPoolDataSource, String, Duration, boolean, String, char[])}.
-     */
-    @Deprecated
-    public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, final String validationQuery,
-            final int validationQueryTimeoutSeconds, final boolean rollbackAfterValidation, final String userName,
-        final char[] userPassword) {
-        this.cpds = cpds;
-        this.validationQuery = validationQuery;
-        this.validationQueryTimeoutDuration = Duration.ofSeconds(validationQueryTimeoutSeconds);
-        this.userPassKey = new UserPassKey(userName, userPassword);
-        this.rollbackAfterValidation = rollbackAfterValidation;
-    }
-
     @Override
     public void activateObject(final PooledObject<PooledConnectionAndInfo> p) throws SQLException {
         validateLifetime(p);


(commons-dbcp) 02/07: KeyedCPDSConnectionFactory.validateObject(UserPassKey, PooledObject) does ignores timeouts less than 1 second when there is no validation query

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 1cb710b857f06a0bed0bf25ec311448ab7539c2b
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:10:03 2024 -0500

    KeyedCPDSConnectionFactory.validateObject(UserPassKey, PooledObject)
    does ignores timeouts less than 1 second when there is no validation
    query
---
 src/changes/changes.xml                            |  1 +
 .../datasources/KeyedCPDSConnectionFactory.java    | 27 +++++++++++++++-------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 048131f7..a13fe11b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
     <release version="2.13.1" date="YYYY-MM-DD" description="This is a minor release, including bug fixes and enhancements.">
       <!-- FIX -->
       <action type="fix" issue="DBCP-597" dev="ggregory" due-to="Xiaotian Bai, Raju Gupta, Gary Gregory">Validation query not timing out on connections managed by SharedPoolDataSource.</action>
+      <action type="fix" issue="DBCP-597" dev="ggregory" due-to="Gary Gregory">KeyedCPDSConnectionFactory.validateObject(UserPassKey, PooledObject) does ignores timeouts less than 1 second when there is no validation query.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Modernize tests to use JUnit 5 features.</action> 
       <!-- ADD -->
       <!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
index f0429733..7521dcb8 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
@@ -340,14 +340,11 @@ final class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserP
         final PooledConnection pooledConn = pooledObject.getObject().getPooledConnection();
         Connection conn = null;
         validatingSet.add(pooledConn);
+        final int timeoutSeconds = toSeconds(validationQueryTimeoutDuration);
         if (validationQuery == null) {
-            Duration timeoutDuration = validationQueryTimeoutDuration;
-            if (timeoutDuration.isNegative()) {
-                timeoutDuration = Duration.ZERO;
-            }
             try {
                 conn = pooledConn.getConnection();
-                valid = conn.isValid((int) timeoutDuration.getSeconds());
+                valid = conn.isValid(timeoutSeconds);
             } catch (final SQLException e) {
                 valid = false;
             } finally {
@@ -365,9 +362,8 @@ final class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserP
             try {
                 conn = pooledConn.getConnection();
                 stmt = conn.createStatement();
-                if (!validationQueryTimeoutDuration.isNegative() && !validationQueryTimeoutDuration.isZero()) {
-                    long seconds = validationQueryTimeoutDuration.getSeconds();
-                    stmt.setQueryTimeout(seconds != 0 ? Math.toIntExact(seconds) : 1);
+                if (timeoutSeconds > 0) {
+                    stmt.setQueryTimeout(timeoutSeconds);
                 }
                 rset = stmt.executeQuery(validationQuery);
                 valid = rset.next();
@@ -385,4 +381,19 @@ final class KeyedCPDSConnectionFactory implements KeyedPooledObjectFactory<UserP
         }
         return valid;
     }
+
+    /**
+     * Converts a duration to seconds where a duration less than one second becomes 1 second.
+     *
+     * @param duration the duration to convert.
+     * @return a duration to seconds where a duration less than one second becomes 1 second.
+     * @throws ArithmeticException if the query validation timeout does not fit as seconds in an int.
+     */
+    private int toSeconds(final Duration duration) {
+        if (duration.isNegative() || duration.isZero()) {
+            return 0;
+        }
+        long seconds = validationQueryTimeoutDuration.getSeconds();
+        return seconds != 0 ? Math.toIntExact(seconds) : 1;
+    }
 }


(commons-dbcp) 06/07: Remove method from package private class

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 cc5e6066a989474950025238691f776de874f8f9
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:20:47 2024 -0500

    Remove method from package private class
    
    - This change is binary compatible since the class is package-private
    - Removed
    org.apache.commons.dbcp2.datasources.CPDSConnectionFactory.setMaxConnLifetime(Duration)
---
 .../commons/dbcp2/datasources/CPDSConnectionFactory.java   | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
index c48e8337..17414666 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
@@ -283,20 +283,6 @@ final class CPDSConnectionFactory
         this.maxConnDuration = maxConnDuration;
     }
 
-    /**
-     * Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation,
-     * passivation and validation.
-     *
-     * @param maxConnDuration
-     *            A value of zero or less indicates an infinite lifetime. The default value is -1 milliseconds.
-     * @since 2.9.0
-     * @deprecated Use {@link #setMaxConn(Duration)}.
-     */
-    @Deprecated
-    public void setMaxConnLifetime(final Duration maxConnDuration) {
-        this.maxConnDuration = maxConnDuration;
-    }
-
     /**
      * Sets the database password used when creating new connections.
      *


(commons-dbcp) 05/07: Remove method from package private class

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 4b3ce8f30aed2da792d57dc3fe34076f6dfa6022
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:20:25 2024 -0500

    Remove method from package private class
    
    - This change is binary compatible since the class is package-private
    - Removed
    org.apache.commons.dbcp2.datasources.CPDSConnectionFactory.setMaxConnLifetimeMillis(long)
---
 .../commons/dbcp2/datasources/CPDSConnectionFactory.java    | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
index 8f0fb460..c48e8337 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
@@ -297,19 +297,6 @@ final class CPDSConnectionFactory
         this.maxConnDuration = maxConnDuration;
     }
 
-    /**
-     * Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation,
-     * passivation and validation.
-     *
-     * @param maxConnLifetimeMillis
-     *            A value of zero or less indicates an infinite lifetime. The default value is -1.
-     * @deprecated Use {@link #setMaxConn(Duration)}.
-     */
-    @Deprecated
-    public void setMaxConnLifetimeMillis(final long maxConnLifetimeMillis) {
-        setMaxConnLifetime(Duration.ofMillis(maxConnLifetimeMillis));
-    }
-
     /**
      * Sets the database password used when creating new connections.
      *


(commons-dbcp) 07/07: Removed two constructors and two methods from the package-private class CPDSConnectionFactory; this is binary compatible

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 27fc0941b7dc1a0ae58904001b3155e917bc6948
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:22:16 2024 -0500

    Removed two constructors and two methods from the package-private class
    CPDSConnectionFactory; this is binary compatible
---
 src/changes/changes.xml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a13fe11b..832670e7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Modernize tests to use JUnit 5 features.</action> 
       <!-- ADD -->
       <!-- UPDATE -->
+      <!-- REMOVE -->
+      <action type="remove" dev="ggregory" due-to="Gary Gregory">Removed two constructors and two methods from the package-private class CPDSConnectionFactory; this is binary compatible.</action> 
     </release>
     <release version="2.13.0" date="2024-11-23" description="This is a minor release, including bug fixes and enhancements.">
       <!-- FIX -->


(commons-dbcp) 03/07: Remove constructor from package private class

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 20bead44d519cef031d96c894cb53332666a20c4
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 14:15:58 2024 -0500

    Remove constructor from package private class
    
    - This change is binary compatible since the class is package-private
    - Removed CPDSConnectionFactory(final ConnectionPoolDataSource cpds,
    final String validationQuery, final int validationQueryTimeoutSeconds,
                final boolean rollbackAfterValidation, final String
    userName, final String userPassword)
---
 .../dbcp2/datasources/CPDSConnectionFactory.java   | 25 ----------------------
 .../datasources/TestCPDSConnectionFactory.java     | 25 ----------------------
 2 files changed, 50 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
index faf55508..2d4e86cd 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
@@ -149,31 +149,6 @@ final class CPDSConnectionFactory
         this.rollbackAfterValidation = rollbackAfterValidation;
     }
 
-    /**
-     * Creates a new {@code PoolableConnectionFactory}.
-     *
-     * @param cpds
-     *            the ConnectionPoolDataSource from which to obtain PooledConnection's
-     * @param validationQuery
-     *            a query to use to {@link #validateObject validate} {@link Connection}s. Should return at least one
-     *            row. May be {@code null} in which case {@link Connection#isValid(int)} will be used to validate
-     *            connections.
-     * @param validationQueryTimeoutSeconds
-     *            Timeout in seconds before validation fails
-     * @param rollbackAfterValidation
-     *            whether a rollback should be issued after {@link #validateObject validating} {@link Connection}s.
-     * @param userName
-     *            The user name to use to create connections
-     * @param userPassword
-     *            The password to use to create connections
-     * @deprecated Use {@link #CPDSConnectionFactory(ConnectionPoolDataSource, String, Duration, boolean, String, String)}.
-     */
-    @Deprecated
-    public CPDSConnectionFactory(final ConnectionPoolDataSource cpds, final String validationQuery, final int validationQueryTimeoutSeconds,
-            final boolean rollbackAfterValidation, final String userName, final String userPassword) {
-        this(cpds, validationQuery, validationQueryTimeoutSeconds, rollbackAfterValidation, userName, Utils.toCharArray(userPassword));
-    }
-
     @Override
     public void activateObject(final PooledObject<PooledConnectionAndInfo> p) throws SQLException {
         validateLifetime(p);
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
index 503bab49..06e9fdff 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
@@ -129,21 +129,6 @@ public class TestCPDSConnectionFactory {
         }
     }
 
-    /**
-     * JIRA: DBCP-442
-     */
-    @Test
-    public void testNullValidationQueryDeprecated() throws Exception {
-        final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
-        try (final GenericObjectPool<PooledConnectionAndInfo> pool = new GenericObjectPool<>(factory)) {
-            factory.setPool(pool);
-            pool.setTestOnBorrow(true);
-            final PooledConnection pcon = pool.borrowObject().getPooledConnection();
-            try (final Connection con = pcon.getConnection()) {
-            }
-        }
-    }
-
     @Test
     public void testSetPasswordThenModCharArray() {
         final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, Duration.ofMillis(-1), false, "userName", "password");
@@ -154,16 +139,6 @@ public class TestCPDSConnectionFactory {
         assertEquals("a", String.valueOf(factory.getPasswordCharArray()));
     }
 
-    @Test
-    public void testSetPasswordThenModCharArrayDeprecated() {
-        final CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, null, -1, false, "userName", "password");
-        final char[] pwd = {'a'};
-        factory.setPassword(pwd);
-        assertEquals("a", String.valueOf(factory.getPasswordCharArray()));
-        pwd[0] = 'b';
-        assertEquals("a", String.valueOf(factory.getPasswordCharArray()));
-    }
-
     /**
      * JIRA DBCP-216
      *


(commons-dbcp) 01/07: Better parameter name

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 40fb3bce25e25df06a4db069fd791db747dc911c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 15 13:54:21 2024 -0500

    Better parameter name
---
 .../commons/dbcp2/datasources/CPDSConnectionFactory.java       | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
index ce0f08ce..faf55508 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
@@ -422,19 +422,19 @@ final class CPDSConnectionFactory
         return builder.toString();
     }
 
-    private void validateLifetime(final PooledObject<PooledConnectionAndInfo> p) throws SQLException {
-        Utils.validateLifetime(p, maxConnDuration);
+    private void validateLifetime(final PooledObject<PooledConnectionAndInfo> pooledObject) throws SQLException {
+        Utils.validateLifetime(pooledObject, maxConnDuration);
     }
 
     @Override
-    public boolean validateObject(final PooledObject<PooledConnectionAndInfo> p) {
+    public boolean validateObject(final PooledObject<PooledConnectionAndInfo> pooledObject) {
         try {
-            validateLifetime(p);
+            validateLifetime(pooledObject);
         } catch (final Exception e) {
             return false;
         }
         boolean valid = false;
-        final PooledConnection pconn = p.getObject().getPooledConnection();
+        final PooledConnection pconn = pooledObject.getObject().getPooledConnection();
         Connection conn = null;
         validatingSet.add(pconn);
         if (null == validationQuery) {