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 2019/07/30 18:25:03 UTC

[commons-dbcp] branch master updated (6442dc8 -> fdc855e)

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 6442dc8  Fix the site's source repository link.
     new 8431c21  [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource to a factory method _in_ DriverConnectionFactory. This moves the factory code closer to home and fixes a checkstyle violation that had BasicDataSource over 2,500 lines of source code.
     new bdc5697  Javadoc.
     new 43ec6a9  Better lvar names.
     new fee15e8  Add license header for Apache RAT check.
     new dbb0f09  Fix site link.
     new 29318b6  Update plugins and start preparing for the next release.
     new cdf40bb  Javadoc.
     new dba0844  [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource to a factory method _in_ DriverConnectionFactory. This moves the factory code closer to home and fixes a checkstyle violation that had BasicDataSource over 2,500 lines of source code.
     new 578129f  Javadoc.
     new 34cb96a  Add @SuppressWarnings.
     new cf295bd  Add @SuppressWarnings.
     new 7b13299  Prepare for the next release.
     new fdc855e  Split out factory code out of BasicDataSource in small factory classes. This helps reduce the size and complexity of BasicDataSource and fixes a Checkstyle violation for the class being too big.

The 13 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                                            |  10 +-
 src/conf/eclipse/formatter.xml                     |  16 ++
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 191 +++++++--------------
 .../commons/dbcp2/BasicDataSourceFactory.java      |   4 +-
 .../commons/dbcp2/ConnectionFactoryFactory.java    |  79 +++++++++
 .../apache/commons/dbcp2/DelegatingConnection.java |  34 ++--
 .../commons/dbcp2/DriverConnectionFactory.java     |   2 +
 .../org/apache/commons/dbcp2/DriverFactory.java    |  81 +++++++++
 .../dbcp2/datasources/InstanceKeyDataSource.java   |  20 ++-
 .../datasources/InstanceKeyDataSourceFactory.java  |   2 +-
 src/site/site.xml                                  |   1 +
 src/site/xdoc/index.xml                            |   2 +
 src/site/xdoc/mail-lists.xml                       |   2 +-
 .../java/org/apache/commons/dbcp2/TestJndi.java    |  12 +-
 .../commons/dbcp2/TesterCallableStatement.java     |   2 +-
 15 files changed, 287 insertions(+), 171 deletions(-)
 create mode 100644 src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java
 create mode 100644 src/main/java/org/apache/commons/dbcp2/DriverFactory.java


[commons-dbcp] 07/13: Javadoc.

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 cdf40bb723913be20d870864c2ea6fcbcac63ee4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:24:08 2019 -0400

    Javadoc.
---
 src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java b/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java
index 9f1698d..d9abb92 100644
--- a/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java
+++ b/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java
@@ -76,7 +76,7 @@ public class TesterCallableStatement extends TesterPreparedStatement implements
     }
 
     /**
-     * @deprecated
+     * @deprecated See {@link CallableStatement#getBigDecimal(int,int)}.
      */
     @Deprecated
     @Override


[commons-dbcp] 09/13: Javadoc.

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 578129fd06bf2898df66771bb1f50bf9798210d2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:25:04 2019 -0400

    Javadoc.
---
 .../org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java     | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
index 13c0cab..52ef8b3 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
@@ -146,6 +146,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
 
     /**
      * Throws an IllegalStateException, if a PooledConnection has already been requested.
+     * 
+     * @throws IllegalStateException Thrown if a PooledConnection has already been requested.
      */
     protected void assertInitializationAllowed() throws IllegalStateException {
         if (getConnectionCalled) {


[commons-dbcp] 06/13: Update plugins and start preparing for the next release.

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 29318b60f4a70b9f6f3d618cce95523d18794133
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:23:54 2019 -0400

    Update plugins and start preparing for the next release.
---
 pom.xml | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 56afc69..35eb0ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -182,7 +182,7 @@
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter</artifactId>
-      <version>5.4.2</version>
+      <version>5.5.1</version>
       <scope>test</scope>
     </dependency>
 
@@ -196,7 +196,7 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
-      <version>2.27.0</version>
+      <version>3.0.0</version>
       <scope>test</scope>
     </dependency>
 
@@ -279,7 +279,7 @@
     <dependency>
       <groupId>org.jboss.logging</groupId>
       <artifactId>jboss-logging</artifactId>
-      <version>3.3.2.Final</version>
+      <version>3.4.0.Final</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
@@ -316,9 +316,11 @@
     <commons.jira.pid>12310469</commons.jira.pid>
     <!-- Override CP version until that is updated -->
     <commons.checkstyle.version>3.0.0</commons.checkstyle.version>
+    <commons.javadoc.version>3.1.1</commons.javadoc.version>
     <!-- Constant for Commons Pool version (used in multiple places) -->
-    <commons.pool.version>2.6.2</commons.pool.version>
+    <commons.pool.version>2.7.0</commons.pool.version>
     <commons.japicmp.version>0.13.1</commons.japicmp.version>
+    <commons.jacoco.version>0.8.4</commons.jacoco.version>
     <!-- See DBCP-445 and DBCP-454 -->
     <commons.osgi.import>javax.transaction;version="1.1.0",javax.transaction.xa;version="1.1.0";partial=true;mandatory:=partial,*</commons.osgi.import>
     <commons.japicmp.ignoreMissingClasses>true</commons.japicmp.ignoreMissingClasses>


[commons-dbcp] 10/13: Add @SuppressWarnings.

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 34cb96a0af2a61489324366472e096580249f29a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:25:36 2019 -0400

    Add @SuppressWarnings.
---
 src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index ad879b8..fd6b4fb 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -1502,6 +1502,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * @throws IllegalStateException if invalidating the connection failed.
      * @since 2.1
      */
+    @SuppressWarnings("resource")
     public void invalidateConnection(final Connection connection) throws IllegalStateException {
         if (connection == null) {
             return;


[commons-dbcp] 01/13: [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource to a factory method _in_ DriverConnectionFactory. This moves the factory code closer to home and fixes a checkstyle violation that had BasicDataSource over 2, 500 lines of source code.

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 8431c21d408f67e0f95f8bf0d9ce5a17eaa7ebf9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 09:56:01 2019 -0400

    [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource
    to a factory method _in_ DriverConnectionFactory. This moves the factory
    code closer to home and fixes a checkstyle violation that had
    BasicDataSource over 2,500 lines of source code.
---
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 56 ++++++++------
 .../commons/dbcp2/DriverConnectionFactory.java     | 88 ++++++++++++++++++++++
 2 files changed, 121 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 6bf8b34..ad879b8 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -76,8 +76,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
 
     private static final Log log = LogFactory.getLog(BasicDataSource.class);
 
-    // ------------------------------------------------------------- Properties
-
     static {
         // Attempt to prevent deadlocks - see DBCP - 272
         DriverManager.getDrivers();
@@ -108,6 +106,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
+    @SuppressWarnings("resource")
     protected static void validateConnectionFactory(final PoolableConnectionFactory connectionFactory)
             throws Exception {
         PoolableConnection conn = null;
@@ -450,7 +449,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
-     * Creates a JDBC connection factory for this datasource. The JDBC driver is loaded using the following algorithm:
+     * Creates a JDBC connection factory for this data source. The JDBC driver is loaded using the following algorithm:
      * <ol>
      * <li>If a Driver instance has been specified via {@link #setDriver(Driver)} use it</li>
      * <li>If no Driver instance was specified and {@link #driverClassName} is specified that class is loaded using the
@@ -460,7 +459,9 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      * context class loader of the current thread.</li>
      * <li>If a driver still isn't loaded one is loaded via the {@link DriverManager} using the specified {@link #url}.
      * </ol>
+     * <p>
      * This method exists so subclasses can replace the implementation class.
+     * </p>
      *
      * @return A new connection factory.
      *
@@ -731,6 +732,17 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
+     * Manually evicts idle connections
+     *
+     * @throws Exception when there is a problem evicting idle objects.
+     */
+    public void evict() throws Exception {
+        if (connectionPool != null) {
+            connectionPool.evict();
+        }
+    }
+
+    /**
      * Gets the print writer used by this configuration to log information on abandoned objects.
      *
      * @return The print writer used by this configuration to log information on abandoned objects.
@@ -845,7 +857,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         return connectionPool;
     }
 
-    // For unit testing
     Properties getConnectionProperties() {
         return connectionProperties;
     }
@@ -1518,18 +1529,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
-     * Manually evicts idle connections.
-     *
-     * @throws Exception Thrown by {@link GenericObjectPool#evict()}.
-     * @see GenericObjectPool#evict()
-     */
-    public void evict() throws Exception {
-        if (connectionPool != null) {
-            connectionPool.evict();
-        }
-    }
-
-    /**
      * Returns the value of the accessToUnderlyingConnectionAllowed property.
      *
      * @return true if access to the underlying connection is allowed, false otherwise.
@@ -1540,7 +1539,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
-     * If true, this data source is closed and no more connections can be retrieved from this datasource.
+     * If true, this data source is closed and no more connections can be retrieved from this data source.
      *
      * @return true, if the data source is closed; false otherwise
      */
@@ -1597,6 +1596,18 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
+    /**
+     * Logs the given throwable.
+     * 
+     * @param throwable the throwable.
+     * @since 2.7.0
+     */
+    protected void log(Throwable throwable) {
+        if (logWriter != null) {
+            throwable.printStackTrace(logWriter);
+        }        
+    }
+
     @Override
     public void postDeregister() {
         // NO-OP
@@ -1712,6 +1723,8 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         this.cacheState = cacheState;
     }
 
+    // ----------------------------------------------------- DataSource Methods
+
     /**
      * Sets the list of SQL statements to be executed when a physical connection is first created.
      * <p>
@@ -1739,8 +1752,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
-    // ----------------------------------------------------- DataSource Methods
-
     /**
      * Sets the connection properties passed to driver.connect(...).
      * <p>
@@ -1964,10 +1975,9 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     /**
      * Sets the ConnectionFactory class name.
      *
-     * @param connectionFactoryClassName
+     * @param connectionFactoryClassName A class name.
      * @since 2.7.0
      */
-
     public void setConnectionFactoryClassName(final String connectionFactoryClassName) {
         if (isEmpty(connectionFactoryClassName)) {
             this.connectionFactoryClassName = null;
@@ -2218,6 +2228,8 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
+    // ------------------------------------------------------ Protected Methods
+
     /**
      * Sets the value of the {@link #numTestsPerEvictionRun} property.
      *
@@ -2231,8 +2243,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
-    // ------------------------------------------------------ Protected Methods
-
     /**
      * <p>
      * Sets the {@link #password}.
diff --git a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
index 1b4f5dd..a99ff9f 100644
--- a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
@@ -18,6 +18,7 @@ package org.apache.commons.dbcp2;
 
 import java.sql.Connection;
 import java.sql.Driver;
+import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Properties;
 
@@ -33,6 +34,93 @@ public class DriverConnectionFactory implements ConnectionFactory {
     private final Properties properties;
 
     /**
+     * Creates a JDBC connection factory for the given data source. The JDBC driver is loaded using the following
+     * algorithm:
+     * <ol>
+     * <li>If a Driver instance has been specified via {@link #setDriver(Driver)} use it</li>
+     * <li>If no Driver instance was specified and {@link #driverClassName} is specified that class is loaded using the
+     * {@link ClassLoader} of this class or, if {@link #driverClassLoader} is set, {@link #driverClassName} is loaded
+     * with the specified {@link ClassLoader}.</li>
+     * <li>If {@link #driverClassName} is specified and the previous attempt fails, the class is loaded using the
+     * context class loader of the current thread.</li>
+     * <li>If a driver still isn't loaded one is loaded via the {@link DriverManager} using the specified {@link #url}.
+     * </ol>
+     * <p>
+     * This method exists so subclasses can replace the implementation class.
+     * </p>
+     *
+     * @return A new connection factory.
+     *
+     * @throws SQLException If the connection factory cannot be created
+     */
+    static DriverConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource) throws SQLException {
+        // Load the JDBC driver class
+        Driver driverToUse = basicDataSource.getDriver();
+        final String driverClassName = basicDataSource.getDriverClassName();
+        final ClassLoader driverClassLoader = basicDataSource.getDriverClassLoader();
+        final String url = basicDataSource.getUrl();
+
+        if (driverToUse == null) {
+            Class<?> driverFromCCL = null;
+            if (driverClassName != null) {
+                try {
+                    try {
+                        if (driverClassLoader == null) {
+                            driverFromCCL = Class.forName(driverClassName);
+                        } else {
+                            driverFromCCL = Class.forName(driverClassName, true, driverClassLoader);
+                        }
+                    } catch (final ClassNotFoundException cnfe) {
+                        driverFromCCL = Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
+                    }
+                } catch (final Exception t) {
+                    final String message = "Cannot load JDBC driver class '" + driverClassName + "'";
+                    basicDataSource.log(message);
+                    basicDataSource.log(t);
+                    throw new SQLException(message, t);
+                }
+            }
+
+            try {
+                if (driverFromCCL == null) {
+                    driverToUse = DriverManager.getDriver(url);
+                } else {
+                    // Usage of DriverManager is not possible, as it does not
+                    // respect the ContextClassLoader
+                    // N.B. This cast may cause ClassCastException which is handled below
+                    driverToUse = (Driver) driverFromCCL.getConstructor().newInstance();
+                    if (!driverToUse.acceptsURL(url)) {
+                        throw new SQLException("No suitable driver", "08001");
+                    }
+                }
+            } catch (final Exception t) {
+                final String message = "Cannot create JDBC driver of class '"
+                        + (driverClassName != null ? driverClassName : "") + "' for connect URL '" + url + "'";
+                basicDataSource.log(message);
+                basicDataSource.log(t);
+                throw new SQLException(message, t);
+            }
+        }
+
+        // Set up the driver connection factory we will use
+        final String user = basicDataSource.getUsername();
+        if (user != null) {
+            basicDataSource.addConnectionProperty("user", user);
+        } else {
+            basicDataSource.log("DBCP DataSource configured without a 'username'");
+        }
+
+        final String pwd = basicDataSource.getPassword();
+        if (pwd != null) {
+            basicDataSource.addConnectionProperty("password", pwd);
+        } else {
+            basicDataSource.log("DBCP DataSource configured without a 'password'");
+        }
+
+        return new DriverConnectionFactory(driverToUse, url, basicDataSource.getConnectionProperties());
+    }
+
+    /**
      * Constructs a connection factory for a given Driver.
      *
      * @param driver


[commons-dbcp] 12/13: Prepare for the next release.

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 7b13299e1c48aeee749396b06eeb8af56b1ffa97
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 13:49:00 2019 -0400

    Prepare for the next release.
---
 src/site/site.xml       | 1 +
 src/site/xdoc/index.xml | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/site/site.xml b/src/site/site.xml
index 561b097..73215a8 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -37,6 +37,7 @@
         <item name="Javadoc&#xA0;2.4.0"     href="/api-2.4.0/index.html"/>
         <item name="Javadoc&#xA0;2.5.0"     href="/api-2.5.0/index.html"/>
         <item name="Javadoc&#xA0;2.6.0"     href="/api-2.6.0/index.html"/>
+        <item name="Javadoc&#xA0;2.7.0"     href="/api-2.7.0/index.html"/>
         <item name="Developers&#xA0;Guide"  href="/guide/index.html" collapse="true">
         <item name="JNDI&#xA0;Howto"        href="/guide/jndi-howto.html"/>
         <item name="Class&#xA0;Diagrams"    href="/guide/classdiagrams.html"/>
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index 8149b53..c6d9596 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -51,6 +51,7 @@ mechanisms that it utilizes.</p>
 <p>DBCP now comes in four different versions to support different versions of
 JDBC. Here is how it works:
 <ul>
+<li>DBCP 2.7.0 compiles and runs under Java 8 only (JDBC 4.2)</li>
 <li>DBCP 2.6.0 compiles and runs under Java 8 only (JDBC 4.2)</li>
 <li>DBCP 2.5.0 compiles and runs under Java 8 only (JDBC 4.2)</li>
 <li>DBCP 2.4.0 compiles and runs under Java 7 only (JDBC 4.1)</li>
@@ -58,6 +59,7 @@ JDBC. Here is how it works:
 <li>DBCP 1.3 compiles and runs under Java 1.4-5.0 only (JDBC 3)</li>
 </ul>
 </p>
+<p>DBCP 2.7.0 binaries should be used by applications running on Java 8 and above.</p>
 <p>DBCP 2.6.0 binaries should be used by applications running on Java 8 and above.</p>
 <p>DBCP 2.5.0 binaries should be used by applications running under Java 8.</p>
 <p>DBCP 2.4.0 binaries should be used by applications running under Java 7.</p>


[commons-dbcp] 04/13: Add license header for Apache RAT check.

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 fee15e81b1f207e8d3a2e6fa5d7a1472975308f7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 09:57:05 2019 -0400

    Add license header for Apache RAT check.
---
 src/conf/eclipse/formatter.xml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/conf/eclipse/formatter.xml b/src/conf/eclipse/formatter.xml
index 17994f4..e181b4b 100644
--- a/src/conf/eclipse/formatter.xml
+++ b/src/conf/eclipse/formatter.xml
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+ <!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  -->
 <profiles version="16">
 <profile kind="CodeFormatterProfile" name="Apache Commons" version="16">
 <setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>


[commons-dbcp] 05/13: Fix site link.

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 dbb0f09e733bee033bbd3c97557cd6c525f7c3f7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 09:57:24 2019 -0400

    Fix site link.
---
 src/site/xdoc/mail-lists.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/site/xdoc/mail-lists.xml b/src/site/xdoc/mail-lists.xml
index a63d323..b1a9dfb 100644
--- a/src/site/xdoc/mail-lists.xml
+++ b/src/site/xdoc/mail-lists.xml
@@ -152,7 +152,7 @@ limitations under the License.
           <td>
             <strong>Commons Commits List</strong>
             <br /><br />
-            Only for e-mails automatically generated by the <a href="source-repository.html">source control</a> sytem.
+            Only for e-mails automatically generated by the <a href="scm.html">source control</a> sytem.
             <br /><br />
           </td>
           <td><a href="mailto:commits-subscribe@commons.apache.org">Subscribe</a></td>


[commons-dbcp] 11/13: Add @SuppressWarnings.

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 cf295bd593a68963d4711f0fbe6d8032cbbf6999
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:27:59 2019 -0400

    Add @SuppressWarnings.
---
 .../java/org/apache/commons/dbcp2/DelegatingConnection.java    | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index fc09b23..fe0de9d 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -87,6 +87,7 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
     /**
      * Returns a string representation of the metadata associated with the innermost delegate connection.
      */
+    @SuppressWarnings("resource")
     @Override
     public synchronized String toString() {
         String str = null;
@@ -114,12 +115,7 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
                 // Ignore
             }
         }
-
-        if (str == null) {
-            str = super.toString();
-        }
-
-        return str;
+        return str != null ? str : super.toString();
     }
 
     /**
@@ -142,6 +138,7 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
      *            connection to compare innermost delegate with
      * @return true if innermost delegate equals <code>c</code>
      */
+    @SuppressWarnings("resource")
     public boolean innermostDelegateEquals(final Connection c) {
         final Connection innerCon = getInnermostDelegateInternal();
         if (innerCon == null) {
@@ -174,6 +171,7 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
      *
      * @return innermost delegate.
      */
+    @SuppressWarnings("resource")
     public final Connection getInnermostDelegateInternal() {
         Connection conn = connection;
         while (conn != null && conn instanceof DelegatingConnection) {


[commons-dbcp] 08/13: [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource to a factory method _in_ DriverConnectionFactory. This moves the factory code closer to home and fixes a checkstyle violation that had BasicDataSource over 2, 500 lines of source code.

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 dba0844dd214171031faeb53713630a012a731a7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 10:24:51 2019 -0400

    [Checkstyle] Move DriverConnectionFactory creation from BasicDataSource
    to a factory method _in_ DriverConnectionFactory. This moves the factory
    code closer to home and fixes a checkstyle violation that had
    BasicDataSource over 2,500 lines of source code.
---
 .../commons/dbcp2/DriverConnectionFactory.java     | 44 +++++++++++++++++-----
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
index a99ff9f..1e25e4d 100644
--- a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
@@ -29,10 +29,6 @@ import java.util.Properties;
  */
 public class DriverConnectionFactory implements ConnectionFactory {
 
-    private final String connectionString;
-    private final Driver driver;
-    private final Properties properties;
-
     /**
      * Creates a JDBC connection factory for the given data source. The JDBC driver is loaded using the following
      * algorithm:
@@ -53,13 +49,15 @@ public class DriverConnectionFactory implements ConnectionFactory {
      *
      * @throws SQLException If the connection factory cannot be created
      */
-    static DriverConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource) throws SQLException {
+    static ConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource) throws SQLException {
         // Load the JDBC driver class
         Driver driverToUse = basicDataSource.getDriver();
         final String driverClassName = basicDataSource.getDriverClassName();
         final ClassLoader driverClassLoader = basicDataSource.getDriverClassLoader();
         final String url = basicDataSource.getUrl();
-
+        
+        final Properties connectionProperties = basicDataSource.getConnectionProperties();
+        
         if (driverToUse == null) {
             Class<?> driverFromCCL = null;
             if (driverClassName != null) {
@@ -87,7 +85,8 @@ public class DriverConnectionFactory implements ConnectionFactory {
                 } else {
                     // Usage of DriverManager is not possible, as it does not
                     // respect the ContextClassLoader
-                    // N.B. This cast may cause ClassCastException which is handled below
+                    // N.B. This cast may cause ClassCastException which is
+                    // handled below
                     driverToUse = (Driver) driverFromCCL.getConstructor().newInstance();
                     if (!driverToUse.acceptsURL(url)) {
                         throw new SQLException("No suitable driver", "08001");
@@ -105,20 +104,45 @@ public class DriverConnectionFactory implements ConnectionFactory {
         // Set up the driver connection factory we will use
         final String user = basicDataSource.getUsername();
         if (user != null) {
-            basicDataSource.addConnectionProperty("user", user);
+            connectionProperties.put("user", user);
         } else {
             basicDataSource.log("DBCP DataSource configured without a 'username'");
         }
 
         final String pwd = basicDataSource.getPassword();
         if (pwd != null) {
-            basicDataSource.addConnectionProperty("password", pwd);
+            connectionProperties.put("password", pwd);
         } else {
             basicDataSource.log("DBCP DataSource configured without a 'password'");
         }
 
-        return new DriverConnectionFactory(driverToUse, url, basicDataSource.getConnectionProperties());
+        return createConnectionFactory(basicDataSource, driverToUse);
     }
+    private static ConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource, final Driver driver) throws SQLException {
+        final String connectionFactoryClassName = basicDataSource.getConnectionFactoryClassName();
+        final Properties connectionProperties = basicDataSource.getConnectionProperties();
+        final String url = basicDataSource.getUrl();
+        if (connectionFactoryClassName != null) {
+            try {
+                final Class<?> connectionFactoryFromCCL = Class.forName(connectionFactoryClassName);
+                return (ConnectionFactory) connectionFactoryFromCCL
+                        .getConstructor(Driver.class, String.class, Properties.class)
+                        .newInstance(driver, url, connectionProperties);
+            } catch (final Exception t) {
+                final String message = "Cannot load ConnectionFactory implementation '" + connectionFactoryClassName
+                        + "'";
+                basicDataSource.log(message);
+                basicDataSource.log(t);
+                throw new SQLException(message, t);
+            }
+        }
+        return new DriverConnectionFactory(driver, url, connectionProperties);
+    }
+    private final String connectionString;
+
+    private final Driver driver;
+
+    private final Properties properties;
 
     /**
      * Constructs a connection factory for a given Driver.


[commons-dbcp] 13/13: Split out factory code out of BasicDataSource in small factory classes. This helps reduce the size and complexity of BasicDataSource and fixes a Checkstyle violation for the class being too big.

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 fdc855e5ded81631c89c9b9142e64bde8507216e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 14:24:45 2019 -0400

    Split out factory code out of BasicDataSource in small factory classes.
    This helps reduce the size and complexity of BasicDataSource and fixes a
    Checkstyle violation for the class being too big.
---
 .../org/apache/commons/dbcp2/BasicDataSource.java  | 146 +++++----------------
 .../commons/dbcp2/BasicDataSourceFactory.java      |   4 +-
 .../commons/dbcp2/ConnectionFactoryFactory.java    |  79 +++++++++++
 .../commons/dbcp2/DriverConnectionFactory.java     | 110 ----------------
 .../org/apache/commons/dbcp2/DriverFactory.java    |  81 ++++++++++++
 5 files changed, 196 insertions(+), 224 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index fd6b4fb..243a29f 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -469,67 +469,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
      */
     protected ConnectionFactory createConnectionFactory() throws SQLException {
         // Load the JDBC driver class
-        Driver driverToUse = this.driver;
-
-        if (driverToUse == null) {
-            Class<?> driverFromCCL = null;
-            if (driverClassName != null) {
-                try {
-                    try {
-                        if (driverClassLoader == null) {
-                            driverFromCCL = Class.forName(driverClassName);
-                        } else {
-                            driverFromCCL = Class.forName(driverClassName, true, driverClassLoader);
-                        }
-                    } catch (final ClassNotFoundException cnfe) {
-                        driverFromCCL = Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
-                    }
-                } catch (final Exception t) {
-                    final String message = "Cannot load JDBC driver class '" + driverClassName + "'";
-                    logWriter.println(message);
-                    t.printStackTrace(logWriter);
-                    throw new SQLException(message, t);
-                }
-            }
-
-            try {
-                if (driverFromCCL == null) {
-                    driverToUse = DriverManager.getDriver(url);
-                } else {
-                    // Usage of DriverManager is not possible, as it does not
-                    // respect the ContextClassLoader
-                    // N.B. This cast may cause ClassCastException which is
-                    // handled below
-                    driverToUse = (Driver) driverFromCCL.getConstructor().newInstance();
-                    if (!driverToUse.acceptsURL(url)) {
-                        throw new SQLException("No suitable driver", "08001");
-                    }
-                }
-            } catch (final Exception t) {
-                final String message = "Cannot create JDBC driver of class '"
-                        + (driverClassName != null ? driverClassName : "") + "' for connect URL '" + url + "'";
-                logWriter.println(message);
-                t.printStackTrace(logWriter);
-                throw new SQLException(message, t);
-            }
-        }
-
-        // Set up the driver connection factory we will use
-        final String user = userName;
-        if (user != null) {
-            connectionProperties.put("user", user);
-        } else {
-            log("DBCP DataSource configured without a 'username'");
-        }
-
-        final String pwd = password;
-        if (pwd != null) {
-            connectionProperties.put("password", pwd);
-        } else {
-            log("DBCP DataSource configured without a 'password'");
-        }
-
-        return createConnectionFactory(driverToUse);
+        return ConnectionFactoryFactory.createConnectionFactory(this, DriverFactory.createDriver(this));
     }
 
     /**
@@ -831,6 +771,19 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
+     * Returns the ConnectionFactoryClassName that has been configured for use by this pool.
+     * <p>
+     * Note: This getter only returns the last value set by a call to {@link #setConnectionFactoryClassName(String)}.
+     * </p>
+     *
+     * @return the ConnectionFactoryClassName that has been configured for use by this pool.
+     * @since 2.7.0
+     */
+    public String getConnectionFactoryClassName() {
+        return this.connectionFactoryClassName;
+    }
+
+    /**
      * Returns the list of SQL statements executed when a physical connection is first created. Returns an empty list if
      * there are no initialization statements configured.
      *
@@ -991,19 +944,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
-     * Returns the ConnectionFactoryClassName that has been configured for use by this pool.
-     * <p>
-     * Note: This getter only returns the last value set by a call to {@link #setConnectionFactoryClassName(String)}.
-     * </p>
-     *
-     * @return the ConnectionFactoryClassName that has been configured for use by this pool.
-     * @since 2.7.0
-     */
-    public String getConnectionFactoryClassName() {
-        return this.connectionFactoryClassName;
-    }
-
-    /**
      * Returns the value of the flag that controls whether or not connections being returned to the pool will be checked
      * and configured with {@link Connection#setAutoCommit(boolean) Connection.setAutoCommit(true)} if the auto commit
      * setting is {@code false} when the connection is returned. It is <code>true</code> by default.
@@ -1599,12 +1539,14 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
 
     /**
      * Logs the given throwable.
-     * 
+     * @param message TODO
      * @param throwable the throwable.
+     * 
      * @since 2.7.0
      */
-    protected void log(Throwable throwable) {
+    protected void log(String message, Throwable throwable) {
         if (logWriter != null) {
+            logWriter.println(message);
             throwable.printStackTrace(logWriter);
         }        
     }
@@ -1715,6 +1657,8 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         this.autoCommitOnReturn = autoCommitOnReturn;
     }
 
+    // ----------------------------------------------------- DataSource Methods
+
     /**
      * Sets the state caching flag.
      *
@@ -1724,7 +1668,19 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         this.cacheState = cacheState;
     }
 
-    // ----------------------------------------------------- DataSource Methods
+    /**
+     * Sets the ConnectionFactory class name.
+     *
+     * @param connectionFactoryClassName A class name.
+     * @since 2.7.0
+     */
+    public void setConnectionFactoryClassName(final String connectionFactoryClassName) {
+        if (isEmpty(connectionFactoryClassName)) {
+            this.connectionFactoryClassName = null;
+        } else {
+            this.connectionFactoryClassName = connectionFactoryClassName;
+        }
+    }
 
     /**
      * Sets the list of SQL statements to be executed when a physical connection is first created.
@@ -1974,20 +1930,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
     }
 
     /**
-     * Sets the ConnectionFactory class name.
-     *
-     * @param connectionFactoryClassName A class name.
-     * @since 2.7.0
-     */
-    public void setConnectionFactoryClassName(final String connectionFactoryClassName) {
-        if (isEmpty(connectionFactoryClassName)) {
-            this.connectionFactoryClassName = null;
-        } else {
-            this.connectionFactoryClassName = connectionFactoryClassName;
-        }
-    }
-
-    /**
      * Sets the value of the flag that controls whether or not connections being returned to the pool will be checked
      * and configured with {@link Connection#setAutoCommit(boolean) Connection.setAutoCommit(true)} if the auto commit
      * setting is {@code false} when the connection is returned. It is <code>true</code> by default.
@@ -2214,6 +2156,8 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
+    // ------------------------------------------------------ Protected Methods
+
     /**
      * Sets the minimum number of idle connections in the pool. The pool attempts to ensure that minIdle connections are
      * available when the idle object evictor runs. The value of this property has no effect unless
@@ -2229,8 +2173,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         }
     }
 
-    // ------------------------------------------------------ Protected Methods
-
     /**
      * Sets the value of the {@link #numTestsPerEvictionRun} property.
      *
@@ -2515,22 +2457,4 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
         config.setJmxNamePrefix(Constants.JMX_CONNECTION_POOL_PREFIX);
     }
 
-    private ConnectionFactory createConnectionFactory(final Driver driver) throws SQLException {
-        if (connectionFactoryClassName != null) {
-            try {
-                Class<?> connectionFactoryFromCCL = Class.forName(connectionFactoryClassName);
-                return (ConnectionFactory) connectionFactoryFromCCL
-                        .getConstructor(Driver.class, String.class, Properties.class)
-                        .newInstance(driver, url, connectionProperties);
-            } catch (final Exception t) {
-                final String message = "Cannot load ConnectionFactory implementation '" + connectionFactoryClassName
-                        + "'";
-                logWriter.println(message);
-                t.printStackTrace(logWriter);
-                throw new SQLException(message, t);
-            }
-        }
-        return new DriverConnectionFactory(driver, url, connectionProperties);
-    }
-
 }
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
index e826cff..945d163 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
@@ -552,11 +552,9 @@ public class BasicDataSourceFactory implements ObjectFactory {
 
         value = properties.getProperty(PROP_CONNECTION_FACTORY_CLASS_NAME);
         if (value != null) {
-        	dataSource.setConnectionFactoryClassName(value);
+            dataSource.setConnectionFactoryClassName(value);
         }
 
-
-
         // DBCP-215
         // Trick to make sure that initialSize connections are created
         if (dataSource.getInitialSize() > 0) {
diff --git a/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java b/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java
new file mode 100644
index 0000000..5d635bb
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/*
+ * Creates {@link ConnectionFactory} instances.
+ * 
+ * @since 2.7.0
+ */
+class ConnectionFactoryFactory {
+
+    /**
+     * Creates a new {@link DriverConnectionFactory} allowing for an override through
+     * {@link BasicDataSource#getDriverClassName()}.
+     * 
+     * @param basicDataSource Configures creation.
+     * @param driver          The JDBC driver.
+     * @return a new {@link DriverConnectionFactory} allowing for a {@link BasicDataSource#getDriverClassName()}
+     *         override.
+     * @throws SQLException Thrown when instantiation fails.
+     */
+    static ConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource, final Driver driver)
+            throws SQLException {
+        final Properties connectionProperties = basicDataSource.getConnectionProperties();
+        final String url = basicDataSource.getUrl();
+        // Set up the driver connection factory we will use
+        final String user = basicDataSource.getUsername();
+        if (user != null) {
+            connectionProperties.put("user", user);
+        } else {
+            basicDataSource.log("DBCP DataSource configured without a 'username'");
+        }
+
+        final String pwd = basicDataSource.getPassword();
+        if (pwd != null) {
+            connectionProperties.put("password", pwd);
+        } else {
+            basicDataSource.log("DBCP DataSource configured without a 'password'");
+        }
+        if (basicDataSource != null) {
+            final String connectionFactoryClassName = basicDataSource.getConnectionFactoryClassName();
+            if (connectionFactoryClassName != null) {
+                try {
+                    final Class<?> connectionFactoryFromCCL = Class.forName(connectionFactoryClassName);
+                    return (ConnectionFactory) connectionFactoryFromCCL
+                            .getConstructor(Driver.class, String.class, Properties.class)
+                            .newInstance(driver, url, connectionProperties);
+                } catch (final Exception t) {
+                    final String message = "Cannot load ConnectionFactory implementation '" + connectionFactoryClassName
+                            + "'";
+                    basicDataSource.log(message, t);
+                    throw new SQLException(message, t);
+                }
+            }
+        }
+        // Defaults to DriverConnectionFactory
+        return new DriverConnectionFactory(driver, url, connectionProperties);
+    }
+
+}
diff --git a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
index 1e25e4d..0434584 100644
--- a/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java
@@ -18,7 +18,6 @@ package org.apache.commons.dbcp2;
 
 import java.sql.Connection;
 import java.sql.Driver;
-import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Properties;
 
@@ -29,115 +28,6 @@ import java.util.Properties;
  */
 public class DriverConnectionFactory implements ConnectionFactory {
 
-    /**
-     * Creates a JDBC connection factory for the given data source. The JDBC driver is loaded using the following
-     * algorithm:
-     * <ol>
-     * <li>If a Driver instance has been specified via {@link #setDriver(Driver)} use it</li>
-     * <li>If no Driver instance was specified and {@link #driverClassName} is specified that class is loaded using the
-     * {@link ClassLoader} of this class or, if {@link #driverClassLoader} is set, {@link #driverClassName} is loaded
-     * with the specified {@link ClassLoader}.</li>
-     * <li>If {@link #driverClassName} is specified and the previous attempt fails, the class is loaded using the
-     * context class loader of the current thread.</li>
-     * <li>If a driver still isn't loaded one is loaded via the {@link DriverManager} using the specified {@link #url}.
-     * </ol>
-     * <p>
-     * This method exists so subclasses can replace the implementation class.
-     * </p>
-     *
-     * @return A new connection factory.
-     *
-     * @throws SQLException If the connection factory cannot be created
-     */
-    static ConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource) throws SQLException {
-        // Load the JDBC driver class
-        Driver driverToUse = basicDataSource.getDriver();
-        final String driverClassName = basicDataSource.getDriverClassName();
-        final ClassLoader driverClassLoader = basicDataSource.getDriverClassLoader();
-        final String url = basicDataSource.getUrl();
-        
-        final Properties connectionProperties = basicDataSource.getConnectionProperties();
-        
-        if (driverToUse == null) {
-            Class<?> driverFromCCL = null;
-            if (driverClassName != null) {
-                try {
-                    try {
-                        if (driverClassLoader == null) {
-                            driverFromCCL = Class.forName(driverClassName);
-                        } else {
-                            driverFromCCL = Class.forName(driverClassName, true, driverClassLoader);
-                        }
-                    } catch (final ClassNotFoundException cnfe) {
-                        driverFromCCL = Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
-                    }
-                } catch (final Exception t) {
-                    final String message = "Cannot load JDBC driver class '" + driverClassName + "'";
-                    basicDataSource.log(message);
-                    basicDataSource.log(t);
-                    throw new SQLException(message, t);
-                }
-            }
-
-            try {
-                if (driverFromCCL == null) {
-                    driverToUse = DriverManager.getDriver(url);
-                } else {
-                    // Usage of DriverManager is not possible, as it does not
-                    // respect the ContextClassLoader
-                    // N.B. This cast may cause ClassCastException which is
-                    // handled below
-                    driverToUse = (Driver) driverFromCCL.getConstructor().newInstance();
-                    if (!driverToUse.acceptsURL(url)) {
-                        throw new SQLException("No suitable driver", "08001");
-                    }
-                }
-            } catch (final Exception t) {
-                final String message = "Cannot create JDBC driver of class '"
-                        + (driverClassName != null ? driverClassName : "") + "' for connect URL '" + url + "'";
-                basicDataSource.log(message);
-                basicDataSource.log(t);
-                throw new SQLException(message, t);
-            }
-        }
-
-        // Set up the driver connection factory we will use
-        final String user = basicDataSource.getUsername();
-        if (user != null) {
-            connectionProperties.put("user", user);
-        } else {
-            basicDataSource.log("DBCP DataSource configured without a 'username'");
-        }
-
-        final String pwd = basicDataSource.getPassword();
-        if (pwd != null) {
-            connectionProperties.put("password", pwd);
-        } else {
-            basicDataSource.log("DBCP DataSource configured without a 'password'");
-        }
-
-        return createConnectionFactory(basicDataSource, driverToUse);
-    }
-    private static ConnectionFactory createConnectionFactory(final BasicDataSource basicDataSource, final Driver driver) throws SQLException {
-        final String connectionFactoryClassName = basicDataSource.getConnectionFactoryClassName();
-        final Properties connectionProperties = basicDataSource.getConnectionProperties();
-        final String url = basicDataSource.getUrl();
-        if (connectionFactoryClassName != null) {
-            try {
-                final Class<?> connectionFactoryFromCCL = Class.forName(connectionFactoryClassName);
-                return (ConnectionFactory) connectionFactoryFromCCL
-                        .getConstructor(Driver.class, String.class, Properties.class)
-                        .newInstance(driver, url, connectionProperties);
-            } catch (final Exception t) {
-                final String message = "Cannot load ConnectionFactory implementation '" + connectionFactoryClassName
-                        + "'";
-                basicDataSource.log(message);
-                basicDataSource.log(t);
-                throw new SQLException(message, t);
-            }
-        }
-        return new DriverConnectionFactory(driver, url, connectionProperties);
-    }
     private final String connectionString;
 
     private final Driver driver;
diff --git a/src/main/java/org/apache/commons/dbcp2/DriverFactory.java b/src/main/java/org/apache/commons/dbcp2/DriverFactory.java
new file mode 100644
index 0000000..2a05453
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/DriverFactory.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/*
+ * Creates {@link Driver} instances.
+ * 
+ * @since 2.7.0
+ */
+class DriverFactory {
+
+    static Driver createDriver(final BasicDataSource basicDataSource) throws SQLException {
+        // Load the JDBC driver class
+        Driver driverToUse = basicDataSource.getDriver();
+        String driverClassName = basicDataSource.getDriverClassName();
+        ClassLoader driverClassLoader = basicDataSource.getDriverClassLoader();
+        String url = basicDataSource.getUrl();
+
+        if (driverToUse == null) {
+            Class<?> driverFromCCL = null;
+            if (driverClassName != null) {
+                try {
+                    try {
+                        if (driverClassLoader == null) {
+                            driverFromCCL = Class.forName(driverClassName);
+                        } else {
+                            driverFromCCL = Class.forName(driverClassName, true, driverClassLoader);
+                        }
+                    } catch (final ClassNotFoundException cnfe) {
+                        driverFromCCL = Thread.currentThread().getContextClassLoader().loadClass(driverClassName);
+                    }
+                } catch (final Exception t) {
+                    final String message = "Cannot load JDBC driver class '" + driverClassName + "'";
+                    basicDataSource.log(message, t);
+                    throw new SQLException(message, t);
+                }
+            }
+
+            try {
+                if (driverFromCCL == null) {
+                    driverToUse = DriverManager.getDriver(url);
+                } else {
+                    // Usage of DriverManager is not possible, as it does not
+                    // respect the ContextClassLoader
+                    // N.B. This cast may cause ClassCastException which is
+                    // handled below
+                    driverToUse = (Driver) driverFromCCL.getConstructor().newInstance();
+                    if (!driverToUse.acceptsURL(url)) {
+                        throw new SQLException("No suitable driver", "08001");
+                    }
+                }
+            } catch (final Exception t) {
+                final String message = "Cannot create JDBC driver of class '"
+                        + (driverClassName != null ? driverClassName : "") + "' for connect URL '" + url + "'";
+                basicDataSource.log(message, t);
+                throw new SQLException(message, t);
+            }
+        }
+        return driverToUse;
+    }
+
+}


[commons-dbcp] 03/13: Better lvar names.

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 43ec6a924be1fb22b21c40b82f1a4ddc101313a8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 09:56:48 2019 -0400

    Better lvar names.
---
 .../apache/commons/dbcp2/DelegatingConnection.java | 30 +++++++++++-----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index 546e6a8..fc09b23 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -89,17 +89,17 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
      */
     @Override
     public synchronized String toString() {
-        String s = null;
+        String str = null;
 
-        final Connection c = this.getInnermostDelegateInternal();
-        if (c != null) {
+        final Connection conn = this.getInnermostDelegateInternal();
+        if (conn != null) {
             try {
-                if (c.isClosed()) {
-                    s = "connection is closed";
+                if (conn.isClosed()) {
+                    str = "connection is closed";
                 } else {
                     final StringBuffer sb = new StringBuffer();
                     sb.append(hashCode());
-                    final DatabaseMetaData meta = c.getMetaData();
+                    final DatabaseMetaData meta = conn.getMetaData();
                     if (meta != null) {
                         sb.append(", URL=");
                         sb.append(meta.getURL());
@@ -107,7 +107,7 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
                         sb.append(meta.getUserName());
                         sb.append(", ");
                         sb.append(meta.getDriverName());
-                        s = sb.toString();
+                        str = sb.toString();
                     }
                 }
             } catch (final SQLException ex) {
@@ -115,11 +115,11 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
             }
         }
 
-        if (s == null) {
-            s = super.toString();
+        if (str == null) {
+            str = super.toString();
         }
 
-        return s;
+        return str;
     }
 
     /**
@@ -175,14 +175,14 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
      * @return innermost delegate.
      */
     public final Connection getInnermostDelegateInternal() {
-        Connection c = connection;
-        while (c != null && c instanceof DelegatingConnection) {
-            c = ((DelegatingConnection<?>) c).getDelegateInternal();
-            if (this == c) {
+        Connection conn = connection;
+        while (conn != null && conn instanceof DelegatingConnection) {
+            conn = ((DelegatingConnection<?>) conn).getDelegateInternal();
+            if (this == conn) {
                 return null;
             }
         }
-        return c;
+        return conn;
     }
 
     /**


[commons-dbcp] 02/13: Javadoc.

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 bdc56975dc63401fa40e2d645ad57ddf32c5230b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 30 09:56:27 2019 -0400

    Javadoc.
---
 .../dbcp2/datasources/InstanceKeyDataSource.java       | 18 +++++++++---------
 .../datasources/InstanceKeyDataSourceFactory.java      |  2 +-
 src/test/java/org/apache/commons/dbcp2/TestJndi.java   | 12 ++++++------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
index 1b070cc..13c0cab 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
@@ -98,7 +98,7 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
     /** Description */
     private String description;
 
-    /** Environment that may be used to set up a jndi initial context. */
+    /** Environment that may be used to set up a JNDI initial context. */
     private Properties jndiEnvironment;
 
     /** Login TimeOut in seconds */
@@ -520,8 +520,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
     }
 
     /**
-     * Gets the value of connectionPoolDataSource. This method will return null, if the backing datasource is being
-     * accessed via jndi.
+     * Gets the value of connectionPoolDataSource. This method will return null, if the backing data source is being
+     * accessed via JNDI.
      *
      * @return value of connectionPoolDataSource.
      */
@@ -530,8 +530,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
     }
 
     /**
-     * Sets the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the
-     * datasource.
+     * Sets the backend ConnectionPoolDataSource. This property should not be set if using JNDI to access the
+     * data source.
      *
      * @param v
      *            Value to assign to connectionPoolDataSource.
@@ -549,8 +549,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
     }
 
     /**
-     * Gets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource
-     * from a jndi service provider.
+     * Gets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the data source
+     * from a JNDI service provider.
      *
      * @return value of dataSourceName.
      */
@@ -559,8 +559,8 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
     }
 
     /**
-     * Sets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource
-     * from a jndi service provider.
+     * Sets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the data source
+     * from a JNDI service provider.
      *
      * @param v
      *            Value to assign to dataSourceName.
diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java
index ee68cd7..f6ee923 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java
@@ -120,7 +120,7 @@ abstract class InstanceKeyDataSourceFactory implements ObjectFactory {
             if (isCorrectClass(ref.getClassName())) {
                 final RefAddr refAddr = ref.get("instanceKey");
                 if (refAddr != null && refAddr.getContent() != null) {
-                    // object was bound to jndi via Referenceable api.
+                    // object was bound to JNDI via Referenceable API.
                     obj = instanceMap.get(refAddr.getContent());
                 } else {
                     // Tomcat JNDI creates a Reference out of server.xml
diff --git a/src/test/java/org/apache/commons/dbcp2/TestJndi.java b/src/test/java/org/apache/commons/dbcp2/TestJndi.java
index fbaef4c..8121174 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestJndi.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestJndi.java
@@ -43,12 +43,12 @@ public class TestJndi {
     protected static final String JNDI_SUBCONTEXT = "jdbc";
 
     /**
-     * the full jndi path to the data source.
+     * the full JNDI path to the data source.
      */
     protected static final String JNDI_PATH = JNDI_SUBCONTEXT + "/"
             + "jndiTestDataSource";
 
-    /** jndi context to use in tests **/
+    /** JNDI context to use in tests **/
     protected Context context = null;
 
     /**
@@ -97,7 +97,7 @@ public class TestJndi {
     }
 
     /**
-     * Binds a DataSource to the jndi and checks that we have successfully
+     * Binds a DataSource to the JNDI and checks that we have successfully
      * bound it by looking it up again.
      *
      * @throws Exception if the bind, lookup or connect fails
@@ -108,7 +108,7 @@ public class TestJndi {
     }
 
     /**
-     * Binds a DataSource into jndi.
+     * Binds a DataSource into JNDI.
      *
      * @throws Exception if creation or binding fails.
      */
@@ -117,9 +117,9 @@ public class TestJndi {
     }
 
     /**
-     * Retrieves a DataSource from jndi.
+     * Retrieves a DataSource from JNDI.
      *
-     * @throws Exception if the jndi lookup fails or no DataSource is bound.
+     * @throws Exception if the JNDI lookup fails or no DataSource is bound.
      */
     protected DataSource retrieveDataSource() throws Exception {
         final Context ctx = getInitialContext();