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 2ce98fcbdf8d3fb6ecd7b6a01ddf04feef22d08a
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Feb 29 09:40:49 2024 -0500

    Refactor common code
    
    Add @SuppressWarnings
---
 .../dbcp2/cpdsadapter/DriverAdapterCPDS.java       | 45 +++++++++++-----------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java 
b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
index 5d97bf39..481acaf3 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
@@ -404,33 +404,19 @@ public class DriverAdapterCPDS implements 
ConnectionPoolDataSource, Referenceabl
      * @param pooledUserPassword password to be used fur the connection
      */
     @Override
-    public PooledConnection getPooledConnection(final String pooledUserName, 
final String pooledUserPassword)
-        throws SQLException {
+    public PooledConnection getPooledConnection(final String pooledUserName, 
final String pooledUserPassword) throws SQLException {
         getConnectionCalled = true;
+        if (connectionProperties != null) {
+            update(connectionProperties, Constants.KEY_USER, pooledUserName);
+            update(connectionProperties, Constants.KEY_PASSWORD, 
pooledUserPassword);
+        }
+        // Workaround for buggy WebLogic 5.1 class loader - ignore 
ClassCircularityError upon first invocation.
         PooledConnectionImpl pooledConnection = null;
-        // Workaround for buggy WebLogic 5.1 class loader - ignore the 
exception upon first invocation.
         try {
-            if (connectionProperties != null) {
-                update(connectionProperties, Constants.KEY_USER, 
pooledUserName);
-                update(connectionProperties, Constants.KEY_PASSWORD, 
pooledUserPassword);
-                pooledConnection = new PooledConnectionImpl(
-                    DriverManager.getConnection(getUrl(), 
connectionProperties));
-            } else {
-                pooledConnection = new PooledConnectionImpl(
-                    DriverManager.getConnection(getUrl(), pooledUserName, 
pooledUserPassword));
-            }
-            
pooledConnection.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
+            pooledConnection = getPooledConnectionImpl(pooledUserName, 
pooledUserPassword);
         } catch (final ClassCircularityError e) {
-            if (connectionProperties != null) {
-                pooledConnection = new PooledConnectionImpl(
-                    DriverManager.getConnection(getUrl(), 
connectionProperties));
-            } else {
-                pooledConnection = new PooledConnectionImpl(
-                    DriverManager.getConnection(getUrl(), pooledUserName, 
pooledUserPassword));
-            }
-            
pooledConnection.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
+            pooledConnection = getPooledConnectionImpl(pooledUserName, 
pooledUserPassword);
         }
-        KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> stmtPool = null;
         if (isPoolPreparedStatements()) {
             final GenericKeyedObjectPoolConfig<DelegatingPreparedStatement> 
config = new GenericKeyedObjectPoolConfig<>();
             config.setMaxTotalPerKey(Integer.MAX_VALUE);
@@ -452,12 +438,25 @@ public class DriverAdapterCPDS implements 
ConnectionPoolDataSource, Referenceabl
                 config.setNumTestsPerEvictionRun(0);
                 config.setMinEvictableIdleDuration(Duration.ZERO);
             }
-            stmtPool = new GenericKeyedObjectPool<>(pooledConnection, config);
+            @SuppressWarnings("resource") // PooledConnectionImpl closes
+            final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> 
stmtPool = new GenericKeyedObjectPool<>(pooledConnection, config);
             pooledConnection.setStatementPool(stmtPool);
         }
         return pooledConnection;
     }
 
+    @SuppressWarnings("resource") // Caller closes
+    private PooledConnectionImpl getPooledConnectionImpl(final String 
pooledUserName, final String pooledUserPassword) throws SQLException {
+        PooledConnectionImpl pooledConnection;
+        if (connectionProperties != null) {
+            pooledConnection = new 
PooledConnectionImpl(DriverManager.getConnection(getUrl(), 
connectionProperties));
+        } else {
+            pooledConnection = new 
PooledConnectionImpl(DriverManager.getConnection(getUrl(), pooledUserName, 
pooledUserPassword));
+        }
+        
pooledConnection.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
+        return pooledConnection;
+    }
+
     /**
      * Implements {@link Referenceable}.
      */

Reply via email to