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/29 14:30:36 UTC
[commons-dbcp] branch release updated (6619cde -> c419630)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git.
from 6619cde Update commons-parent from 47 to 48.
new 91c3023 Remove obsolete comment.
new d603fc5 Javadoc.
new f6c1c4b Add @SuppressWarnings.
new dabd348 Add @SuppressWarnings.
new e6893e4 Sort members.
new 5b43bc7 [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 c419630 Use current version of JaCoCo.
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:
pom.xml | 3 +-
.../org/apache/commons/dbcp2/BasicDataSource.java | 113 ++++++---------------
.../apache/commons/dbcp2/DelegatingConnection.java | 30 +++---
.../commons/dbcp2/DriverConnectionFactory.java | 88 ++++++++++++++++
.../dbcp2/datasources/InstanceKeyDataSource.java | 18 ++--
.../datasources/InstanceKeyDataSourceFactory.java | 2 +-
.../java/org/apache/commons/dbcp2/TestJndi.java | 12 +--
7 files changed, 154 insertions(+), 112 deletions(-)
[commons-dbcp] 03/07: 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 release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit f6c1c4be33054ec634edf10f16bec71b6f85e3cd
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:35:04 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 1aab125..5ef4156 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -106,6 +106,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
+ @SuppressWarnings("resource")
protected static void validateConnectionFactory(final PoolableConnectionFactory connectionFactory)
throws Exception {
PoolableConnection conn = null;
[commons-dbcp] 07/07: Use current version of JaCoCo.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit c419630e2342f6acc2109fb0773c55f1a96d9f67
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 10:30:31 2019 -0400
Use current version of JaCoCo.
- Also fix BC version.
- Reinstate log(String) as a protected method for BC.
- Better lvar names.
- Javadoc "jdni" -> "JNDI".
- Javadoc "api" -> "API".
---
pom.xml | 3 ++-
.../org/apache/commons/dbcp2/BasicDataSource.java | 10 ++++++--
.../apache/commons/dbcp2/DelegatingConnection.java | 30 +++++++++++-----------
.../dbcp2/datasources/InstanceKeyDataSource.java | 18 ++++++-------
.../datasources/InstanceKeyDataSourceFactory.java | 2 +-
.../java/org/apache/commons/dbcp2/TestJndi.java | 12 ++++-----
6 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6a09757..4142991 100644
--- a/pom.xml
+++ b/pom.xml
@@ -312,11 +312,12 @@
<!-- Constant for Commons Pool version (used in multiple places) -->
<commons.pool.version>2.7.0</commons.pool.version>
<commons.japicmp.version>0.14.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 Release Plugin -->
- <commons.bc.version>2.6.2</commons.bc.version>
+ <commons.bc.version>2.6.0</commons.bc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.releaseManagerName>Gary Gregory</commons.releaseManagerName>
<commons.releaseManagerKey>86fdc7e2a11262cb</commons.releaseManagerKey>
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 6dd7320..25d5981 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -1520,13 +1520,19 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
- void log(final String message) {
+ protected void log(final String message) {
if (logWriter != null) {
logWriter.println(message);
}
}
- void log(Throwable throwable) {
+ /**
+ * Logs the given throwable.
+ *
+ * @param throwable the throwable.
+ * @since 2.7.0
+ */
+ protected void log(Throwable throwable) {
if (logWriter != null) {
throwable.printStackTrace(logWriter);
}
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;
}
/**
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 6d5eb94..c9f5b27 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();
[commons-dbcp] 01/07: Remove obsolete comment.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit 91c30237317a31cfc56224ce63e34636add62c0c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:10:29 2019 -0400
Remove obsolete comment.
---
src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 093aab7..28698ac 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();
[commons-dbcp] 02/07: Javadoc.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit d603fc52f548b5e50985b0c6c09e1357bef8aafa
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:34:20 2019 -0400
Javadoc.
---
src/main/java/org/apache/commons/dbcp2/BasicDataSource.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 28698ac..1aab125 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -446,7 +446,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
@@ -456,7 +456,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.
*
@@ -1518,6 +1520,8 @@ 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) {
[commons-dbcp] 06/07: [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 release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit 5b43bc7347ba68a4d5831060b8198266470c38ee
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:58:25 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 | 81 +++-----------------
.../commons/dbcp2/DriverConnectionFactory.java | 88 ++++++++++++++++++++++
2 files changed, 100 insertions(+), 69 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index c6a4c34..6dd7320 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -467,69 +467,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
* If the connection factort cannot be created
*/
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'");
- }
-
- final ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driverToUse, url,
- connectionProperties);
- return driverConnectionFactory;
+ return DriverConnectionFactory.createConnectionFactory(this);
}
/**
@@ -868,7 +806,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
return connectionPool;
}
- // For unit testing
Properties getConnectionProperties() {
return connectionProperties;
}
@@ -1583,12 +1520,18 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
- protected void log(final String message) {
+ void log(final String message) {
if (logWriter != null) {
logWriter.println(message);
}
}
+ void log(Throwable throwable) {
+ if (logWriter != null) {
+ throwable.printStackTrace(logWriter);
+ }
+ }
+
@Override
public void postDeregister() {
// NO-OP
@@ -1709,6 +1652,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>
@@ -1737,8 +1682,6 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
- // ----------------------------------------------------- DataSource Methods
-
/**
* Sets the connection properties passed to driver.connect(...).
* <p>
@@ -2228,6 +2171,8 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
}
}
+ // ------------------------------------------------------ Protected Methods
+
/**
* Sets the value of the {@link #numTestsPerEvictionRun} property.
*
@@ -2242,8 +2187,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] 04/07: 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 release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit dabd348acf5e9ea732d2e1395a22aa27ef23b048
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:35:38 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 5ef4156..85e94f3 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -1493,6 +1493,7 @@ public class BasicDataSource implements DataSource, BasicDataSourceMXBean, MBean
* if invalidating the connection failed.
* @since 2.1
*/
+ @SuppressWarnings("resource")
public void invalidateConnection(final Connection connection) throws IllegalStateException {
if (connection == null) {
return;
[commons-dbcp] 05/07: Sort members.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit e6893e4580338bc657da41b66efe4be41275de69
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jul 29 09:42:14 2019 -0400
Sort members.
---
.../org/apache/commons/dbcp2/BasicDataSource.java | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 85e94f3..c6a4c34 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -739,6 +739,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.
@@ -1521,17 +1532,6 @@ 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();
- }
- }
-
- /**
* Returns the value of the accessToUnderlyingConnectionAllowed property.
*
* @return true if access to the underlying connection is allowed, false otherwise.