diff -Nru commons-dbcp2-2.6.0/CONTRIBUTING.md commons-dbcp2-2.7.0/CONTRIBUTING.md --- commons-dbcp2-2.6.0/CONTRIBUTING.md 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/CONTRIBUTING.md 2019-07-31 12:46:24.000000000 +0000 @@ -1,115 +1,115 @@ - - -Contributing to Apache Commons DBCP -====================== - -You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to -the open source community. Before you dig right into the code there are a few guidelines that we need contributors to -follow so that we can have a chance of keeping on top of things. - -Getting Started ---------------- - -+ Make sure you have a [JIRA account](https://issues.apache.org/jira/). -+ Make sure you have a [GitHub account](https://github.com/signup/free). -+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons DBCP's scope. -+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. - + Clearly describe the issue including steps to reproduce when it is a bug. - + Make sure you fill in the earliest version that you know has the issue. -+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), -[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. - -Making Changes --------------- - -+ Create a _topic branch_ for your isolated work. - * Usually you should base your branch on the `master` or `trunk` branch. - * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `DBCP-123-InputStream`. - * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. -+ Make commits of logical units. - * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. - * e.g. `DBCP-123: Close input stream earlier` -+ Respect the original code style: - + Only use spaces for indentation. - + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. - + Check for unnecessary whitespace with `git diff` -- check before committing. -+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`. -+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. - -Making Trivial Changes ----------------------- - -The JIRA tickets are used to generate the changelog for the next release. - -For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. -In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number. - - -Submitting Changes ------------------- - -+ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already. - * Note that small patches & typical bug fixes do not require a CLA as - clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions) - covers them. -+ Push your changes to a topic branch in your fork of the repository. -+ Submit a _Pull Request_ to the corresponding repository in the `apache` organization. - * Verify _Files Changed_ shows only your intended changes and does not - include additional files like `target/*.class` -+ Update your JIRA ticket and include a link to the pull request in the ticket. - -If you prefer to not use GitHub, then you can instead use -`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue. - - -Additional Resources --------------------- - -+ [Contributing patches](https://commons.apache.org/patches.html) -+ [Apache Commons DBCP JIRA project page][jira] -+ [Contributor License Agreement][cla] -+ [General GitHub documentation](https://help.github.com/) -+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.net` - -[cla]:https://www.apache.org/licenses/#clas -[jira]:https://issues.apache.org/jira/browse/DBCP + + +Contributing to Apache Commons DBCP +====================== + +You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to +the open source community. Before you dig right into the code there are a few guidelines that we need contributors to +follow so that we can have a chance of keeping on top of things. + +Getting Started +--------------- + ++ Make sure you have a [JIRA account](https://issues.apache.org/jira/). ++ Make sure you have a [GitHub account](https://github.com/signup/free). ++ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons DBCP's scope. ++ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. + + Clearly describe the issue including steps to reproduce when it is a bug. + + Make sure you fill in the earliest version that you know has the issue. ++ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), +[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. + +Making Changes +-------------- + ++ Create a _topic branch_ for your isolated work. + * Usually you should base your branch on the `master` or `trunk` branch. + * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `DBCP-123-InputStream`. + * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. ++ Make commits of logical units. + * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. + * e.g. `DBCP-123: Close input stream earlier` ++ Respect the original code style: + + Only use spaces for indentation. + + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. + + Check for unnecessary whitespace with `git diff` -- check before committing. ++ Make sure you have added the necessary tests for your changes, typically in `src/test/java`. ++ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. + +Making Trivial Changes +---------------------- + +The JIRA tickets are used to generate the changelog for the next release. + +For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. +In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number. + + +Submitting Changes +------------------ + ++ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already. + * Note that small patches & typical bug fixes do not require a CLA as + clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions) + covers them. ++ Push your changes to a topic branch in your fork of the repository. ++ Submit a _Pull Request_ to the corresponding repository in the `apache` organization. + * Verify _Files Changed_ shows only your intended changes and does not + include additional files like `target/*.class` ++ Update your JIRA ticket and include a link to the pull request in the ticket. + +If you prefer to not use GitHub, then you can instead use +`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue. + + +Additional Resources +-------------------- + ++ [Contributing patches](https://commons.apache.org/patches.html) ++ [Apache Commons DBCP JIRA project page][jira] ++ [Contributor License Agreement][cla] ++ [General GitHub documentation](https://help.github.com/) ++ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) ++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) ++ `#apache-commons` IRC channel on `irc.freenode.net` + +[cla]:https://www.apache.org/licenses/#clas +[jira]:https://issues.apache.org/jira/browse/DBCP diff -Nru commons-dbcp2-2.6.0/debian/changelog commons-dbcp2-2.7.0/debian/changelog --- commons-dbcp2-2.6.0/debian/changelog 2019-07-18 21:43:30.000000000 +0000 +++ commons-dbcp2-2.7.0/debian/changelog 2019-08-11 22:20:00.000000000 +0000 @@ -1,3 +1,9 @@ +commons-dbcp2 (2.7.0-1) unstable; urgency=medium + + * New upstream version 2.7.0. + + -- Markus Koschany Mon, 12 Aug 2019 00:20:00 +0200 + commons-dbcp2 (2.6.0-1) unstable; urgency=medium * New upstream version 2.6.0. diff -Nru commons-dbcp2-2.6.0/debian/maven.ignoreRules commons-dbcp2-2.7.0/debian/maven.ignoreRules --- commons-dbcp2-2.6.0/debian/maven.ignoreRules 2019-07-18 21:43:30.000000000 +0000 +++ commons-dbcp2-2.7.0/debian/maven.ignoreRules 2019-08-11 22:20:00.000000000 +0000 @@ -19,3 +19,4 @@ org.slf4j slf4j-simple * * * * tomcat naming-common * * * * tomcat naming-java * * * * +org.junit.jupiter junit-jupiter * * * * diff -Nru commons-dbcp2-2.6.0/NOTICE.txt commons-dbcp2-2.7.0/NOTICE.txt --- commons-dbcp2-2.6.0/NOTICE.txt 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/NOTICE.txt 2019-07-31 12:46:24.000000000 +0000 @@ -1,5 +1,5 @@ -Apache Commons DBCP -Copyright 2001-2019 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). +Apache Commons DBCP +Copyright 2001-2019 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff -Nru commons-dbcp2-2.6.0/pom.xml commons-dbcp2-2.7.0/pom.xml --- commons-dbcp2-2.6.0/pom.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/pom.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,507 +1,515 @@ - - - - - org.apache.commons - commons-parent - 47 - - 4.0.0 - commons-dbcp2 - 2.6.0 - Apache Commons DBCP - - 2001 - Apache Commons DBCP software implements Database Connection Pooling - http://commons.apache.org/dbcp/ - - - - - apache.website - Apache Commons Site - scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-dbcp/ - - - - - jira - http://issues.apache.org/jira/browse/DBCP - - - - scm:git:http://git-wip-us.apache.org/repos/asf/commons-dbcp.git - scm:git:https://git-wip-us.apache.org/repos/asf/commons-dbcp.git - https://git-wip-us.apache.org/repos/asf?p=commons-dbcp.git - - - - - Morgan Delagrange - morgand - - - - - Geir Magnusson - geirm - - - - - Craig McClanahan - craigmcc - - - - - John McNally - jmcnally - - - - - Martin Poeschl - mpoeschl - mpoeschl@marmot.at - tucana.at - - - Rodney Waldhoff - rwaldhoff - - - - - David Weinrich - dweinr1 - - - - - Dirk Verbeeck - dirkv - - - - - Yoav Shapira - yoavs - yoavs@apache.org - The Apache Software Foundation - - - Jörg Schaible - joehni - joerg.schaible@gmx.de - - +1 - - - Mark Thomas - markt - markt@apache.org - The Apache Software Foundation - - - Gary Gregory - ggregory - ggregory@apache.org - The Apache Software Foundation - - - Ignacio J. Ortega - nacho - - - Sean C. Sullivan - sullis - - - - - Todd Carmichael - toddc@concur.com - - - Wayne Woodfield - - - Dain Sundstrom - dain@apache.org - - - Philippe Mouawad - - - Glenn L. Nielsen - - - James House - - - James Ring - - - Peter Wicks - pwicks@apache.org - - - - - - org.apache.commons - commons-pool2 - ${commons.pool.version} - - - - commons-logging - commons-logging - 1.2 - - - - junit - junit - 4.12 - test - - - - org.mockito - mockito-core - 2.24.0 - test - - - - - org.apache.geronimo.specs - geronimo-jta_1.1_spec - 1.1.1 - true - - - - - tomcat - naming-common - 5.0.28 - test - - - - tomcat - naming-java - 5.0.28 - test - - - - - org.apache.geronimo.modules - geronimo-transaction - 2.2.1 - test - - - junit - junit - - - commons-logging - commons-logging - - - - - org.slf4j - slf4j-simple - 1.7.25 - test - - - com.h2database - h2 - 1.4.197 - test - - - org.jboss.narayana.jta - narayana-jta - 5.9.2.Final - test - - - org.jboss.spec.javax.transaction - jboss-transaction-api_1.2_spec - 1.1.1.Final - test - - - org.jboss - jboss-transaction-spi - 7.6.0.Final - - - org.jboss.logging - jboss-logging-spi - - - test - - - org.jboss.logging - jboss-logging - 3.3.2.Final - test - - - - - UTF-8 - UTF-8 - 1.8 - 1.8 - dbcp - RC1 - org.apache.commons.dbcp2 - - 2.6.0 - for JDBC 4.2 on Java 8 - - 2.4.0 - for JDBC 4.1 on Java 7 - - - commons-dbcp-${commons.release.3.version} - 1.4 - for JDBC 4 on Java 6 - - - commons-dbcp-${commons.release.4.version} - 1.3 - for JDBC 3 on Java 1.4 or 5 - - dbcp - https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-dbcp - site-content - DBCP - 12310469 - - 3.0.0 - - 2.6.1 - 0.13.0 - - javax.transaction;version="1.1.0",javax.transaction.xa;version="1.1.0";partial=true;mandatory:=partial,* - true - - 2.5.0 - true - Gary Gregory - 86fdc7e2a11262cb - - - - - - - org.apache.maven.plugins - maven-scm-publish-plugin - ${commons.scm-publish.version} - - - javadocs - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${commons.checkstyle.version} - - ${basedir}/checkstyle.xml - false - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - org.apache.commons.dbcp2.StackMessageLog - - - - **/Tester*.java - - **/Test*$*.java - - - - - maven-assembly-plugin - - - src/main/assembly/bin.xml - src/main/assembly/src-tar-gz.xml - src/main/assembly/src-zip.xml - - gnu - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - - api-* - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${commons.javadoc.version} - - - http://docs.oracle.com/javase/7/docs/api - http://commons.apache.org/proper/commons-pool/api-${commons.pool.version} - http://docs.oracle.com/javaee/7/api/ - - - - - - - - - com.github.siom79.japicmp - japicmp-maven-plugin - ${commons.japicmp.version} - - - - - - - - - - - - - true - ${commons.japicmp.breakBuildOnBinaryIncompatibleModifications} - - true - true - true - ${commons.japicmp.ignoreMissingClasses} - ${commons.bc.version} - - - - org.apache.geronimo.specs - geronimo-jta_1.1_spec - 1.1.1 - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.5 - - Normal - Default - ${basedir}/findbugs-exclude-filter.xml - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${commons.javadoc.version} - - - http://docs.oracle.com/javase/7/docs/api - http://commons.apache.org/proper/commons-pool/api-${commons.pool.version} - http://docs.oracle.com/javaee/7/api/ - - - - - org.apache.maven.plugins - maven-changes-plugin - ${commons.changes.version} - - - src/changes - - - 12313721,12326766,12328750 - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${commons.checkstyle.version} - - ${basedir}/checkstyle.xml - false - - - - org.codehaus.mojo - clirr-maven-plugin - ${commons.clirr.version} - - info - - - - maven-pmd-plugin - 3.11.0 - - ${maven.compiler.target} - - - - - pmd - cpd - - - - - - - - - + + + + + org.apache.commons + commons-parent + 48 + + 4.0.0 + commons-dbcp2 + 2.7.0 + Apache Commons DBCP + + 2001 + Apache Commons DBCP software implements Database Connection Pooling + https://commons.apache.org/dbcp/ + + + + + apache.website + Apache Commons Site + scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-dbcp/ + + + + + jira + https://issues.apache.org/jira/browse/DBCP + + + + scm:git:http://git-wip-us.apache.org/repos/asf/commons-dbcp.git + scm:git:https://git-wip-us.apache.org/repos/asf/commons-dbcp.git + https://git-wip-us.apache.org/repos/asf?p=commons-dbcp.git + + + + + Morgan Delagrange + morgand + + + + + Geir Magnusson + geirm + + + + + Craig McClanahan + craigmcc + + + + + John McNally + jmcnally + + + + + Martin Poeschl + mpoeschl + mpoeschl@marmot.at + tucana.at + + + Rodney Waldhoff + rwaldhoff + + + + + David Weinrich + dweinr1 + + + + + Dirk Verbeeck + dirkv + + + + + Yoav Shapira + yoavs + yoavs@apache.org + The Apache Software Foundation + + + Jörg Schaible + joehni + joerg.schaible@gmx.de + + +1 + + + Mark Thomas + markt + markt@apache.org + The Apache Software Foundation + + + Gary Gregory + ggregory + ggregory@apache.org + The Apache Software Foundation + + + Ignacio J. Ortega + nacho + + + Sean C. Sullivan + sullis + + + + + Todd Carmichael + toddc@concur.com + + + Wayne Woodfield + + + Dain Sundstrom + dain@apache.org + + + Philippe Mouawad + + + Glenn L. Nielsen + + + James House + + + James Ring + + + Peter Wicks + pwicks@apache.org + + + + + + org.apache.commons + commons-pool2 + ${commons.pool.version} + + + + commons-logging + commons-logging + 1.2 + + + + org.junit.jupiter + junit-jupiter + 5.5.1 + test + + + + org.hamcrest + hamcrest-all + 1.3 + test + + + + org.mockito + mockito-core + 3.0.0 + test + + + + + org.apache.geronimo.specs + geronimo-jta_1.1_spec + 1.1.1 + true + + + + + tomcat + naming-common + 5.0.28 + test + + + + tomcat + naming-java + 5.0.28 + test + + + + + org.apache.geronimo.modules + geronimo-transaction + 2.2.1 + test + + + org.junit.jupiter + junit-jupiter + + + commons-logging + commons-logging + + + + + org.slf4j + slf4j-simple + 1.7.26 + test + + + com.h2database + h2 + 1.4.199 + test + + + org.jboss.narayana.jta + narayana-jta + 5.9.5.Final + test + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.2_spec + 1.1.1.Final + test + + + org.jboss + jboss-transaction-spi + 7.6.0.Final + + + org.jboss.logging + jboss-logging-spi + + + test + + + org.jboss.logging + jboss-logging + 3.4.0.Final + test + + + + + UTF-8 + UTF-8 + 1.8 + 1.8 + dbcp + RC1 + org.apache.commons.dbcp2 + + 2.7.0 + for JDBC 4.2 on Java 8 + + 2.4.0 + for JDBC 4.1 on Java 7 + + + commons-dbcp-${commons.release.3.version} + 1.4 + for JDBC 4 on Java 6 + + + commons-dbcp-${commons.release.4.version} + 1.3 + for JDBC 3 on Java 1.4 or 5 + + dbcp + https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-dbcp + site-content + DBCP + 12310469 + + 3.0.0 + 3.1.1 + + 2.7.0 + 0.13.1 + 0.8.4 + + javax.transaction;version="1.1.0",javax.transaction.xa;version="1.1.0";partial=true;mandatory:=partial,* + true + + 2.6.0 + true + Gary Gregory + 86fdc7e2a11262cb + + false + + + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + ${commons.scm-publish.version} + + + javadocs + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${commons.checkstyle.version} + + ${basedir}/checkstyle.xml + false + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + org.apache.commons.dbcp2.StackMessageLog + + + + **/Tester*.java + + **/Test*$*.java + + + + + maven-assembly-plugin + + + src/main/assembly/bin.xml + src/main/assembly/src-tar-gz.xml + src/main/assembly/src-zip.xml + + gnu + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + + api-* + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${commons.javadoc.version} + + + http://docs.oracle.com/javase/7/docs/api + https://commons.apache.org/proper/commons-pool/api-${commons.pool.version} + http://docs.oracle.com/javaee/7/api/ + + + + + + + + + com.github.siom79.japicmp + japicmp-maven-plugin + ${commons.japicmp.version} + + + + cmp-report + + + + + + true + ${commons.japicmp.breakBuildOnBinaryIncompatibleModifications} + + true + true + true + ${commons.japicmp.ignoreMissingClasses} + ${commons.bc.version} + + + + org.apache.geronimo.specs + geronimo-jta_1.1_spec + 1.1.1 + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.5 + + Normal + Default + ${basedir}/findbugs-exclude-filter.xml + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${commons.javadoc.version} + + + http://docs.oracle.com/javase/7/docs/api + https://commons.apache.org/proper/commons-pool/api-${commons.pool.version} + http://docs.oracle.com/javaee/7/api/ + + + + + org.apache.maven.plugins + maven-changes-plugin + ${commons.changes.version} + + + src/changes + + + 12313721,12326766,12328750 + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${commons.checkstyle.version} + + ${basedir}/checkstyle.xml + false + + + + org.codehaus.mojo + clirr-maven-plugin + ${commons.clirr.version} + + info + + + + maven-pmd-plugin + 3.12.0 + + ${maven.compiler.target} + + + + + pmd + cpd + + + + + + + + + diff -Nru commons-dbcp2-2.6.0/README.md commons-dbcp2-2.7.0/README.md --- commons-dbcp2-2.6.0/README.md 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/README.md 2019-07-31 12:46:24.000000000 +0000 @@ -1,105 +1,105 @@ - - -Apache Commons DBCP -=================== - -[![Build Status](https://travis-ci.org/apache/commons-dbcp.svg)](https://travis-ci.org/apache/commons-dbcp) -[![Coverage Status](https://coveralls.io/repos/apache/commons-dbcp/badge.svg)](https://coveralls.io/r/apache/commons-dbcp) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/) -[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.6.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.6.0) - -Apache Commons DBCP software implements Database Connection Pooling - -Documentation -------------- - -More information can be found on the [Apache Commons DBCP homepage](https://commons.apache.org/proper/commons-dbcp). -The [Javadoc](https://commons.apache.org/proper/commons-dbcp/javadocs/api-release) can be browsed. -Questions related to the usage of Apache Commons DBCP should be posted to the [user mailing list][ml]. - -Where can I get the latest release? ------------------------------------ -You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi). - -Alternatively you can pull it from the central Maven repositories: - -```xml - - org.apache.commons - commons-dbcp2 - 2.6.0 - -``` - -Contributing ------------- - -We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. -There are some guidelines which will make applying PRs easier for us: -+ No tabs! Please use spaces for indentation. -+ Respect the code style. -+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. -+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. - -If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). -You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). - -License -------- -This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). - -See the `NOTICE.txt` file for required notices and attributions. - -Donations ---------- -You like Apache Commons DBCP? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. - -Additional Resources --------------------- - -+ [Apache Commons Homepage](https://commons.apache.org/) -+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/DBCP) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.org` - -[ml]:https://commons.apache.org/mail-lists.html + + +Apache Commons DBCP +=================== + +[![Build Status](https://travis-ci.org/apache/commons-dbcp.svg)](https://travis-ci.org/apache/commons-dbcp) +[![Coverage Status](https://coveralls.io/repos/apache/commons-dbcp/badge.svg)](https://coveralls.io/r/apache/commons-dbcp) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-dbcp2/) +[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-dbcp2/2.7.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-dbcp2/2.7.0) + +Apache Commons DBCP software implements Database Connection Pooling + +Documentation +------------- + +More information can be found on the [Apache Commons DBCP homepage](https://commons.apache.org/proper/commons-dbcp). +The [Javadoc](https://commons.apache.org/proper/commons-dbcp/javadocs/api-release) can be browsed. +Questions related to the usage of Apache Commons DBCP should be posted to the [user mailing list][ml]. + +Where can I get the latest release? +----------------------------------- +You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi). + +Alternatively you can pull it from the central Maven repositories: + +```xml + + org.apache.commons + commons-dbcp2 + 2.7.0 + +``` + +Contributing +------------ + +We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. +There are some guidelines which will make applying PRs easier for us: ++ No tabs! Please use spaces for indentation. ++ Respect the code style. ++ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. ++ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. + +If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). +You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). + +License +------- +This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). + +See the `NOTICE.txt` file for required notices and attributions. + +Donations +--------- +You like Apache Commons DBCP? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. + +Additional Resources +-------------------- + ++ [Apache Commons Homepage](https://commons.apache.org/) ++ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/DBCP) ++ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) ++ `#apache-commons` IRC channel on `irc.freenode.org` + +[ml]:https://commons.apache.org/mail-lists.html diff -Nru commons-dbcp2-2.6.0/README.txt commons-dbcp2-2.7.0/README.txt --- commons-dbcp2-2.6.0/README.txt 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/README.txt 2019-07-31 12:46:24.000000000 +0000 @@ -2,7 +2,7 @@ =========================== Welcome to the DBCP component of the Apache Commons -project (http://commons.apache.org). +project (https://commons.apache.org). DBCP version 2.5.0 requires JDK 1.8. @@ -11,6 +11,6 @@ build.properties. There is a build.properties.sample file included in the source distribution. -See http://commons.apache.org/dbcp/ for additional and +See https://commons.apache.org/dbcp/ for additional and up-to-date information on Commons DBCP. diff -Nru commons-dbcp2-2.6.0/RELEASE-NOTES.txt commons-dbcp2-2.7.0/RELEASE-NOTES.txt --- commons-dbcp2-2.6.0/RELEASE-NOTES.txt 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/RELEASE-NOTES.txt 2019-07-31 12:46:24.000000000 +0000 @@ -1,4 +1,58 @@ Apache Apache Commons DBCP + Version 2.7.0 + RELEASE NOTES + 7 July 2019 + +The Apache Commons DBCP team is pleased to announce the release of Apache Apache Commons DBCP 2.7.0. + +Apache Commons DBCP software implements Database Connection Pooling. + +This is a minor release, including bug fixes and enhancements. + +Changes in this version include: + +New features: +o DBCP-539: ManagedDataSource#close() should declare used exceptions. Thanks to Jacques Le Roux. +o DBCP-547: Add a ConnectionFactory class name setting for BasicDataSource.createConnectionFactory() #33. Thanks to leechoongyon, Gary Gregory. +o Add missing Javadocs. Thanks to Gary Gregory. + +Fixed Bugs: +o DBCP-538: Wrong JMX base name derived in BasicDataSource#updateJmxName. Thanks to Ragnar Haugan, Gary Gregory. +o DBCP-546: Avoid NPE when calling DriverAdapterCPDS.toString(). Thanks to Sergey Chupov. +o DBCP-550: java.util.IllegalFormatException while building a message for a SQLFeatureNotSupportedException in Jdbc41Bridge.getObject(ResultSet,String,Class). Thanks to Gary Gregory. +o Fix Javadoc link in README.md #21. Thanks to LichKing-lee. + +Changes: +o DBCP-540: Close ObjectOutputStream before calling toByteArray() on underlying ByteArrayOutputStream #28. Thanks to emopers. +o DBCP-541: Upgrade to JUnit Jupiter #19. Thanks to Allon Murienik. +o DBCP-542: Fix tests on Java 11. Thanks to Zheng Feng, Gary Gregory. +o DBCP-543: Update Apache Commons Pool from 2.6.1 to 2.6.2. Thanks to Gary Gregory. +o DBCP-529: Add 'jmxName' property to web configuration parameters listing. Thanks to Yuri. +o DBCP-548: Update Apache Commons Pool from 2.6.2 to 2.7.0. Thanks to Gary Gregory. +o DBCP-549: Make org.apache.commons.dbcp2.AbandonedTrace.removeTrace(AbandonedTrace) null-safe. Thanks to Gary Gregory. +o DBCP-551: org.apache.commons.dbcp2.DelegatingStatement.close() should try to close ALL of its result sets even when an exception occurs. Thanks to Gary Gregory. +o DBCP-552: org.apache.commons.dbcp2.DelegatingConnection.passivate() should close ALL of its resources even when an exception occurs. Thanks to Gary Gregory. +o DBCP-553: org.apache.commons.dbcp2.PoolablePreparedStatement.passivate() should close ALL of its resources even when an exception occurs. Thanks to Gary Gregory. +o DBCP-554: org.apache.commons.dbcp2.PoolableCallableStatement.passivate() should close ALL of its resources even when an exception occurs. Thanks to Gary Gregory. +o Update tests from org.mockito:mockito-core 2.28.2 to 3.0.0. Thanks to Gary Gregory. +o Update tests from H2 1.4.198 to 1.4.199. Thanks to Gary Gregory. +o Update tests from com.h2database:h2 1.4.197 to 1.4.199. Thanks to Gary Gregory. +o Update tests from org.jboss.narayana.jta:narayana-jta 5.9.2.Final to 5.9.5.Final. Thanks to Gary Gregory. +o Update tests from org.jboss.logging:jboss-logging 3.3.2.Final to 3.4.0.Final. Thanks to Gary Gregory. +o Update tests from org.mockito:mockito-core 2.24.0 to 2.28.2. Thanks to Gary Gregory. +o Update tests from org.mockito:mockito-core 2.28.2 to 3.0.0. Thanks to Gary Gregory. + + +For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, +patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: + +https://commons.apache.org/dbcp/ + +Download page: https://commons.apache.org/dbcp/download_dbcp.cgi + +----------------------------------------------------------------------------- + + Apache Apache Commons DBCP Version 2.6.0 RELEASE NOTES @@ -31,9 +85,9 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download page: http://commons.apache.org/dbcp/download_dbcp.cgi +Download page: https://commons.apache.org/dbcp/download_dbcp.cgi ----------------------------------------------------------------------------- @@ -70,13 +124,13 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +Download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi ----------------------------------------------------------------------------- -Download page: http://commons.apache.org/dbcp/download_dbcp.cgi +Download page: https://commons.apache.org/dbcp/download_dbcp.cgi Apache Apache Commons DBCP Version 2.4.0 @@ -86,7 +140,7 @@ Apache Commons DBCP software implements Database Connection Pooling. -This is a minor release, including bug fixes and enhancements, which you can download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +This is a minor release, including bug fixes and enhancements, which you can download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi Changes in this version include: @@ -112,9 +166,9 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +Download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi ----------------------------------------------------------------------------- @@ -145,9 +199,9 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +Download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi ----------------------------------------------------------------------------- @@ -209,9 +263,9 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +Download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi ----------------------------------------------------------------------------- @@ -244,6 +298,6 @@ For complete information on Apache Commons DBCP, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Apache Commons DBCP website: -http://commons.apache.org/dbcp/ +https://commons.apache.org/dbcp/ -Download from http://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi +Download from https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi diff -Nru commons-dbcp2-2.6.0/src/changes/changes.xml commons-dbcp2-2.7.0/src/changes/changes.xml --- commons-dbcp2-2.6.0/src/changes/changes.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/changes/changes.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,1006 +1,1087 @@ - - - - - - - - Commons DBCP Release Notes - - - - - - - Allow for manual connection eviction. - - - Allow DBCP to register with a TransactionSynchronizationRegistry for XA cases. - - - Make defensive copies of char[] passwords. - - - Do not try to register synchronization when the transaction is no longer active. - - - Do not double returnObject back to the pool if there is a transaction context with a shared connection. - - - Allow DBCP to work with old Java 6/JDBC drivers without throwing AbstractMethodError. - - - Add some toString() methods for debugging (never printing passwords.) - - - BasicManagedDataSource needs to pass the TSR with creating DataSourceXAConnectionFactory. - - - Add getters to some classes. - - - org.apache.commons.dbcp2.DriverManagerConnectionFactory should use a char[] instead of a String to store passwords. - - - Update Apache Commons Pool from 2.6.0 to 2.6.1. - - - - - Update Java requirement from version 7 to 8. - - - Support JDBC 4.2. - - - Support default schema in configuration. - - - Examines 'SQLException's thrown by underlying connections or statements for fatal (disconnection) errors. - - - Change default for fail-fast connections from false to true. - - - Prepared statement keys should take a Connection's schema into account. - - - Increase test coverage. - - - Update Apache Commons Pool from 2.5.0 to 2.6.0. - - - Avoid exceptions when closing a connection in mutli-threaded use case. - - - - - Connection leak during XATransaction in high load. - - - Drop Ant build. - - - Ensure DBCP ConnectionListener can deal with transaction managers which invoke rollback in a separate thread. - - - org.apache.commons.dbcp2.PStmtKey should make copies of given arrays in constructors. - - - Remove duplicate code in org.apache.commons.dbcp2.cpdsadapter.PStmtKeyCPDS. - - - Add support for pooling CallableStatements to the org.apache.commons.dbcp2.cpdsadapter package. - - - Deprecate use of PStmtKeyCPDS in favor of PStmtKey. - - - org.apache.commons.dbcp2.DataSourceConnectionFactory should use a char[] instead of a String to store passwords. - - - org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory should use a char[] instead of a String to store passwords. - - - org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS should use a char[] instead of a String to store passwords. - - - org.apache.commons.dbcp2.datasources.CPDSConnectionFactory should use a char[] instead of a String to store passwords. - - - org.apache.commons.dbcp2.datasources internals should use a char[] instead of a String to store passwords. - - - org.apache.commons.dbcp2.datasources.InstanceKeyDataSourceFactory.closeAll() does not close all. - - - - - AbandonedTrace.getTrace() contains race condition. - - - Avoid javax.management.InstanceNotFoundException on shutdown when a bean is not registered. Closes #9. - - - Make constant public: org.apache.commons.dbcp2.PoolingDriver.URL_PREFIX. - - - DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set. - - - Add API org.apache.commons.dbcp2.datasources.PerUserPoolDataSource.clear(). - - - NPE for org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS.setConnectionProperties(null). - - - The method org.apache.commons.dbcp2.PoolingDriver.getConnectionPool(String) does not tell you which pool name is not registered when it throws an exception. - - - - - Update Apache Commons Pool from 2.4.2 to 2.5.0. - - - OSGi declarations contain multiple import headers for javax.transaction. - - - Wrong parameter name in site documentation for BasicDataSource Configuration Parameters. - - - Add jmxName to properties set by BasicDataSourceFactory. This - enables container-managed pools created from JNDI Resource - definitions to enable JMX by supplying a valid root JMX name. - - - NullPointerException thrown when calling ManagedConnection.isClosed(). - - - InvalidateConnection can result in closed connection returned by getConnection. - - - Complete the fix for DBCP-418, enabling PoolableConnection class to load in environments - (such as GAE) where the JMX ManagementFactory is not available. - - - Add constructor DriverManagerConnectionFactory(String). - - - Ensure that the cacheState setting is used when statement pooling is - disabled. - - - Ensure that setSoftMinEvictableIdleTimeMillis is used when working with - BasicDataSource. - - - Correct the name of the configuration attribute - softMinEvictableIdleTimeMillis. - - - Avoid potential infinite loops when checking if an SQLException is fatal - for a connection or not. - - - Expand the fail-fast for fatal connection errors feature to include - managed connections. - - - Correct a typo in the method name - PoolableConnectionFactory#setMaxOpenPreparedStatements. The old method - remains but is deprecated so not to break clients currently using the - incorrect name. - - - Refactoring to prepare for a future patch to enable pooling of all - prepared and callable statements in PoolingConnection. - - - Ensure that a thread's interrupt status is visible to the caller if the - thread is interrupted during a call to - PoolingDataSource.getConnection(). - - - Make it simpler to extend BasicDataSource to allow sub-classes to - provide custom GenericObjectPool implementations. - - - When using a BasicDataSource, pass changes related to the handling of - abandoned connections to the underlying pool so that the pool - configuration may be updated dynamically. - - - Enable pooling of all prepared and callable statements - inPoolingConnection. - - - - - Updated pool version to 2.4.2. The fix for POOL-300 may cause DBCP - users to see more reports of abandoned connections (if removal and logging - are configured). Prior to the fix for POOL-300, the PrintWriter used to log - abandoned connection stack traces was not being flushed on each log event. - - - Added BasicDataSource abandonedUsageTracking property missing from BasicDataSourceFactory. - - - SharedPoolDataSource getConnection fails when testOnBorrow is set with - a null validation query. - - - Nested connections in a transaction (local) throws null pointer. - - - BasicDataSource does not set disconnectionSql properties on its PoolableConnectionFactory. - - - - - InstanceKeyDataSource discards native SQLException when given password does not match - password used to create the connection. - - - Update Apache Commons Logging to 1.2 from 1.1.3. - - - Correct some Javadoc references to Apache Commons Pool 2 classes that - have changed names since Pool 1.x. - - - Do not ignore the configured custom eviction policy when creating a - BasicDataSource. - - - Added invalidateConnection method to BasicDataSource. - - - Unsuccessful Connection enlistment in XA Transaction ignored by TransactionContext. - - - Made expired connection logging configurable in BasicDataSource. Setting - logExpiredConnections to false suppresses expired connection log messages. - - - Made Datasources implement AutoCloseable. - - - Added fastFailValidation property to PoolableConnection, configurable in - BasicDataSource. When set to true, connections that have previously thrown - fatal disconnection errors will fail validation immediately (no driver calls). - - - Changed BasicDataSource createDataSource method to ensure that initialization - completes before clients get reference to newly created instances. - - - Fixed connection leak when SQLException is thrown while enlisting an XA - transaction. - - - Setting jmxName to null should suppress JMX registration of connection - and statement pools. - - - Eliminated synchronization in BasicDataSource getNumActive, getNumIdle methods. - - - Added property name verification to BasicDataSourceFactory. References including - obsolete or unrecognized properties now generate log messages. - - - - - Small performance improvements when returning connections to the pool. - - - Fixed DelegatingStatement close to ensure closed statements do not retain references - to pooled prepared statements. Due to finalization code added in 2.0, this was causing - pooled prepared statements to be closed by GC while in use by clients. - - - Added check in PoolingDataSource constructor to ensure that the connection factory - and pool are properly linked. - - - Fixed connection leak when managed connections are closed during transactions. - - - Enable PoolableConnection class to load without JMX. - - - - - BasicManagedDataSource - unregister from JMX on close(). - - - Log validation failures of poolable connections. - - - DelegatingStatement.close() fails with NPE if statement is null - - - CPDSConnectionFactory.validateObject(Object) ignores Throwable. - - - Provide a new option (cacheState) to cache current values of autoCommit - and readOnly so database queries are not required for every call to the - associated getters. This option is enabled by default. - - - Removed unnecessary synchronisation in BasicDataSource#createDataSource. - - - The Java package name has been changed from org.apache.commons.dbcp to - org.apache.commons.dbcp2. - - - Update to Commons Pool 2 (based on java.util.concurrent) to provide - pooling functionality. - - - Updated source code for Java 1.6 (added @Override & @Deprecated - annotations). - - - Removed JOCL support. - - - Remove deprecated SQLNestedException. - - - Fix threading issues with accessToUnderlyingConnectionAllowed attribute - of PoolingDriver which is used to support unit testing. - - - BasicDataSource instances are now exposed via JMX. All the configuration - properties are available as is the connection pool and the statement - pools (if statement pooling is enabled). - - - Fix thread safety issues in the SharedPoolDataSource and the - PerUserPoolDataSource. - - - Allow accessToUnderlyingConnectionAllowed to be configured when - configuration takes place via JNDI in a JavaEE container. - - - Fix threading issue when using multiple instances of the - SharedPoolDataSource concurrently. - - - Ensure that the close state of a pooled connection and the underlying - connection is consistent when the underlying connection is closed as a - result of an error condition. - - - Make all mutable fields private. - - - Return BasicDataSource rather than DataSource from - BasicDataSourceFactory so a cast is not required to use BasicDataSource - specific methods. - - - The equals() implementations of the DelegatingXxx classes are now - symmetric. There are some important API changes underlying this fix. - Firstly, two DelegatingXxx instances are no longer considered equal if - they have the same innermost delegate. Secondly, a DelegatingXxx - instance is not considered equal to its innermost delegate. The - getInnermostDelegateInternal() method has been made public (but remains - part of the internal API) to allow classes extending this implementation - to access the innermost delegate when required. - - - Expose the new Pool 2 property evictionPolicyClassName to enable more - sophisticated eviction strategies to be used. - - - Add support for pooling PreparedStatements that use auto-generated keys. - - - Enable JDBC resources that are no longer referenced by client code to be - eligible for garbage collection. - - - Enable DBCP to work with a SecurityManager such that only DBCP needs to - be granted the necessary permissions to communicate with the database. - - - Correct path to Javadoc overview in build.xml. - - - The default values for readOnly, autoCommit and transactionIsolation are - now taken from the JDBC driver. No calls to setReadOnly(), - setAutoCommit() or setTransactionIsolation() will be made for a newly - borrowed connection unless a default is explicitly configured and the - connection is currently using a different setting. - - - Register pooled connections with JMX so that they may be forcibly closed - via JMX if required. - - - Modify SharedPoolDataSource and PerUserPoolDataSource to expose all of - the configuration properties of the underlying connection pool(s). This - represents a significant refactoring of these classes and a number of - property names have changed as a result. - - - Provide an option to control if autoCommit is always set to true when a - connection is returned to the connection pool. - - - Provide an option to control if rollback is called when a connection is - returned to the poll with autoCommit disabled. - - - Provide an option to set the default query timeout. - - - Connection.isValid() should not throw an SQLException if the connection - is closed. - - - Use Connection.isValid() to validate connections unless a validation - query is explicitly configured. Note that this means it is no longer - necessary for a validation query to be specified in order for validation - to take place. When testing with Oracle, this resulted in database - validation being approximately 7 times faster. - - - Add support for validation testing database connections on creation. - - - - - Correct the documentation for the maxOpenPreparedStatements parameter - and review the use of the phrase non-positive throughout the - documentation and javadoc, replacing it with negative where that is the - correct definition to use. - - - Avoid multiple calls to Connection.getAutoCommit() in - PoolableConnectionFactory.passivateObject() as it could be an expensive - call. - - - Use one line per statement for methods with multiple statements rather - than using a single line. - - - Expose all of the AbandonedConfig properties through a BasicDataSource. - - - Correct implementation of DelegatingConnection.isWrapperFor() so it - works correctly with older JDBC drivers. - - - Correct implementation of DelegatingStatement.isWrapperFor(). Also fix - DelegatingDatabaseMetaData.isWrapperFor() and - DelegatingResultSet.isWrapperFor() that had the same problem. - - - LocalXAConnectionFactory does not properly check if Xid is equal to - currentXid when resuming which may result in an XAException. - - - Ensure that the XAConnection is closed when the associated Connection is - closed. - - - Clarify Jaavdoc for isClosed() method of PoolableConnection. - - - Avoid NullPointerException and throw an XAException if an attempt is - made to commit the current transaction for a connection when no - transaction has been started. - - - Using batchUpdate() should not invalidate the PreparedStatement when it - is returned to the pool. - - - Improve documentation for JNDI example using BasicDataSource. - - - - - Exposed GenericObjectPool's softMinEvictableIdleTimeMillis property for - configuration and use by BasicDataSource. - - - Made equals reflexive in DelegatingStatement (and subclasses), DelegatingMetaData, - DelegatingResultSet and PoolingDriver#PoolGuardConnectionWrapper. - - - Modified createDataSource method in BasicDataSource to ensure that GenericObjectPool - Evictor tasks are not started and orphaned when BasicDataSource encounters errors on - initialization. Prior to this fix, when minIdle and timeBetweenEvictionRunsMillis - are both positive, Evictors orphaned by failed initialization can continue to - generate database connection requests. This issue is duplicated by DBCP-339 - and DBCP-93. - - - Changed DelegatingDatabaseMetaData to no longer add itself to the AbandonedTrace - of its parent connection. This was causing excessive memory consumption and was - not necessary, as resultsets created by DelegatingDatabaseMetaData instances are - attached to the parent connection's trace on creation. Also fixes DBCP-352. - - - Modified execute methods of Statement objects to ensure that whenever - a statement is used, the lastUsed property of its parent connection is - updated. - - - Correctly implemented the option to configure the class loader used to load - the JDBC driver. - - - LIFO configuration option has been added to BasicDataSource. When set - to true (the default), the pool acts as a LIFO queue; setting to false - causes connections to enter and exit to pool in FIFO order. - - - Test transitive dependencies brought in by geronimo-transaction created - version conflicts (commons logging and junit). These have been explicitly - excluded in the POM. - - - BasicDataSourceFactory incorrectly used "initConnectSqls" in versions - 1.3 and 1.4 of DBCP as the property name for connectionInitSqls. - Online docs for 1.3/1/4 have been updated to reflect this inconsistency. - The BasicDataSourceFactory property name has been changed to "connectInitSqls" - to match the online docs and the BasicDataSource property name. - - - - - Eliminated poolKeys cache from PerUserPoolDataSource. - - - Eliminated userKeys LRUMap cache from SharedPoolDataSource. - - - Made private fields final where possible. - - - PerUserPoolDataSource.getPooledConnectionAndInfo multi-threading bug. - - - Remove throws clause from method that does not throw an exception. - - - Remove code that catches and ignores Exceptions when calling - PooledConnection.removeConnectionEventListener(ConnectionEventListener) - as the method does not throw any Exceptions. - - - Remove impossible null check. - - - Renamed variables with duplicate names in different scopes. - - - Clarified javadoc for BasicDataSource close() method. - - - Made PoolingConnection pool CallableStatements. When BasicDataSource's - poolPreparedStatements property is true, CallableStatements are now - pooled along with PreparedStatements. The maxOpenPreparedStatements - property limits the combined number of Callable and Prepared statements - that can be in use at a given time. - - - Use an API specific exception for logging abandoned objects to make - scanning the logs for these exceptions simpler and to provide a better - message that includes the creation time of the abandoned object. - - - Ensure Statement.getGeneratedKeys() works correctly with the CPDS - adapter. - - - Removed incorrectly advertised ClassNotFoundException from - JOCLContentHandler.ConstructorDetails.createObject(). - - - Make the class loader used to load the JDBC driver configurable for the - BasicDatasource. - - - Handle user password changes for InstanceKeyDataSources. - - - Made XADataSource configurable in BasicManagedDataSource. - - - Added PoolableManagedConnection and PoolableManagedConnectionFactory so that - pooled managed connections can unregister themselves from transaction registries, - avoiding resource leaks. - - - Added connectionProperties property to DriverAdapterCPDS. - - - Added a validationQueryTimeout configuration parameter to BasicDataSource - allowing the user to specify a timeout value (in seconds) for connection - validation queries. - - - Added a connectionInitSqls configuration parameter to BasicDataSource - allowing the user to specify a collection of SQL statements to execute - one time when a physical database connection is first opened. - - - PoolableConnectionFactory.makeObject() is no longer synchronized. This - provides improved response times when load spikes at the cost of a - faster rise in database server load. This change was made as a partial - fix for DBCP-212. The synchronization changes in Commons Pool 1.5 complete - the fix for this issue. - - - Reverted DelegatingConnection close to 1.2.2 version to ensure - open statements are closed before the underlying connection is closed. - - - Refactor DelegatingConnection and ManagedConnection enable overridden - equals() and hashcode() to work correctly. - - - Add a DelegatingDatabaseMetaData to track ResultSets returned from - DatabaseMetaData objects. - - - Modified BasicDataSourceFactory to complete initialization of the pool - by creating initialSize connections rather than leaving this to lazy - initialization when the pool is used. - - - Eliminated masked _stmt field in descendents of DelegatingStatement. - - - Modified DBCP sources to support compilation under JDK 1.4-1.6 - using Ant flags to do conditional compilation. - - - Added a static initializer to BasicDatasource that calls - DriverManager.getDrivers() to force initialization before we ever do - anything that might use Class.forName() to load (and register) a JDBC - driver. - - - Eliminated direct System.out calls in AbandonedTrace. - - - Modified DelegatingStatement close to clear open batches. - - - Eliminated unused private "parent" field in AbandonedTrace. - - - Fixed errors handling boolean-valued Reference properties in - InstanceKeyObjectFactory, DriverAdapterCPDS that were causing - testOnBorrow and poolPreparedStatements properties to be incorrectly - set when creating objects from javax.naming.Reference instances. - - - Made private instance fields of AbandonedTrace volatile (parent, - createdBy, lastUsed, createdTime) or final (trace). - - - Narrowed synchronization in AbandonedTrace to resolve an Evictor deadlock. - - - Corrected Javadoc to state that getLoginTimeout and setLoginTimeout are - NOT supported by BasicDataSource. - - - Added Maven 2 pom.xml. Removed a block of code from TestJOCLed that set - the Xerces parser manually. This was to support early JDKs. The 1.3 - version of DBCP requires JDK 1.4+. - - - Added support for pooling managed connections. - - - Added BasicManagedDataSource, extending BasicDataSource. - Also improved extensibility of BasicDataSource by encapsulating - methods to create object pool, connection factory and datasource - instance previously embedded in createDataSource. - - - Changed behavior to allow Connection, Statement, PreparedStatement, - CallableStatement and ResultSet to be closed multiple times. The first - time close is called the resource is closed and any subsequent calls - have no effect. This behavior is required as per the Javadocs for these - classes. Also added tests for closing all types multiple times and - updated any tests that incorrectly assert that a resource can not be - closed more then once. Fixes DBCP-3, DBCP-5, DBCP-23 and DBCP-134. - - - Modified PoolingDataSource, PoolingDriver and DelegatingStatement to - assure that all returned Statements, PreparedStatements, - CallableStatements and ResultSets are wrapped with a delegating object, - which already properly handle the back pointers for Connection and - Statement. Also added tests to to assure that the *same* object used - to create the statement or result set is returned from either - getConnection() or getStatement(). - - - SQLNestedException has been deprecated and will be replaced in DBCP 2.0 with - SQLException and standard Java exception chaining. - - - BasicDataSource.close() now permanently marks the data source as closed, - and no new connections can be obtained from the data source. At close all - idle connections are destroyed and the method returns. As the remaining - active connections are closed, they are destroyed. - - - Eliminated potential sources of NullPointerExceptions in - PoolingConnection. - - - Improved error recovery and listener cleanup in - KeyedCPDSConnectionFactory. Substituted calls to destroyObject with - _pool.invalidateObject on error to ensure pool active count is - decremented on error events. Ensured that events from closed or invalid - connections are ignored and listeners are cleaned up. - - - Fixed error in SharedPoolDataSource causing incorrect passwords to be - stored under certain conditions. - - - Added exception handler to ensure that PooledConnections are not - orphaned when an exception occurs in setUpDefaults or clearWarnings in - InstanceKeyDataSource.getConnection. - - - Made getPool synchronized in PoolableConnectionFactory. - Fixes inconsistent synchronization accessing _pool. - - - Fixed inconsistent synchronization on _rollbackAfterValidation, - _validationQuery and _pool in CPDSConnectionFactory and - KeyedCPDSConnectionFactory by making the first two volatile and making - both getter and setter for _pool synchronized. - - - - - See <a href="changes-report.html#a1.4">DBCP 1.4 Changes </a> for details. Version - 1.3 is identical to 1.4, other than JDBC 4 methods being filtered out of the DBCP 1.3 sources. Changes - Since 1.2.2 are the same for 1.3 and 1.4. - - - - - Add a <i>JNDI How To</i> to the User Guide. - - - DriverManagerConnectionFactory: blank user name and password handling. - - - Broken behaviour for BasicDataSource.setMaxActive(0). - - - BasicDataSource does not work with getConnection(String, String). - - - Enhancements to prepared statement in DriverAdapterCPDS. - - - Better messages and docs for LoginTimeout UnsupportedOperationException. - - - Error in JOCL snippet in org.apache.commons.dbcp package javadoc. - - - Added toString() methods to DelegatingPreparedStatement and DelegatingStatement - - - Changes to make DBCP compile on JDK 1.5 by adding source="1.4" to compiler - arguments (there are compiler errors in JDK 5.0 without this source switch - that cannot be fixed without JDK 5.0-specific syntax). - - - Per-user pooling with Oracle driver and default isolation settings. - - - Error in JOCL document in javadoc. - - - Added toString() method to DelegatingConnection. - - - Add DriverManager.invalidateConnection(). - - - Improved Exception nesting in ConnectionPool. - - - Fix broken website links for examples. - - - Modified PoolableConnection close method to invalidate instance - when invoked on an already closed connection. - - - Inserted null checks to avoid NPE in close operations. - - - Changed getReference method in InstanceKeyDataSource to return a - concrete factory and added implementations of getReference in concrete - subclasses. - - - Inserted null check in close method of SharedPoolDataSource to avoid - NPE when invoked on non-initialized pool. - - - Document fact that true values for testOnBorrow, testOnReturn, testWhileIdle - only have effect when validationQuery is set to a non-null string. - - - Modified activateObject in PoolableConnection to test connection - properties before resetting to defaults. - - - Corrected maxActive documentation in configuration.html. - - - Upgraded dependency to Pool 1.3. - - - Added connection info to SQLException messages when closed connections - (resp stmts) are accessed in DelegatingConnection, DelegatingStatement. - - - Fixed errors in pool parameter documentation and made - 0 value for _maxPreparedStatements in DriverAdapterCPDS behave - like a negative value, to be consistent with documentation - and pool behavior. - - - Made userKeys an instance variable (i.e., not static) - in SharedPoolDataSource. - - - Changed implementation of equals in - PoolingDataSource.PoolGuardConnectionWrapper - to ensure it is reflexive, even when wrapped connections are not - DelegatingConnections. - - - Added rollbackAfterValidation property and code to issue a rollback on a - connection after validation when this property is set to true to eliminate - Oracle driver exceptions. Default property value is false. - - - Removed dependency on Commons Collections by adding collections - 2.1 sources for LRUMap and SequencedHashMap with package scope to - datasources package. - - - Removed synchronization from prepareStatement methods in - PoolingConnection. Synchronization in these methods was causing - deadlocks. No resources other than the prepared statement pool are - accessed by these methods, and the pool methods are synchronized. - Also fixes DBCP-202. - - - - - - See <a href="release-notes-1.2.1.html">DBCP 1.2.1 Release Notes</a> for details. - - - - - - See <a href="release-notes-1.2.html">DBCP 1.2 Release Notes</a> for details. - - - - - - See <a href="release-notes-1.1.html">DBCP 1.1 Release Notes</a> for details. - - - - - - Initial Release - - - - - + + + + + + + + Apache Commons DBCP Release Notes + + + + + + + + ManagedDataSource#close() should declare used exceptions. + + + Add a ConnectionFactory class name setting for BasicDataSource.createConnectionFactory() #33. + + + Add missing Javadocs. + + + + Wrong JMX base name derived in BasicDataSource#updateJmxName. + + + Avoid NPE when calling DriverAdapterCPDS.toString(). + + + java.util.IllegalFormatException while building a message for a SQLFeatureNotSupportedException in Jdbc41Bridge.getObject(ResultSet,String,Class). + + + Fix Javadoc link in README.md #21. + + + + Close ObjectOutputStream before calling toByteArray() on underlying ByteArrayOutputStream #28. + + + Upgrade to JUnit Jupiter #19. + + + Fix tests on Java 11. + + + Update Apache Commons Pool from 2.6.1 to 2.6.2. + + + Add 'jmxName' property to web configuration parameters listing. + + + Update Apache Commons Pool from 2.6.2 to 2.7.0. + + + Make org.apache.commons.dbcp2.AbandonedTrace.removeTrace(AbandonedTrace) null-safe. + + + org.apache.commons.dbcp2.DelegatingStatement.close() should try to close ALL of its result sets even when an exception occurs. + + + org.apache.commons.dbcp2.DelegatingConnection.passivate() should close ALL of its resources even when an exception occurs. + + + org.apache.commons.dbcp2.PoolablePreparedStatement.passivate() should close ALL of its resources even when an exception occurs. + + + org.apache.commons.dbcp2.PoolableCallableStatement.passivate() should close ALL of its resources even when an exception occurs. + + + + Update tests from org.mockito:mockito-core 2.28.2 to 3.0.0. + + + Update tests from H2 1.4.198 to 1.4.199. + + + Update tests from com.h2database:h2 1.4.197 to 1.4.199. + + + Update tests from org.jboss.narayana.jta:narayana-jta 5.9.2.Final to 5.9.5.Final. + + + Update tests from org.jboss.logging:jboss-logging 3.3.2.Final to 3.4.0.Final. + + + Update tests from org.mockito:mockito-core 2.24.0 to 2.28.2. + + + Update tests from org.mockito:mockito-core 2.28.2 to 3.0.0. + + + + + Allow for manual connection eviction. + + + Allow DBCP to register with a TransactionSynchronizationRegistry for XA cases. + + + Make defensive copies of char[] passwords. + + + Do not try to register synchronization when the transaction is no longer active. + + + Do not double returnObject back to the pool if there is a transaction context with a shared connection. + + + Allow DBCP to work with old Java 6/JDBC drivers without throwing AbstractMethodError. + + + Add some toString() methods for debugging (never printing passwords.) + + + BasicManagedDataSource needs to pass the TSR with creating DataSourceXAConnectionFactory. + + + Add getters to some classes. + + + org.apache.commons.dbcp2.DriverManagerConnectionFactory should use a char[] instead of a String to store passwords. + + + Update Apache Commons Pool from 2.6.0 to 2.6.1. + + + + + Update Java requirement from version 7 to 8. + + + Support JDBC 4.2. + + + Support default schema in configuration. + + + Examines 'SQLException's thrown by underlying connections or statements for fatal (disconnection) errors. + + + Change default for fail-fast connections from false to true. + + + Prepared statement keys should take a Connection's schema into account. + + + Increase test coverage. + + + Update Apache Commons Pool from 2.5.0 to 2.6.0. + + + Avoid exceptions when closing a connection in mutli-threaded use case. + + + + + Connection leak during XATransaction in high load. + + + Drop Ant build. + + + Ensure DBCP ConnectionListener can deal with transaction managers which invoke rollback in a separate thread. + + + org.apache.commons.dbcp2.PStmtKey should make copies of given arrays in constructors. + + + Remove duplicate code in org.apache.commons.dbcp2.cpdsadapter.PStmtKeyCPDS. + + + Add support for pooling CallableStatements to the org.apache.commons.dbcp2.cpdsadapter package. + + + Deprecate use of PStmtKeyCPDS in favor of PStmtKey. + + + org.apache.commons.dbcp2.DataSourceConnectionFactory should use a char[] instead of a String to store passwords. + + + org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory should use a char[] instead of a String to store passwords. + + + org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS should use a char[] instead of a String to store passwords. + + + org.apache.commons.dbcp2.datasources.CPDSConnectionFactory should use a char[] instead of a String to store passwords. + + + org.apache.commons.dbcp2.datasources internals should use a char[] instead of a String to store passwords. + + + org.apache.commons.dbcp2.datasources.InstanceKeyDataSourceFactory.closeAll() does not close all. + + + + + AbandonedTrace.getTrace() contains race condition. + + + Avoid javax.management.InstanceNotFoundException on shutdown when a bean is not registered. Closes #9. + + + Make constant public: org.apache.commons.dbcp2.PoolingDriver.URL_PREFIX. + + + DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set. + + + Add API org.apache.commons.dbcp2.datasources.PerUserPoolDataSource.clear(). + + + NPE for org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS.setConnectionProperties(null). + + + The method org.apache.commons.dbcp2.PoolingDriver.getConnectionPool(String) does not tell you which pool name is not registered when it throws an exception. + + + + + Update Apache Commons Pool from 2.4.2 to 2.5.0. + + + OSGi declarations contain multiple import headers for javax.transaction. + + + Wrong parameter name in site documentation for BasicDataSource Configuration Parameters. + + + Add jmxName to properties set by BasicDataSourceFactory. This + enables container-managed pools created from JNDI Resource + definitions to enable JMX by supplying a valid root JMX name. + + + NullPointerException thrown when calling ManagedConnection.isClosed(). + + + InvalidateConnection can result in closed connection returned by getConnection. + + + Complete the fix for DBCP-418, enabling PoolableConnection class to load in environments + (such as GAE) where the JMX ManagementFactory is not available. + + + Add constructor DriverManagerConnectionFactory(String). + + + Ensure that the cacheState setting is used when statement pooling is + disabled. + + + Ensure that setSoftMinEvictableIdleTimeMillis is used when working with + BasicDataSource. + + + Correct the name of the configuration attribute + softMinEvictableIdleTimeMillis. + + + Avoid potential infinite loops when checking if an SQLException is fatal + for a connection or not. + + + Expand the fail-fast for fatal connection errors feature to include + managed connections. + + + Correct a typo in the method name + PoolableConnectionFactory#setMaxOpenPreparedStatements. The old method + remains but is deprecated so not to break clients currently using the + incorrect name. + + + Refactoring to prepare for a future patch to enable pooling of all + prepared and callable statements in PoolingConnection. + + + Ensure that a thread's interrupt status is visible to the caller if the + thread is interrupted during a call to + PoolingDataSource.getConnection(). + + + Make it simpler to extend BasicDataSource to allow sub-classes to + provide custom GenericObjectPool implementations. + + + When using a BasicDataSource, pass changes related to the handling of + abandoned connections to the underlying pool so that the pool + configuration may be updated dynamically. + + + Enable pooling of all prepared and callable statements + inPoolingConnection. + + + + + Updated pool version to 2.4.2. The fix for POOL-300 may cause DBCP + users to see more reports of abandoned connections (if removal and logging + are configured). Prior to the fix for POOL-300, the PrintWriter used to log + abandoned connection stack traces was not being flushed on each log event. + + + Added BasicDataSource abandonedUsageTracking property missing from BasicDataSourceFactory. + + + SharedPoolDataSource getConnection fails when testOnBorrow is set with + a null validation query. + + + Nested connections in a transaction (local) throws null pointer. + + + BasicDataSource does not set disconnectionSql properties on its PoolableConnectionFactory. + + + + + InstanceKeyDataSource discards native SQLException when given password does not match + password used to create the connection. + + + Update Apache Commons Logging to 1.2 from 1.1.3. + + + Correct some Javadoc references to Apache Commons Pool 2 classes that + have changed names since Pool 1.x. + + + Do not ignore the configured custom eviction policy when creating a + BasicDataSource. + + + Added invalidateConnection method to BasicDataSource. + + + Unsuccessful Connection enlistment in XA Transaction ignored by TransactionContext. + + + Made expired connection logging configurable in BasicDataSource. Setting + logExpiredConnections to false suppresses expired connection log messages. + + + Made Datasources implement AutoCloseable. + + + Added fastFailValidation property to PoolableConnection, configurable in + BasicDataSource. When set to true, connections that have previously thrown + fatal disconnection errors will fail validation immediately (no driver calls). + + + Changed BasicDataSource createDataSource method to ensure that initialization + completes before clients get reference to newly created instances. + + + Fixed connection leak when SQLException is thrown while enlisting an XA + transaction. + + + Setting jmxName to null should suppress JMX registration of connection + and statement pools. + + + Eliminated synchronization in BasicDataSource getNumActive, getNumIdle methods. + + + Added property name verification to BasicDataSourceFactory. References including + obsolete or unrecognized properties now generate log messages. + + + + + Small performance improvements when returning connections to the pool. + + + Fixed DelegatingStatement close to ensure closed statements do not retain references + to pooled prepared statements. Due to finalization code added in 2.0, this was causing + pooled prepared statements to be closed by GC while in use by clients. + + + Added check in PoolingDataSource constructor to ensure that the connection factory + and pool are properly linked. + + + Fixed connection leak when managed connections are closed during transactions. + + + Enable PoolableConnection class to load without JMX. + + + + + BasicManagedDataSource - unregister from JMX on close(). + + + Log validation failures of poolable connections. + + + DelegatingStatement.close() fails with NPE if statement is null + + + CPDSConnectionFactory.validateObject(Object) ignores Throwable. + + + Provide a new option (cacheState) to cache current values of autoCommit + and readOnly so database queries are not required for every call to the + associated getters. This option is enabled by default. + + + Removed unnecessary synchronisation in BasicDataSource#createDataSource. + + + The Java package name has been changed from org.apache.commons.dbcp to + org.apache.commons.dbcp2. + + + Update to Commons Pool 2 (based on java.util.concurrent) to provide + pooling functionality. + + + Updated source code for Java 1.6 (added @Override & @Deprecated + annotations). + + + Removed JOCL support. + + + Remove deprecated SQLNestedException. + + + Fix threading issues with accessToUnderlyingConnectionAllowed attribute + of PoolingDriver which is used to support unit testing. + + + BasicDataSource instances are now exposed via JMX. All the configuration + properties are available as is the connection pool and the statement + pools (if statement pooling is enabled). + + + Fix thread safety issues in the SharedPoolDataSource and the + PerUserPoolDataSource. + + + Allow accessToUnderlyingConnectionAllowed to be configured when + configuration takes place via JNDI in a JavaEE container. + + + Fix threading issue when using multiple instances of the + SharedPoolDataSource concurrently. + + + Ensure that the close state of a pooled connection and the underlying + connection is consistent when the underlying connection is closed as a + result of an error condition. + + + Make all mutable fields private. + + + Return BasicDataSource rather than DataSource from + BasicDataSourceFactory so a cast is not required to use BasicDataSource + specific methods. + + + The equals() implementations of the DelegatingXxx classes are now + symmetric. There are some important API changes underlying this fix. + Firstly, two DelegatingXxx instances are no longer considered equal if + they have the same innermost delegate. Secondly, a DelegatingXxx + instance is not considered equal to its innermost delegate. The + getInnermostDelegateInternal() method has been made public (but remains + part of the internal API) to allow classes extending this implementation + to access the innermost delegate when required. + + + Expose the new Pool 2 property evictionPolicyClassName to enable more + sophisticated eviction strategies to be used. + + + Add support for pooling PreparedStatements that use auto-generated keys. + + + Enable JDBC resources that are no longer referenced by client code to be + eligible for garbage collection. + + + Enable DBCP to work with a SecurityManager such that only DBCP needs to + be granted the necessary permissions to communicate with the database. + + + Correct path to Javadoc overview in build.xml. + + + The default values for readOnly, autoCommit and transactionIsolation are + now taken from the JDBC driver. No calls to setReadOnly(), + setAutoCommit() or setTransactionIsolation() will be made for a newly + borrowed connection unless a default is explicitly configured and the + connection is currently using a different setting. + + + Register pooled connections with JMX so that they may be forcibly closed + via JMX if required. + + + Modify SharedPoolDataSource and PerUserPoolDataSource to expose all of + the configuration properties of the underlying connection pool(s). This + represents a significant refactoring of these classes and a number of + property names have changed as a result. + + + Provide an option to control if autoCommit is always set to true when a + connection is returned to the connection pool. + + + Provide an option to control if rollback is called when a connection is + returned to the poll with autoCommit disabled. + + + Provide an option to set the default query timeout. + + + Connection.isValid() should not throw an SQLException if the connection + is closed. + + + Use Connection.isValid() to validate connections unless a validation + query is explicitly configured. Note that this means it is no longer + necessary for a validation query to be specified in order for validation + to take place. When testing with Oracle, this resulted in database + validation being approximately 7 times faster. + + + Add support for validation testing database connections on creation. + + + + + Correct the documentation for the maxOpenPreparedStatements parameter + and review the use of the phrase non-positive throughout the + documentation and javadoc, replacing it with negative where that is the + correct definition to use. + + + Avoid multiple calls to Connection.getAutoCommit() in + PoolableConnectionFactory.passivateObject() as it could be an expensive + call. + + + Use one line per statement for methods with multiple statements rather + than using a single line. + + + Expose all of the AbandonedConfig properties through a BasicDataSource. + + + Correct implementation of DelegatingConnection.isWrapperFor() so it + works correctly with older JDBC drivers. + + + Correct implementation of DelegatingStatement.isWrapperFor(). Also fix + DelegatingDatabaseMetaData.isWrapperFor() and + DelegatingResultSet.isWrapperFor() that had the same problem. + + + LocalXAConnectionFactory does not properly check if Xid is equal to + currentXid when resuming which may result in an XAException. + + + Ensure that the XAConnection is closed when the associated Connection is + closed. + + + Clarify Jaavdoc for isClosed() method of PoolableConnection. + + + Avoid NullPointerException and throw an XAException if an attempt is + made to commit the current transaction for a connection when no + transaction has been started. + + + Using batchUpdate() should not invalidate the PreparedStatement when it + is returned to the pool. + + + Improve documentation for JNDI example using BasicDataSource. + + + + + Exposed GenericObjectPool's softMinEvictableIdleTimeMillis property for + configuration and use by BasicDataSource. + + + Made equals reflexive in DelegatingStatement (and subclasses), DelegatingMetaData, + DelegatingResultSet and PoolingDriver#PoolGuardConnectionWrapper. + + + Modified createDataSource method in BasicDataSource to ensure that GenericObjectPool + Evictor tasks are not started and orphaned when BasicDataSource encounters errors on + initialization. Prior to this fix, when minIdle and timeBetweenEvictionRunsMillis + are both positive, Evictors orphaned by failed initialization can continue to + generate database connection requests. This issue is duplicated by DBCP-339 + and DBCP-93. + + + Changed DelegatingDatabaseMetaData to no longer add itself to the AbandonedTrace + of its parent connection. This was causing excessive memory consumption and was + not necessary, as resultsets created by DelegatingDatabaseMetaData instances are + attached to the parent connection's trace on creation. Also fixes DBCP-352. + + + Modified execute methods of Statement objects to ensure that whenever + a statement is used, the lastUsed property of its parent connection is + updated. + + + Correctly implemented the option to configure the class loader used to load + the JDBC driver. + + + LIFO configuration option has been added to BasicDataSource. When set + to true (the default), the pool acts as a LIFO queue; setting to false + causes connections to enter and exit to pool in FIFO order. + + + Test transitive dependencies brought in by geronimo-transaction created + version conflicts (commons logging and junit). These have been explicitly + excluded in the POM. + + + BasicDataSourceFactory incorrectly used "initConnectSqls" in versions + 1.3 and 1.4 of DBCP as the property name for connectionInitSqls. + Online docs for 1.3/1/4 have been updated to reflect this inconsistency. + The BasicDataSourceFactory property name has been changed to "connectInitSqls" + to match the online docs and the BasicDataSource property name. + + + + + Eliminated poolKeys cache from PerUserPoolDataSource. + + + Eliminated userKeys LRUMap cache from SharedPoolDataSource. + + + Made private fields final where possible. + + + PerUserPoolDataSource.getPooledConnectionAndInfo multi-threading bug. + + + Remove throws clause from method that does not throw an exception. + + + Remove code that catches and ignores Exceptions when calling + PooledConnection.removeConnectionEventListener(ConnectionEventListener) + as the method does not throw any Exceptions. + + + Remove impossible null check. + + + Renamed variables with duplicate names in different scopes. + + + Clarified javadoc for BasicDataSource close() method. + + + Made PoolingConnection pool CallableStatements. When BasicDataSource's + poolPreparedStatements property is true, CallableStatements are now + pooled along with PreparedStatements. The maxOpenPreparedStatements + property limits the combined number of Callable and Prepared statements + that can be in use at a given time. + + + Use an API specific exception for logging abandoned objects to make + scanning the logs for these exceptions simpler and to provide a better + message that includes the creation time of the abandoned object. + + + Ensure Statement.getGeneratedKeys() works correctly with the CPDS + adapter. + + + Removed incorrectly advertised ClassNotFoundException from + JOCLContentHandler.ConstructorDetails.createObject(). + + + Make the class loader used to load the JDBC driver configurable for the + BasicDatasource. + + + Handle user password changes for InstanceKeyDataSources. + + + Made XADataSource configurable in BasicManagedDataSource. + + + Added PoolableManagedConnection and PoolableManagedConnectionFactory so that + pooled managed connections can unregister themselves from transaction registries, + avoiding resource leaks. + + + Added connectionProperties property to DriverAdapterCPDS. + + + Added a validationQueryTimeout configuration parameter to BasicDataSource + allowing the user to specify a timeout value (in seconds) for connection + validation queries. + + + Added a connectionInitSqls configuration parameter to BasicDataSource + allowing the user to specify a collection of SQL statements to execute + one time when a physical database connection is first opened. + + + PoolableConnectionFactory.makeObject() is no longer synchronized. This + provides improved response times when load spikes at the cost of a + faster rise in database server load. This change was made as a partial + fix for DBCP-212. The synchronization changes in Commons Pool 1.5 complete + the fix for this issue. + + + Reverted DelegatingConnection close to 1.2.2 version to ensure + open statements are closed before the underlying connection is closed. + + + Refactor DelegatingConnection and ManagedConnection enable overridden + equals() and hashcode() to work correctly. + + + Add a DelegatingDatabaseMetaData to track ResultSets returned from + DatabaseMetaData objects. + + + Modified BasicDataSourceFactory to complete initialization of the pool + by creating initialSize connections rather than leaving this to lazy + initialization when the pool is used. + + + Eliminated masked _stmt field in descendents of DelegatingStatement. + + + Modified DBCP sources to support compilation under JDK 1.4-1.6 + using Ant flags to do conditional compilation. + + + Added a static initializer to BasicDatasource that calls + DriverManager.getDrivers() to force initialization before we ever do + anything that might use Class.forName() to load (and register) a JDBC + driver. + + + Eliminated direct System.out calls in AbandonedTrace. + + + Modified DelegatingStatement close to clear open batches. + + + Eliminated unused private "parent" field in AbandonedTrace. + + + Fixed errors handling boolean-valued Reference properties in + InstanceKeyObjectFactory, DriverAdapterCPDS that were causing + testOnBorrow and poolPreparedStatements properties to be incorrectly + set when creating objects from javax.naming.Reference instances. + + + Made private instance fields of AbandonedTrace volatile (parent, + createdBy, lastUsed, createdTime) or final (trace). + + + Narrowed synchronization in AbandonedTrace to resolve an Evictor deadlock. + + + Corrected Javadoc to state that getLoginTimeout and setLoginTimeout are + NOT supported by BasicDataSource. + + + Added Maven 2 pom.xml. Removed a block of code from TestJOCLed that set + the Xerces parser manually. This was to support early JDKs. The 1.3 + version of DBCP requires JDK 1.4+. + + + Added support for pooling managed connections. + + + Added BasicManagedDataSource, extending BasicDataSource. + Also improved extensibility of BasicDataSource by encapsulating + methods to create object pool, connection factory and datasource + instance previously embedded in createDataSource. + + + Changed behavior to allow Connection, Statement, PreparedStatement, + CallableStatement and ResultSet to be closed multiple times. The first + time close is called the resource is closed and any subsequent calls + have no effect. This behavior is required as per the Javadocs for these + classes. Also added tests for closing all types multiple times and + updated any tests that incorrectly assert that a resource can not be + closed more then once. Fixes DBCP-3, DBCP-5, DBCP-23 and DBCP-134. + + + Modified PoolingDataSource, PoolingDriver and DelegatingStatement to + assure that all returned Statements, PreparedStatements, + CallableStatements and ResultSets are wrapped with a delegating object, + which already properly handle the back pointers for Connection and + Statement. Also added tests to to assure that the *same* object used + to create the statement or result set is returned from either + getConnection() or getStatement(). + + + SQLNestedException has been deprecated and will be replaced in DBCP 2.0 with + SQLException and standard Java exception chaining. + + + BasicDataSource.close() now permanently marks the data source as closed, + and no new connections can be obtained from the data source. At close all + idle connections are destroyed and the method returns. As the remaining + active connections are closed, they are destroyed. + + + Eliminated potential sources of NullPointerExceptions in + PoolingConnection. + + + Improved error recovery and listener cleanup in + KeyedCPDSConnectionFactory. Substituted calls to destroyObject with + _pool.invalidateObject on error to ensure pool active count is + decremented on error events. Ensured that events from closed or invalid + connections are ignored and listeners are cleaned up. + + + Fixed error in SharedPoolDataSource causing incorrect passwords to be + stored under certain conditions. + + + Added exception handler to ensure that PooledConnections are not + orphaned when an exception occurs in setUpDefaults or clearWarnings in + InstanceKeyDataSource.getConnection. + + + Made getPool synchronized in PoolableConnectionFactory. + Fixes inconsistent synchronization accessing _pool. + + + Fixed inconsistent synchronization on _rollbackAfterValidation, + _validationQuery and _pool in CPDSConnectionFactory and + KeyedCPDSConnectionFactory by making the first two volatile and making + both getter and setter for _pool synchronized. + + + + + See <a href="changes-report.html#a1.4">DBCP 1.4 Changes </a> for details. Version + 1.3 is identical to 1.4, other than JDBC 4 methods being filtered out of the DBCP 1.3 sources. Changes + Since 1.2.2 are the same for 1.3 and 1.4. + + + + + Add a <i>JNDI How To</i> to the User Guide. + + + DriverManagerConnectionFactory: blank user name and password handling. + + + Broken behaviour for BasicDataSource.setMaxActive(0). + + + BasicDataSource does not work with getConnection(String, String). + + + Enhancements to prepared statement in DriverAdapterCPDS. + + + Better messages and docs for LoginTimeout UnsupportedOperationException. + + + Error in JOCL snippet in org.apache.commons.dbcp package javadoc. + + + Added toString() methods to DelegatingPreparedStatement and DelegatingStatement + + + Changes to make DBCP compile on JDK 1.5 by adding source="1.4" to compiler + arguments (there are compiler errors in JDK 5.0 without this source switch + that cannot be fixed without JDK 5.0-specific syntax). + + + Per-user pooling with Oracle driver and default isolation settings. + + + Error in JOCL document in javadoc. + + + Added toString() method to DelegatingConnection. + + + Add DriverManager.invalidateConnection(). + + + Improved Exception nesting in ConnectionPool. + + + Fix broken website links for examples. + + + Modified PoolableConnection close method to invalidate instance + when invoked on an already closed connection. + + + Inserted null checks to avoid NPE in close operations. + + + Changed getReference method in InstanceKeyDataSource to return a + concrete factory and added implementations of getReference in concrete + subclasses. + + + Inserted null check in close method of SharedPoolDataSource to avoid + NPE when invoked on non-initialized pool. + + + Document fact that true values for testOnBorrow, testOnReturn, testWhileIdle + only have effect when validationQuery is set to a non-null string. + + + Modified activateObject in PoolableConnection to test connection + properties before resetting to defaults. + + + Corrected maxActive documentation in configuration.html. + + + Upgraded dependency to Pool 1.3. + + + Added connection info to SQLException messages when closed connections + (resp stmts) are accessed in DelegatingConnection, DelegatingStatement. + + + Fixed errors in pool parameter documentation and made + 0 value for _maxPreparedStatements in DriverAdapterCPDS behave + like a negative value, to be consistent with documentation + and pool behavior. + + + Made userKeys an instance variable (i.e., not static) + in SharedPoolDataSource. + + + Changed implementation of equals in + PoolingDataSource.PoolGuardConnectionWrapper + to ensure it is reflexive, even when wrapped connections are not + DelegatingConnections. + + + Added rollbackAfterValidation property and code to issue a rollback on a + connection after validation when this property is set to true to eliminate + Oracle driver exceptions. Default property value is false. + + + Removed dependency on Commons Collections by adding collections + 2.1 sources for LRUMap and SequencedHashMap with package scope to + datasources package. + + + Removed synchronization from prepareStatement methods in + PoolingConnection. Synchronization in these methods was causing + deadlocks. No resources other than the prepared statement pool are + accessed by these methods, and the pool methods are synchronized. + Also fixes DBCP-202. + + + + + + See <a href="release-notes-1.2.1.html">DBCP 1.2.1 Release Notes</a> for details. + + + + + + See <a href="release-notes-1.2.html">DBCP 1.2 Release Notes</a> for details. + + + + + + See <a href="release-notes-1.1.html">DBCP 1.1 Release Notes</a> for details. + + + + + + Initial Release + + + + + diff -Nru commons-dbcp2-2.6.0/src/conf/eclipse/formatter.xml commons-dbcp2-2.7.0/src/conf/eclipse/formatter.xml --- commons-dbcp2-2.6.0/src/conf/eclipse/formatter.xml 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/conf/eclipse/formatter.xml 2019-07-31 12:46:24.000000000 +0000 @@ -0,0 +1,370 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/AbandonedTrace.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/AbandonedTrace.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/AbandonedTrace.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/AbandonedTrace.java 2019-07-31 12:46:24.000000000 +0000 @@ -155,7 +155,7 @@ final Iterator> iter = traceList.iterator(); while (iter.hasNext()) { final AbandonedTrace traceInList = iter.next().get(); - if (trace.equals(traceInList)) { + if (trace != null && trace.equals(traceInList)) { iter.remove(); break; } else if (traceInList == null) { @@ -165,4 +165,16 @@ } } } + + /** + * Removes this object the source object is tracing. + * + * @param source The object tracing + * @since 2.7.0 + */ + protected void removeThisTrace(final Object source) { + if (source instanceof AbandonedTrace) { + AbandonedTrace.class.cast(source).removeTrace(this); + } + } } diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -87,6 +87,7 @@ private static final String PROP_VALIDATION_QUERY = "validationQuery"; private static final String PROP_VALIDATION_QUERY_TIMEOUT = "validationQueryTimeout"; private static final String PROP_JMX_NAME = "jmxName"; + private static final String PROP_CONNECTION_FACTORY_CLASS_NAME = "connectionFactoryClassName"; /** * The property name for connectionInitSqls. The associated value String must be of the form [query;]* @@ -141,7 +142,8 @@ PROP_REMOVE_ABANDONED_TIMEOUT, PROP_LOG_ABANDONED, PROP_ABANDONED_USAGE_TRACKING, PROP_POOL_PREPARED_STATEMENTS, PROP_MAX_OPEN_PREPARED_STATEMENTS, PROP_CONNECTION_PROPERTIES, PROP_MAX_CONN_LIFETIME_MILLIS, PROP_LOG_EXPIRED_CONNECTIONS, PROP_ROLLBACK_ON_RETURN, PROP_ENABLE_AUTO_COMMIT_ON_RETURN, - PROP_DEFAULT_QUERY_TIMEOUT, PROP_FAST_FAIL_VALIDATION, PROP_DISCONNECTION_SQL_CODES, PROP_JMX_NAME }; + PROP_DEFAULT_QUERY_TIMEOUT, PROP_FAST_FAIL_VALIDATION, PROP_DISCONNECTION_SQL_CODES, PROP_JMX_NAME, + PROP_CONNECTION_FACTORY_CLASS_NAME }; /** * Obsolete properties from DBCP 1.x. with warning strings suggesting new properties. LinkedHashMap will guarantee @@ -548,6 +550,11 @@ dataSource.setDisconnectionSqlCodes(parseList(value, ',')); } + value = properties.getProperty(PROP_CONNECTION_FACTORY_CLASS_NAME); + if (value != null) { + dataSource.setConnectionFactoryClassName(value); + } + // DBCP-215 // Trick to make sure that initialSize connections are created if (dataSource.getInitialSize() > 0) { diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -76,8 +76,6 @@ private static final Log log = LogFactory.getLog(BasicDataSource.class); - // ------------------------------------------------------------- Properties - static { // Attempt to prevent deadlocks - see DBCP - 272 DriverManager.getDrivers(); @@ -108,6 +106,7 @@ } } + @SuppressWarnings("resource") protected static void validateConnectionFactory(final PoolableConnectionFactory connectionFactory) throws Exception { PoolableConnection conn = null; @@ -315,6 +314,11 @@ private volatile int validationQueryTimeoutSeconds = -1; /** + * The fully qualified Java class name of a {@link ConnectionFactory} implementation. + */ + private String connectionFactoryClassName; + + /** * These SQL statements run once after a Connection is created. *

* This property can be used for example to run ALTER SESSION SET NLS_SORT=XCYECH in an Oracle Database only once @@ -380,10 +384,8 @@ * be called before the first connection is retrieved (along with all the other configuration property setters). * Calls to this method after the connection pool has been initialized have no effect. * - * @param name - * Name of the custom connection property - * @param value - * Value of the custom connection property + * @param name Name of the custom connection property + * @param value Value of the custom connection property */ public void addConnectionProperty(final String name, final String value) { connectionProperties.put(name, value); @@ -408,8 +410,7 @@ * exceptions. *

* - * @throws SQLException - * if an error occurs closing idle connections + * @throws SQLException if an error occurs closing idle connections */ @Override public synchronized void close() throws SQLException { @@ -418,12 +419,12 @@ registeredJmxObjectName = null; } closed = true; - final GenericObjectPool oldpool = connectionPool; + final GenericObjectPool oldPool = connectionPool; connectionPool = null; dataSource = null; try { - if (oldpool != null) { - oldpool.close(); + if (oldPool != null) { + oldPool.close(); } } catch (final RuntimeException e) { throw e; @@ -448,7 +449,7 @@ } /** - * 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: *
    *
  1. If a Driver instance has been specified via {@link #setDriver(Driver)} use it
  2. *
  3. If no Driver instance was specified and {@link #driverClassName} is specified that class is loaded using the @@ -458,77 +459,17 @@ * context class loader of the current thread.
  4. *
  5. If a driver still isn't loaded one is loaded via the {@link DriverManager} using the specified {@link #url}. *
+ *

* This method exists so subclasses can replace the implementation class. + *

* * @return A new connection factory. * - * @throws SQLException - * If the connection factort cannot be created + * @throws SQLException 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 ConnectionFactoryFactory.createConnectionFactory(this, DriverFactory.createDriver(this)); } /** @@ -540,8 +481,7 @@ * positive value causes {@link GenericObjectPool}'s eviction timer to be started. *

* - * @param factory - * The factory to use to create new connections for this pool. + * @param factory The factory to use to create new connections for this pool. */ protected void createConnectionPool(final PoolableConnectionFactory factory) { // Create an object pool to contain our active connections @@ -574,8 +514,7 @@ *

* * @return The current internal DataSource or a newly created instance if it has not yet been created. - * @throws SQLException - * if the object pool cannot be created. + * @throws SQLException if the object pool cannot be created. */ protected DataSource createDataSource() throws SQLException { if (closed) { @@ -648,7 +587,8 @@ throw new SQLException("Error preloading the connection pool", e); } - // If timeBetweenEvictionRunsMillis > 0, start the pool's evictor task + // If timeBetweenEvictionRunsMillis > 0, start the pool's evictor + // task startPoolMaintenance(); dataSource = newDataSource; @@ -660,8 +600,7 @@ * Creates the actual data source instance. This method only exists so that subclasses can replace the * implementation class. * - * @throws SQLException - * if unable to create a datasource instance + * @throws SQLException if unable to create a datasource instance * * @return A new DataSource instance */ @@ -674,12 +613,9 @@ /** * Creates an object pool used to provide pooling support for {@link Connection JDBC connections}. * - * @param factory - * the object factory - * @param poolConfig - * the object pool configuration - * @param abandonedConfig - * the abandoned objects configuration + * @param factory the object factory + * @param poolConfig the object pool configuration + * @param abandonedConfig the abandoned objects configuration * @return a non-null instance */ protected GenericObjectPool createObjectPool(final PoolableConnectionFactory factory, @@ -698,10 +634,8 @@ * Creates the PoolableConnectionFactory and attaches it to the connection pool. This method only exists so * subclasses can replace the default implementation. * - * @param driverConnectionFactory - * JDBC connection factory - * @throws SQLException - * if an error occurs creating the PoolableConnectionFactory + * @param driverConnectionFactory JDBC connection factory + * @throws SQLException if an error occurs creating the PoolableConnectionFactory * * @return A new PoolableConnectionFactory configured with the current configuration of this BasicDataSource */ @@ -738,6 +672,17 @@ } /** + * 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. @@ -788,8 +733,7 @@ /** * Creates (if necessary) and return a connection to the database. * - * @throws SQLException - * if a database access error occurs + * @throws SQLException if a database access error occurs * @return a database connection */ @Override @@ -812,24 +756,34 @@ /** * BasicDataSource does NOT support this method. * - * @param user - * Database user on whose behalf the Connection is being made - * @param pass - * The database user's password - * - * @throws UnsupportedOperationException - * always thrown. - * @throws SQLException - * if a database access error occurs + * @param user Database user on whose behalf the Connection is being made + * @param pass The database user's password + * + * @throws UnsupportedOperationException always thrown. + * @throws SQLException if a database access error occurs * @return nothing - always throws UnsupportedOperationException */ @Override public Connection getConnection(final String user, final String pass) throws SQLException { - // This method isn't supported by the PoolingDataSource returned by the createDataSource + // This method isn't supported by the PoolingDataSource returned by the + // createDataSource throw new UnsupportedOperationException("Not supported by BasicDataSource"); } /** + * Returns the ConnectionFactoryClassName that has been configured for use by this pool. + *

+ * Note: This getter only returns the last value set by a call to {@link #setConnectionFactoryClassName(String)}. + *

+ * + * @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. * @@ -856,7 +810,6 @@ return connectionPool; } - // For unit testing Properties getConnectionProperties() { return connectionProperties; } @@ -1096,15 +1049,15 @@ * Calls {@link #createDataSource()}, so has the side effect of initializing the connection pool. *

* - * @throws SQLException - * if a database access error occurs - * @throws UnsupportedOperationException - * If the DataSource implementation does not support the login timeout feature. + * @throws SQLException if a database access error occurs + * @throws UnsupportedOperationException If the DataSource implementation does not support the login timeout + * feature. * @return login timeout in seconds */ @Override public int getLoginTimeout() throws SQLException { - // This method isn't supported by the PoolingDataSource returned by the createDataSource + // This method isn't supported by the PoolingDataSource returned by the + // createDataSource throw new UnsupportedOperationException("Not supported by BasicDataSource"); } @@ -1116,8 +1069,7 @@ * Calls {@link #createDataSource()}, so has the side effect of initializing the connection pool. *

* - * @throws SQLException - * if a database access error occurs + * @throws SQLException if a database access error occurs * @return log writer in use */ @Override @@ -1485,13 +1437,12 @@ * Manually invalidates a connection, effectively requesting the pool to try to close it, remove it from the pool * and reclaim pool capacity. * - * @param connection - * The Connection to invalidate. + * @param connection The Connection to invalidate. * - * @throws IllegalStateException - * if invalidating the connection failed. + * @throws IllegalStateException if invalidating the connection failed. * @since 2.1 */ + @SuppressWarnings("resource") public void invalidateConnection(final Connection connection) throws IllegalStateException { if (connection == null) { return; @@ -1519,15 +1470,6 @@ } /** - * Manually evicts idle connections - */ - 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. @@ -1538,7 +1480,7 @@ } /** - * 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 */ @@ -1548,6 +1490,16 @@ } /** + * Delegates in a null-safe manner to {@link String#isEmpty()}. + * + * @param value the string to test, may be null. + * @return boolean false if value is null, otherwise {@link String#isEmpty()}. + */ + private boolean isEmpty(String value) { + return value == null ? true : value.trim().isEmpty(); + } + + /** * Returns true if we are pooling statements. * * @return true if prepared and callable statements are pooled @@ -1585,6 +1537,20 @@ } } + /** + * Logs the given throwable. + * @param message TODO + * @param throwable the throwable. + * + * @since 2.7.0 + */ + protected void log(String message, Throwable throwable) { + if (logWriter != null) { + logWriter.println(message); + throwable.printStackTrace(logWriter); + } + } + @Override public void postDeregister() { // NO-OP @@ -1619,8 +1585,7 @@ /** * Removes a custom connection property. * - * @param name - * Name of the custom connection property to remove + * @param name Name of the custom connection property to remove * @see #addConnectionProperty(String, String) */ public void removeConnectionProperty(final String name) { @@ -1630,8 +1595,7 @@ /** * Sets the print writer to be used by this configuration to log information on abandoned objects. * - * @param logWriter - * The new log writer + * @param logWriter The new log writer */ public void setAbandonedLogWriter(final PrintWriter logWriter) { if (abandonedConfig == null) { @@ -1649,9 +1613,8 @@ * the connection pool should record a stack trace every time a method is called on a pooled connection and retain * the most recent stack trace to aid debugging of abandoned connections. * - * @param usageTracking - * A value of true will enable the recording of a stack trace on every use of a pooled - * connection + * @param usageTracking A value of true will enable the recording of a stack trace on every use of a + * pooled connection */ public void setAbandonedUsageTracking(final boolean usageTracking) { if (abandonedConfig == null) { @@ -1675,8 +1638,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param allow - * Access to the underlying connection is granted when true. + * @param allow Access to the underlying connection is granted when true. */ public synchronized void setAccessToUnderlyingConnectionAllowed(final boolean allow) { this.accessToUnderlyingConnectionAllowed = allow; @@ -1687,25 +1649,40 @@ * 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 true by default. * - * @param autoCommitOnReturn - * Whether or not connections being returned to the pool will be checked and configured with auto-commit. + * @param autoCommitOnReturn Whether or not connections being returned to the pool will be checked and configured + * with auto-commit. * @since 2.6.0 */ public void setAutoCommitOnReturn(final boolean autoCommitOnReturn) { this.autoCommitOnReturn = autoCommitOnReturn; } + // ----------------------------------------------------- DataSource Methods + /** * Sets the state caching flag. * - * @param cacheState - * The new value for the state caching flag + * @param cacheState The new value for the state caching flag */ public void setCacheState(final boolean cacheState) { this.cacheState = cacheState; } /** + * 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. *

* Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first @@ -1713,14 +1690,13 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param connectionInitSqls - * Collection of SQL statements to execute on connection creation + * @param connectionInitSqls Collection of SQL statements to execute on connection creation */ public void setConnectionInitSqls(final Collection connectionInitSqls) { if (connectionInitSqls != null && connectionInitSqls.size() > 0) { ArrayList newVal = null; for (final String s : connectionInitSqls) { - if (s != null && s.trim().length() > 0) { + if (!isEmpty(s)) { if (newVal == null) { newVal = new ArrayList<>(); } @@ -1733,8 +1709,6 @@ } } - // ----------------------------------------------------- DataSource Methods - /** * Sets the connection properties passed to driver.connect(...). *

@@ -1744,8 +1718,7 @@ * NOTE - The "user" and "password" properties will be added explicitly, so they do not need to be included here. *

* - * @param connectionProperties - * the connection properties used to create new connections + * @param connectionProperties the connection properties used to create new connections */ public void setConnectionProperties(final String connectionProperties) { Objects.requireNonNull(connectionProperties, "connectionProperties is null"); @@ -1759,7 +1732,8 @@ final String value = entry.substring(index + 1); properties.setProperty(name, value); } else { - // no value is empty string which is how java.util.Properties works + // no value is empty string which is how + // java.util.Properties works properties.setProperty(entry, ""); } } @@ -1777,8 +1751,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param defaultAutoCommit - * default auto-commit value + * @param defaultAutoCommit default auto-commit value */ public void setDefaultAutoCommit(final Boolean defaultAutoCommit) { this.defaultAutoCommit = defaultAutoCommit; @@ -1794,14 +1767,13 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param defaultCatalog - * the default catalog + * @param defaultCatalog the default catalog */ public void setDefaultCatalog(final String defaultCatalog) { - if (defaultCatalog != null && defaultCatalog.trim().length() > 0) { - this.defaultCatalog = defaultCatalog; - } else { + if (isEmpty(defaultCatalog)) { this.defaultCatalog = null; + } else { + this.defaultCatalog = defaultCatalog; } } @@ -1809,8 +1781,7 @@ * Sets the default query timeout that will be used for {@link java.sql.Statement Statement}s created from this * connection. null means that the driver default will be used. * - * @param defaultQueryTimeoutSeconds - * The default query timeout in seconds. + * @param defaultQueryTimeoutSeconds The default query timeout in seconds. */ public void setDefaultQueryTimeout(final Integer defaultQueryTimeoutSeconds) { this.defaultQueryTimeoutSeconds = defaultQueryTimeoutSeconds; @@ -1826,8 +1797,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param defaultReadOnly - * default read-only value + * @param defaultReadOnly default read-only value */ public void setDefaultReadOnly(final Boolean defaultReadOnly) { this.defaultReadOnly = defaultReadOnly; @@ -1843,15 +1813,14 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param defaultSchema - * the default catalog + * @param defaultSchema the default catalog * @since 2.5.0 */ public void setDefaultSchema(final String defaultSchema) { - if (defaultSchema != null && defaultSchema.trim().length() > 0) { - this.defaultSchema = defaultSchema; - } else { + if (isEmpty(defaultSchema)) { this.defaultSchema = null; + } else { + this.defaultSchema = defaultSchema; } } @@ -1865,8 +1834,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param defaultTransactionIsolation - * the default transaction isolation state + * @param defaultTransactionIsolation the default transaction isolation state * @see Connection#getTransactionIsolation */ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation) { @@ -1891,15 +1859,14 @@ * setLoginTimeout, getLoginTimeout, getLogWriter}. *

* - * @param disconnectionSqlCodes - * SQL_STATE codes considered to signal fatal conditions + * @param disconnectionSqlCodes SQL_STATE codes considered to signal fatal conditions * @since 2.1 */ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { if (disconnectionSqlCodes != null && disconnectionSqlCodes.size() > 0) { HashSet newVal = null; for (final String s : disconnectionSqlCodes) { - if (s != null && s.trim().length() > 0) { + if (!isEmpty(s)) { if (newVal == null) { newVal = new HashSet<>(); } @@ -1920,8 +1887,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param driver - * The JDBC Driver instance to use for this pool. + * @param driver The JDBC Driver instance to use for this pool. */ public synchronized void setDriver(final Driver driver) { this.driver = driver; @@ -1937,8 +1903,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param driverClassLoader - * the class loader with which to load the JDBC driver + * @param driverClassLoader the class loader with which to load the JDBC driver */ public synchronized void setDriverClassLoader(final ClassLoader driverClassLoader) { this.driverClassLoader = driverClassLoader; @@ -1954,14 +1919,13 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param driverClassName - * the class name of the JDBC driver + * @param driverClassName the class name of the JDBC driver */ public synchronized void setDriverClassName(final String driverClassName) { - if (driverClassName != null && driverClassName.trim().length() > 0) { - this.driverClassName = driverClassName; - } else { + if (isEmpty(driverClassName)) { this.driverClassName = null; + } else { + this.driverClassName = driverClassName; } } @@ -1970,8 +1934,8 @@ * 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 true by default. * - * @param autoCommitOnReturn - * Whether or not connections being returned to the pool will be checked and configured with auto-commit. + * @param autoCommitOnReturn Whether or not connections being returned to the pool will be checked and configured + * with auto-commit. * @deprecated Use {@link #setAutoCommitOnReturn(boolean)}. */ @Deprecated @@ -1982,8 +1946,7 @@ /** * Sets the EvictionPolicy implementation to use with this connection pool. * - * @param evictionPolicyClassName - * The fully qualified class name of the EvictionPolicy implementation + * @param evictionPolicyClassName The fully qualified class name of the EvictionPolicy implementation */ public synchronized void setEvictionPolicyClassName(final String evictionPolicyClassName) { if (connectionPool != null) { @@ -1994,8 +1957,7 @@ /** * @see #getFastFailValidation() - * @param fastFailValidation - * true means connections created by this factory will fast fail validation + * @param fastFailValidation true means connections created by this factory will fast fail validation * @since 2.1 */ public void setFastFailValidation(final boolean fastFailValidation) { @@ -2012,8 +1974,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param initialSize - * the number of connections created when the pool is initialized + * @param initialSize the number of connections created when the pool is initialized */ public synchronized void setInitialSize(final int initialSize) { this.initialSize = initialSize; @@ -2025,8 +1986,7 @@ * this DataSource with JMX and this name is valid this name will be used in preference to any specified by the * other component. * - * @param jmxName - * The JMX name that has been requested for this DataSource + * @param jmxName The JMX name that has been requested for this DataSource */ public void setJmxName(final String jmxName) { this.jmxName = jmxName; @@ -2035,8 +1995,7 @@ /** * Sets the LIFO property. True means the pool behaves as a LIFO queue; false means FIFO. * - * @param lifo - * the new value for the LIFO property + * @param lifo the new value for the LIFO property */ public synchronized void setLifo(final boolean lifo) { this.lifo = lifo; @@ -2046,8 +2005,7 @@ } /** - * @param logAbandoned - * new logAbandoned property value + * @param logAbandoned new logAbandoned property value */ public void setLogAbandoned(final boolean logAbandoned) { if (abandonedConfig == null) { @@ -2065,9 +2023,8 @@ * not log messages are generated when the pool closes connections due to maximum lifetime exceeded. Set this * property to false to suppress log messages when connections expire. * - * @param logExpiredConnections - * Whether or not log messages are generated when the pool closes connections due to maximum lifetime - * exceeded. + * @param logExpiredConnections Whether or not log messages are generated when the pool closes connections due to + * maximum lifetime exceeded. */ public void setLogExpiredConnections(final boolean logExpiredConnections) { this.logExpiredConnections = logExpiredConnections; @@ -2083,16 +2040,15 @@ * Calls {@link #createDataSource()}, so has the side effect of initializing the connection pool. *

* - * @param loginTimeout - * The new login timeout, or zero for no timeout - * @throws UnsupportedOperationException - * If the DataSource implementation does not support the login timeout feature. - * @throws SQLException - * if a database access error occurs + * @param loginTimeout The new login timeout, or zero for no timeout + * @throws UnsupportedOperationException If the DataSource implementation does not support the login timeout + * feature. + * @throws SQLException if a database access error occurs */ @Override public void setLoginTimeout(final int loginTimeout) throws SQLException { - // This method isn't supported by the PoolingDataSource returned by the createDataSource + // This method isn't supported by the PoolingDataSource returned by the + // createDataSource throw new UnsupportedOperationException("Not supported by BasicDataSource"); } @@ -2104,10 +2060,8 @@ * Calls {@link #createDataSource()}, so has the side effect of initializing the connection pool. *

* - * @param logWriter - * The new log writer - * @throws SQLException - * if a database access error occurs + * @param logWriter The new log writer + * @throws SQLException if a database access error occurs */ @Override public void setLogWriter(final PrintWriter logWriter) throws SQLException { @@ -2126,8 +2080,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param maxConnLifetimeMillis - * The maximum permitted lifetime of a connection in milliseconds. + * @param maxConnLifetimeMillis The maximum permitted lifetime of a connection in milliseconds. */ public void setMaxConnLifetimeMillis(final long maxConnLifetimeMillis) { this.maxConnLifetimeMillis = maxConnLifetimeMillis; @@ -2138,8 +2091,7 @@ * return to the pool. * * @see #getMaxIdle() - * @param maxIdle - * the new value for maxIdle + * @param maxIdle the new value for maxIdle */ public synchronized void setMaxIdle(final int maxIdle) { this.maxIdle = maxIdle; @@ -2158,8 +2110,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param maxOpenStatements - * the new maximum number of prepared statements + * @param maxOpenStatements the new maximum number of prepared statements */ public synchronized void setMaxOpenPreparedStatements(final int maxOpenStatements) { this.maxOpenPreparedStatements = maxOpenStatements; @@ -2169,8 +2120,7 @@ * Sets the maximum total number of idle and borrows connections that can be active at the same time. Use a negative * value for no limit. * - * @param maxTotal - * the new value for maxTotal + * @param maxTotal the new value for maxTotal * @see #getMaxTotal() */ public synchronized void setMaxTotal(final int maxTotal) { @@ -2183,8 +2133,7 @@ /** * Sets the MaxWaitMillis property. Use -1 to make the pool wait indefinitely. * - * @param maxWaitMillis - * the new value for MaxWaitMillis + * @param maxWaitMillis the new value for MaxWaitMillis * @see #getMaxWaitMillis() */ public synchronized void setMaxWaitMillis(final long maxWaitMillis) { @@ -2197,8 +2146,7 @@ /** * Sets the {@link #minEvictableIdleTimeMillis} property. * - * @param minEvictableIdleTimeMillis - * the minimum amount of time an object may sit idle in the pool + * @param minEvictableIdleTimeMillis the minimum amount of time an object may sit idle in the pool * @see #minEvictableIdleTimeMillis */ public synchronized void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) { @@ -2208,13 +2156,14 @@ } } + // ------------------------------------------------------ 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 * {@link #timeBetweenEvictionRunsMillis} has a positive value. * - * @param minIdle - * the new value for minIdle + * @param minIdle the new value for minIdle * @see GenericObjectPool#setMinIdle(int) */ public synchronized void setMinIdle(final int minIdle) { @@ -2227,8 +2176,7 @@ /** * Sets the value of the {@link #numTestsPerEvictionRun} property. * - * @param numTestsPerEvictionRun - * the new {@link #numTestsPerEvictionRun} value + * @param numTestsPerEvictionRun the new {@link #numTestsPerEvictionRun} value * @see #numTestsPerEvictionRun */ public synchronized void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) { @@ -2238,8 +2186,6 @@ } } - // ------------------------------------------------------ Protected Methods - /** *

* Sets the {@link #password}. @@ -2250,8 +2196,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param password - * new value for the password + * @param password new value for the password */ public void setPassword(final String password) { this.password = password; @@ -2267,16 +2212,15 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param poolingStatements - * pooling on or off + * @param poolingStatements pooling on or off */ public synchronized void setPoolPreparedStatements(final boolean poolingStatements) { this.poolPreparedStatements = poolingStatements; } /** - * @param removeAbandonedOnBorrow - * true means abandoned connections may be removed when connections are borrowed from the pool. + * @param removeAbandonedOnBorrow true means abandoned connections may be removed when connections are borrowed from + * the pool. * @see #getRemoveAbandonedOnBorrow() */ public void setRemoveAbandonedOnBorrow(final boolean removeAbandonedOnBorrow) { @@ -2291,8 +2235,7 @@ } /** - * @param removeAbandonedOnMaintenance - * true means abandoned connections may be removed on pool maintenance. + * @param removeAbandonedOnMaintenance true means abandoned connections may be removed on pool maintenance. * @see #getRemoveAbandonedOnMaintenance() */ public void setRemoveAbandonedOnMaintenance(final boolean removeAbandonedOnMaintenance) { @@ -2316,8 +2259,7 @@ * {@link #getRemoveAbandonedOnMaintenance()} are false. *

* - * @param removeAbandonedTimeout - * new abandoned timeout in seconds + * @param removeAbandonedTimeout new abandoned timeout in seconds * @see #getRemoveAbandonedTimeout() * @see #getRemoveAbandonedOnBorrow() * @see #getRemoveAbandonedOnMaintenance() @@ -2337,8 +2279,7 @@ * Sets the flag that controls if a connection will be rolled back when it is returned to the pool if auto commit is * not enabled and the connection is not read only. * - * @param rollbackOnReturn - * whether a connection will be rolled back when it is returned to the pool. + * @param rollbackOnReturn whether a connection will be rolled back when it is returned to the pool. */ public void setRollbackOnReturn(final boolean rollbackOnReturn) { this.rollbackOnReturn = rollbackOnReturn; @@ -2348,9 +2289,9 @@ * Sets the minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the * idle object evictor, with the extra condition that at least "minIdle" connections remain in the pool. * - * @param softMinEvictableIdleTimeMillis - * minimum amount of time a connection may sit idle in the pool before it is eligible for eviction, - * assuming there are minIdle idle connections in the pool. + * @param softMinEvictableIdleTimeMillis minimum amount of time a connection may sit idle in the pool before it is + * eligible for eviction, assuming there are minIdle idle connections in the + * pool. * @see #getSoftMinEvictableIdleTimeMillis */ public synchronized void setSoftMinEvictableIdleTimeMillis(final long softMinEvictableIdleTimeMillis) { @@ -2364,8 +2305,7 @@ * Sets the {@link #testOnBorrow} property. This property determines whether or not the pool will validate objects * before they are borrowed from the pool. * - * @param testOnBorrow - * new value for testOnBorrow property + * @param testOnBorrow new value for testOnBorrow property */ public synchronized void setTestOnBorrow(final boolean testOnBorrow) { this.testOnBorrow = testOnBorrow; @@ -2378,8 +2318,7 @@ * Sets the {@link #testOnCreate} property. This property determines whether or not the pool will validate objects * immediately after they are created by the pool * - * @param testOnCreate - * new value for testOnCreate property + * @param testOnCreate new value for testOnCreate property */ public synchronized void setTestOnCreate(final boolean testOnCreate) { this.testOnCreate = testOnCreate; @@ -2392,8 +2331,7 @@ * Sets the testOnReturn property. This property determines whether or not the pool will validate * objects before they are returned to the pool. * - * @param testOnReturn - * new value for testOnReturn property + * @param testOnReturn new value for testOnReturn property */ public synchronized void setTestOnReturn(final boolean testOnReturn) { this.testOnReturn = testOnReturn; @@ -2406,8 +2344,7 @@ * Sets the testWhileIdle property. This property determines whether or not the idle object evictor * will validate connections. * - * @param testWhileIdle - * new value for testWhileIdle property + * @param testWhileIdle new value for testWhileIdle property */ public synchronized void setTestWhileIdle(final boolean testWhileIdle) { this.testWhileIdle = testWhileIdle; @@ -2419,8 +2356,7 @@ /** * Sets the {@link #timeBetweenEvictionRunsMillis} property. * - * @param timeBetweenEvictionRunsMillis - * the new time between evictor runs + * @param timeBetweenEvictionRunsMillis the new time between evictor runs * @see #timeBetweenEvictionRunsMillis */ public synchronized void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) { @@ -2440,8 +2376,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param url - * the new value for the JDBC connection url + * @param url the new value for the JDBC connection url */ public synchronized void setUrl(final String url) { this.url = url; @@ -2457,8 +2392,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param userName - * the new value for the JDBC connection user name + * @param userName the new value for the JDBC connection user name */ public void setUsername(final String userName) { this.userName = userName; @@ -2474,14 +2408,13 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param validationQuery - * the new value for the validation query + * @param validationQuery the new value for the validation query */ public void setValidationQuery(final String validationQuery) { - if (validationQuery != null && validationQuery.trim().length() > 0) { - this.validationQuery = validationQuery; - } else { + if (isEmpty(validationQuery)) { this.validationQuery = null; + } else { + this.validationQuery = validationQuery; } } @@ -2494,8 +2427,7 @@ * setLoginTimeout, getLoginTimeout, getLogWriter. *

* - * @param validationQueryTimeoutSeconds - * new validation query timeout value in seconds + * @param validationQueryTimeoutSeconds new validation query timeout value in seconds */ public void setValidationQueryTimeout(final int validationQueryTimeoutSeconds) { this.validationQueryTimeoutSeconds = validationQueryTimeoutSeconds; @@ -2524,4 +2456,5 @@ config.setJmxNameBase(base.toString()); config.setJmxNamePrefix(Constants.JMX_CONNECTION_POOL_PREFIX); } + } diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/ConnectionFactoryFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -0,0 +1,77 @@ +/* + * 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'"); + } + 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 -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java 2019-07-31 12:46:24.000000000 +0000 @@ -86,6 +86,11 @@ private static final String GET_CONNECTION_CALLED = "A PooledConnection was already requested from this source, " + "further initialization is not allowed."; + static { + // Attempt to prevent deadlocks - see DBCP - 272 + DriverManager.getDrivers(); + } + /** Description */ private String description; @@ -106,13 +111,13 @@ /** Log stream. NOT USED */ private transient PrintWriter logWriter; - // PreparedStatement pool properties private boolean poolPreparedStatements; private int maxIdle = 10; private long timeBetweenEvictionRunsMillis = BaseObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; private int numTestsPerEvictionRun = -1; private int minEvictableIdleTimeMillis = -1; + private int maxPreparedStatements = -1; /** Whether or not getConnection has been called */ @@ -121,11 +126,6 @@ /** Connection properties passed to JDBC Driver */ private Properties connectionProperties; - static { - // Attempt to prevent deadlocks - see DBCP - 272 - DriverManager.getDrivers(); - } - /** * Controls access to the underlying connection */ @@ -138,6 +138,208 @@ } /** + * Throws an IllegalStateException, if a PooledConnection has already been requested. + */ + private void assertInitializationAllowed() throws IllegalStateException { + if (getConnectionCalled) { + throw new IllegalStateException(GET_CONNECTION_CALLED); + } + } + + private boolean getBooleanContentString(RefAddr ra) { + return Boolean.valueOf(getStringContent(ra)).booleanValue(); + } + + /** + * Gets the connection properties passed to the JDBC driver. + * + * @return the JDBC connection properties used when creating connections. + */ + public Properties getConnectionProperties() { + return connectionProperties; + } + + /** + * Gets the value of description. This property is here for use by the code which will deploy this datasource. It is + * not used internally. + * + * @return value of description, may be null. + * @see #setDescription(String) + */ + public String getDescription() { + return description; + } + + /** + * Gets the driver class name. + * + * @return value of driver. + */ + public String getDriver() { + return driver; + } + + private int getIntegerStringContent(final RefAddr ra) { + return Integer.parseInt(getStringContent(ra)); + } + + /** + * Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. NOT + * USED. + */ + @Override + public int getLoginTimeout() { + return loginTimeout; + } + + /** + * Gets the log writer for this data source. NOT USED. + */ + @Override + public PrintWriter getLogWriter() { + return logWriter; + } + + /** + * Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or + * negative for no limit. + * + * @return the value of maxIdle + */ + public int getMaxIdle() { + return this.maxIdle; + } + + /** + * Gets the maximum number of prepared statements. + * + * @return maxPrepartedStatements value + */ + public int getMaxPreparedStatements() { + return maxPreparedStatements; + } + + /** + * Gets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the + * idle object evictor (if any). + * + * @see #setMinEvictableIdleTimeMillis + * @see #setTimeBetweenEvictionRunsMillis + * @return the minimum amount of time a statement may sit idle in the pool. + */ + public int getMinEvictableIdleTimeMillis() { + return minEvictableIdleTimeMillis; + } + + /** + * Gets the number of statements to examine during each run of the idle object evictor thread (if any.) + * + * @see #setNumTestsPerEvictionRun + * @see #setTimeBetweenEvictionRunsMillis + * @return the number of statements to examine during each run of the idle object evictor thread (if any.) + */ + public int getNumTestsPerEvictionRun() { + return numTestsPerEvictionRun; + } + + /** + * Implements {@link ObjectFactory} to create an instance of this class + */ + @Override + public Object getObjectInstance(final Object refObj, final Name name, final Context context, + final Hashtable env) throws Exception { + // The spec says to return null if we can't create an instance + // of the reference + DriverAdapterCPDS cpds = null; + if (refObj instanceof Reference) { + final Reference ref = (Reference) refObj; + if (ref.getClassName().equals(getClass().getName())) { + RefAddr ra = ref.get("description"); + if (isNotEmpty(ra)) { + setDescription(getStringContent(ra)); + } + + ra = ref.get("driver"); + if (isNotEmpty(ra)) { + setDriver(getStringContent(ra)); + } + ra = ref.get("url"); + if (isNotEmpty(ra)) { + setUrl(getStringContent(ra)); + } + ra = ref.get(KEY_USER); + if (isNotEmpty(ra)) { + setUser(getStringContent(ra)); + } + ra = ref.get(KEY_PASSWORD); + if (isNotEmpty(ra)) { + setPassword(getStringContent(ra)); + } + + ra = ref.get("poolPreparedStatements"); + if (isNotEmpty(ra)) { + setPoolPreparedStatements(getBooleanContentString(ra)); + } + ra = ref.get("maxIdle"); + if (isNotEmpty(ra)) { + setMaxIdle(getIntegerStringContent(ra)); + } + + ra = ref.get("timeBetweenEvictionRunsMillis"); + if (isNotEmpty(ra)) { + setTimeBetweenEvictionRunsMillis(getIntegerStringContent(ra)); + } + + ra = ref.get("numTestsPerEvictionRun"); + if (isNotEmpty(ra)) { + setNumTestsPerEvictionRun(getIntegerStringContent(ra)); + } + + ra = ref.get("minEvictableIdleTimeMillis"); + if (isNotEmpty(ra)) { + setMinEvictableIdleTimeMillis(getIntegerStringContent(ra)); + } + ra = ref.get("maxPreparedStatements"); + if (isNotEmpty(ra)) { + setMaxPreparedStatements(getIntegerStringContent(ra)); + } + + ra = ref.get("accessToUnderlyingConnectionAllowed"); + if (isNotEmpty(ra)) { + setAccessToUnderlyingConnectionAllowed(getBooleanContentString(ra)); + } + + cpds = this; + } + } + return cpds; + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new SQLFeatureNotSupportedException(); + } + + /** + * Gets the value of password for the default user. + * + * @return value of password. + */ + public String getPassword() { + return Utils.toString(userPassword); + } + + /** + * Gets the value of password for the default user. + * + * @return value of password. + * @since 2.4.0 + */ + public char[] getPasswordCharArray() { + return userPassword; + } + + /** * Attempts to establish a database connection using the default user and password. */ @Override @@ -146,7 +348,7 @@ } /** - * Attempt to establish a database connection. + * Attempts to establish a database connection. * * @param pooledUserName * name to be used for the connection @@ -208,16 +410,8 @@ return pooledConnection; } - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new SQLFeatureNotSupportedException(); - } - - // ---------------------------------------------------------------------- - // Referenceable implementation - /** - * Referenceable implementation. + * Implements {@link Referenceable}. */ @Override public Reference getReference() throws NamingException { @@ -243,256 +437,110 @@ return ref; } - // ---------------------------------------------------------------------- - // ObjectFactory implementation - - /** - * implements ObjectFactory to create an instance of this class - */ - @Override - public Object getObjectInstance(final Object refObj, final Name name, final Context context, - final Hashtable env) throws Exception { - // The spec says to return null if we can't create an instance - // of the reference - DriverAdapterCPDS cpds = null; - if (refObj instanceof Reference) { - final Reference ref = (Reference) refObj; - if (ref.getClassName().equals(getClass().getName())) { - RefAddr ra = ref.get("description"); - if (ra != null && ra.getContent() != null) { - setDescription(ra.getContent().toString()); - } - - ra = ref.get("driver"); - if (ra != null && ra.getContent() != null) { - setDriver(ra.getContent().toString()); - } - ra = ref.get("url"); - if (ra != null && ra.getContent() != null) { - setUrl(ra.getContent().toString()); - } - ra = ref.get(KEY_USER); - if (ra != null && ra.getContent() != null) { - setUser(ra.getContent().toString()); - } - ra = ref.get(KEY_PASSWORD); - if (ra != null && ra.getContent() != null) { - setPassword(ra.getContent().toString()); - } - - ra = ref.get("poolPreparedStatements"); - if (ra != null && ra.getContent() != null) { - setPoolPreparedStatements(Boolean.valueOf(ra.getContent().toString()).booleanValue()); - } - ra = ref.get("maxIdle"); - if (ra != null && ra.getContent() != null) { - setMaxIdle(Integer.parseInt(ra.getContent().toString())); - } - - ra = ref.get("timeBetweenEvictionRunsMillis"); - if (ra != null && ra.getContent() != null) { - setTimeBetweenEvictionRunsMillis(Integer.parseInt(ra.getContent().toString())); - } - - ra = ref.get("numTestsPerEvictionRun"); - if (ra != null && ra.getContent() != null) { - setNumTestsPerEvictionRun(Integer.parseInt(ra.getContent().toString())); - } - - ra = ref.get("minEvictableIdleTimeMillis"); - if (ra != null && ra.getContent() != null) { - setMinEvictableIdleTimeMillis(Integer.parseInt(ra.getContent().toString())); - } - ra = ref.get("maxPreparedStatements"); - if (ra != null && ra.getContent() != null) { - setMaxPreparedStatements(Integer.parseInt(ra.getContent().toString())); - } - - ra = ref.get("accessToUnderlyingConnectionAllowed"); - if (ra != null && ra.getContent() != null) { - setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(ra.getContent().toString()).booleanValue()); - } - - cpds = this; - } - } - return cpds; - } - - /** - * Throws an IllegalStateException, if a PooledConnection has already been requested. - */ - private void assertInitializationAllowed() throws IllegalStateException { - if (getConnectionCalled) { - throw new IllegalStateException(GET_CONNECTION_CALLED); - } + private String getStringContent(RefAddr ra) { + return ra.getContent().toString(); } - // ---------------------------------------------------------------------- - // Properties - /** - * Gets the connection properties passed to the JDBC driver. - * - * @return the JDBC connection properties used when creating connections. - */ - public Properties getConnectionProperties() { - return connectionProperties; - } - - /** - *

- * Sets the connection properties passed to the JDBC driver. - *

- * - *

- * If props contains "user" and/or "password" properties, the corresponding instance properties are - * set. If these properties are not present, they are filled in using {@link #getUser()}, {@link #getPassword()} - * when {@link #getPooledConnection()} is called, or using the actual parameters to the method call when - * {@link #getPooledConnection(String, String)} is called. Calls to {@link #setUser(String)} or - * {@link #setPassword(String)} overwrite the values of these properties if connectionProperties is not - * null. - *

- * - * @param props - * Connection properties to use when creating new connections. - * @throws IllegalStateException - * if {@link #getPooledConnection()} has been called - */ - public void setConnectionProperties(final Properties props) { - assertInitializationAllowed(); - connectionProperties = props; - if (connectionProperties != null) { - if (connectionProperties.containsKey(KEY_USER)) { - setUser(connectionProperties.getProperty(KEY_USER)); - } - if (connectionProperties.containsKey(KEY_PASSWORD)) { - setPassword(connectionProperties.getProperty(KEY_PASSWORD)); - } - } - } - - /** - * Gets the value of description. This property is here for use by the code which will deploy this datasource. It is - * not used internally. - * - * @return value of description, may be null. - * @see #setDescription(String) - */ - public String getDescription() { - return description; - } - - /** - * Sets the value of description. This property is here for use by the code which will deploy this datasource. It is - * not used internally. - * - * @param v - * Value to assign to description. - */ - public void setDescription(final String v) { - this.description = v; - } - - /** - * Gets the value of password for the default user. - * - * @return value of password. - * @since 2.4.0 - */ - public char[] getPasswordCharArray() { - return userPassword; - } - - /** - * Gets the value of password for the default user. + * Gets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no + * idle object evictor thread will be run. * - * @return value of password. + * @return the value of the evictor thread timer + * @see #setTimeBetweenEvictionRunsMillis(long) */ - public String getPassword() { - return Utils.toString(userPassword); + public long getTimeBetweenEvictionRunsMillis() { + return timeBetweenEvictionRunsMillis; } /** - * Sets the value of password for the default user. + * Gets the value of url used to locate the database for this datasource. * - * @param userPassword - * Value to assign to password. - * @throws IllegalStateException - * if {@link #getPooledConnection()} has been called + * @return value of url. */ - public void setPassword(final char[] userPassword) { - assertInitializationAllowed(); - this.userPassword = Utils.clone(userPassword); - update(connectionProperties, KEY_PASSWORD, Utils.toString(this.userPassword)); + public String getUrl() { + return url; } /** - * Sets the value of password for the default user. + * Gets the value of default user (login or user name). * - * @param userPassword - * Value to assign to password. - * @throws IllegalStateException - * if {@link #getPooledConnection()} has been called + * @return value of user. */ - public void setPassword(final String userPassword) { - assertInitializationAllowed(); - this.userPassword = Utils.toCharArray(userPassword); - update(connectionProperties, KEY_PASSWORD, userPassword); + public String getUser() { + return userName; } /** - * Gets the value of url used to locate the database for this datasource. + * Returns the value of the accessToUnderlyingConnectionAllowed property. * - * @return value of url. + * @return true if access to the underlying is allowed, false otherwise. */ - public String getUrl() { - return url; + public synchronized boolean isAccessToUnderlyingConnectionAllowed() { + return this.accessToUnderlyingConnectionAllowed; + } + + private boolean isNotEmpty(RefAddr ra) { + return ra != null && ra.getContent() != null; } /** - * Sets the value of URL string used to locate the database for this datasource. + * Whether to toggle the pooling of PreparedStatements * - * @param v - * Value to assign to url. - * @throws IllegalStateException - * if {@link #getPooledConnection()} has been called + * @return value of poolPreparedStatements. */ - public void setUrl(final String v) { - assertInitializationAllowed(); - this.url = v; + public boolean isPoolPreparedStatements() { + return poolPreparedStatements; } /** - * Gets the value of default user (login or user name). + * Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to + * the underlying connection. (Default: false) * - * @return value of user. + * @param allow + * Access to the underlying connection is granted when true. */ - public String getUser() { - return userName; + public synchronized void setAccessToUnderlyingConnectionAllowed(final boolean allow) { + this.accessToUnderlyingConnectionAllowed = allow; } /** - * Sets the value of default user (login or user name). + * Sets the connection properties passed to the JDBC driver. + *

+ * If props contains "user" and/or "password" properties, the corresponding instance properties are + * set. If these properties are not present, they are filled in using {@link #getUser()}, {@link #getPassword()} + * when {@link #getPooledConnection()} is called, or using the actual parameters to the method call when + * {@link #getPooledConnection(String, String)} is called. Calls to {@link #setUser(String)} or + * {@link #setPassword(String)} overwrite the values of these properties if connectionProperties is not + * null. + *

* - * @param v - * Value to assign to user. + * @param props + * Connection properties to use when creating new connections. * @throws IllegalStateException * if {@link #getPooledConnection()} has been called */ - public void setUser(final String v) { + public void setConnectionProperties(final Properties props) { assertInitializationAllowed(); - this.userName = v; - update(connectionProperties, KEY_USER, v); + connectionProperties = props; + if (connectionProperties != null) { + if (connectionProperties.containsKey(KEY_USER)) { + setUser(connectionProperties.getProperty(KEY_USER)); + } + if (connectionProperties.containsKey(KEY_PASSWORD)) { + setPassword(connectionProperties.getProperty(KEY_PASSWORD)); + } + } } /** - * Gets the driver class name. + * Sets the value of description. This property is here for use by the code which will deploy this datasource. It is + * not used internally. * - * @return value of driver. + * @param v + * Value to assign to description. */ - public String getDriver() { - return driver; + public void setDescription(final String v) { + this.description = v; } /** @@ -514,23 +562,6 @@ } /** - * Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. NOT - * USED. - */ - @Override - public int getLoginTimeout() { - return loginTimeout; - } - - /** - * Gets the log writer for this data source. NOT USED. - */ - @Override - public PrintWriter getLogWriter() { - return logWriter; - } - - /** * Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. NOT * USED. */ @@ -547,41 +578,6 @@ logWriter = out; } - // ------------------------------------------------------------------ - // PreparedStatement pool properties - - /** - * Flag to toggle the pooling of PreparedStatements - * - * @return value of poolPreparedStatements. - */ - public boolean isPoolPreparedStatements() { - return poolPreparedStatements; - } - - /** - * Flag to toggle the pooling of PreparedStatements - * - * @param poolPreparedStatements - * true to pool statements. - * @throws IllegalStateException - * if {@link #getPooledConnection()} has been called - */ - public void setPoolPreparedStatements(final boolean poolPreparedStatements) { - assertInitializationAllowed(); - this.poolPreparedStatements = poolPreparedStatements; - } - - /** - * Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or - * negative for no limit. - * - * @return the value of maxIdle - */ - public int getMaxIdle() { - return this.maxIdle; - } - /** * Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or * negative for no limit. @@ -597,41 +593,29 @@ } /** - * Gets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no - * idle object evictor thread will be run. + * Sets the maximum number of prepared statements. * - * @return the value of the evictor thread timer - * @see #setTimeBetweenEvictionRunsMillis(long) + * @param maxPreparedStatements + * the new maximum number of prepared statements */ - public long getTimeBetweenEvictionRunsMillis() { - return timeBetweenEvictionRunsMillis; + public void setMaxPreparedStatements(final int maxPreparedStatements) { + this.maxPreparedStatements = maxPreparedStatements; } /** - * Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no - * idle object evictor thread will be run. + * Sets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the + * idle object evictor (if any). When non-positive, no objects will be evicted from the pool due to idle time alone. * - * @param timeBetweenEvictionRunsMillis - * The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, - * no idle object evictor thread will be run. - * @see #getTimeBetweenEvictionRunsMillis() + * @param minEvictableIdleTimeMillis + * minimum time to set (in ms) + * @see #getMinEvictableIdleTimeMillis() + * @see #setTimeBetweenEvictionRunsMillis(long) * @throws IllegalStateException * if {@link #getPooledConnection()} has been called */ - public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) { + public void setMinEvictableIdleTimeMillis(final int minEvictableIdleTimeMillis) { assertInitializationAllowed(); - this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; - } - - /** - * Gets the number of statements to examine during each run of the idle object evictor thread (if any.) - * - * @see #setNumTestsPerEvictionRun - * @see #setTimeBetweenEvictionRunsMillis - * @return the number of statements to examine during each run of the idle object evictor thread (if any.) - */ - public int getNumTestsPerEvictionRun() { - return numTestsPerEvictionRun; + this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; } /** @@ -655,80 +639,87 @@ } /** - * Gets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the - * idle object evictor (if any). + * Sets the value of password for the default user. * - * @see #setMinEvictableIdleTimeMillis - * @see #setTimeBetweenEvictionRunsMillis - * @return the minimum amount of time a statement may sit idle in the pool. + * @param userPassword + * Value to assign to password. + * @throws IllegalStateException + * if {@link #getPooledConnection()} has been called */ - public int getMinEvictableIdleTimeMillis() { - return minEvictableIdleTimeMillis; + public void setPassword(final char[] userPassword) { + assertInitializationAllowed(); + this.userPassword = Utils.clone(userPassword); + update(connectionProperties, KEY_PASSWORD, Utils.toString(this.userPassword)); } /** - * Sets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the - * idle object evictor (if any). When non-positive, no objects will be evicted from the pool due to idle time alone. + * Sets the value of password for the default user. * - * @param minEvictableIdleTimeMillis - * minimum time to set (in ms) - * @see #getMinEvictableIdleTimeMillis() - * @see #setTimeBetweenEvictionRunsMillis(long) + * @param userPassword + * Value to assign to password. * @throws IllegalStateException * if {@link #getPooledConnection()} has been called */ - public void setMinEvictableIdleTimeMillis(final int minEvictableIdleTimeMillis) { + public void setPassword(final String userPassword) { assertInitializationAllowed(); - this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; + this.userPassword = Utils.toCharArray(userPassword); + update(connectionProperties, KEY_PASSWORD, userPassword); } /** - * Returns the value of the accessToUnderlyingConnectionAllowed property. + * Whether to toggle the pooling of PreparedStatements * - * @return true if access to the underlying is allowed, false otherwise. + * @param poolPreparedStatements + * true to pool statements. + * @throws IllegalStateException + * if {@link #getPooledConnection()} has been called */ - public synchronized boolean isAccessToUnderlyingConnectionAllowed() { - return this.accessToUnderlyingConnectionAllowed; + public void setPoolPreparedStatements(final boolean poolPreparedStatements) { + assertInitializationAllowed(); + this.poolPreparedStatements = poolPreparedStatements; } /** - * Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to - * the underlying connection. (Default: false) + * Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no + * idle object evictor thread will be run. * - * @param allow - * Access to the underlying connection is granted when true. + * @param timeBetweenEvictionRunsMillis + * The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, + * no idle object evictor thread will be run. + * @see #getTimeBetweenEvictionRunsMillis() + * @throws IllegalStateException + * if {@link #getPooledConnection()} has been called */ - public synchronized void setAccessToUnderlyingConnectionAllowed(final boolean allow) { - this.accessToUnderlyingConnectionAllowed = allow; + public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) { + assertInitializationAllowed(); + this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; } /** - * Gets the maximum number of prepared statements. + * Sets the value of URL string used to locate the database for this datasource. * - * @return maxPrepartedStatements value + * @param v + * Value to assign to url. + * @throws IllegalStateException + * if {@link #getPooledConnection()} has been called */ - public int getMaxPreparedStatements() { - return maxPreparedStatements; + public void setUrl(final String v) { + assertInitializationAllowed(); + this.url = v; } /** - * Sets the maximum number of prepared statements. + * Sets the value of default user (login or user name). * - * @param maxPreparedStatements - * the new maximum number of prepared statements + * @param v + * Value to assign to user. + * @throws IllegalStateException + * if {@link #getPooledConnection()} has been called */ - public void setMaxPreparedStatements(final int maxPreparedStatements) { - this.maxPreparedStatements = maxPreparedStatements; - } - - private void update(final Properties properties, final String key, final String value) { - if (properties != null) { - if (value == null) { - properties.remove(key); - } else { - properties.setProperty(key, value); - } - } + public void setUser(final String v) { + assertInitializationAllowed(); + this.userName = v; + update(connectionProperties, KEY_USER, v); } /** @@ -765,7 +756,7 @@ builder.append(", connectionProperties="); Properties tmpProps = connectionProperties; final String pwdKey = "password"; - if (connectionProperties.contains(pwdKey)) { + if (connectionProperties != null && connectionProperties.contains(pwdKey)) { tmpProps = (Properties) connectionProperties.clone(); tmpProps.remove(pwdKey); } @@ -775,4 +766,14 @@ builder.append("]"); return builder.toString(); } + + private void update(final Properties properties, final String key, final String value) { + if (properties != null && key != null) { + if (value == null) { + properties.remove(key); + } else { + properties.setProperty(key, value); + } + } + } } diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java 2019-07-31 12:46:24.000000000 +0000 @@ -181,6 +181,10 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @return a {@link PStmtKey} for the given arguments. */ protected PStmtKey createKey(final String sql) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull()); @@ -188,6 +192,13 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param autoGeneratedKeys + * A flag indicating whether auto-generated keys should be returned; one of + * Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final int autoGeneratedKeys) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull(), autoGeneratedKeys); @@ -195,6 +206,13 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param columnIndexes + * An array of column indexes indicating the columns that should be returned from the inserted row or + * rows. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final int columnIndexes[]) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull(), columnIndexes); @@ -202,6 +220,16 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param resultSetType + * A result set type; one of ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE. + * @param resultSetConcurrency + * A concurrency type; one of ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull(), resultSetType, @@ -210,6 +238,19 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param resultSetType + * a result set type; one of ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE. + * @param resultSetConcurrency + * A concurrency type; one of ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE + * @param resultSetHoldability + * One of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT + * or ResultSet.CLOSE_CURSORS_AT_COMMIT. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { @@ -220,6 +261,20 @@ /** * Creates a {@link PStmtKey} for the given arguments. * + * @param sql + * The SQL statement. + * @param resultSetType + * a result set type; one of ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE + * @param resultSetConcurrency + * A concurrency type; one of ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE. + * @param resultSetHoldability + * One of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT + * or ResultSet.CLOSE_CURSORS_AT_COMMIT. + * @param statementType + * The SQL statement type, prepared or callable. + * @return a key to uniquely identify a prepared statement. * @since 2.4.0 */ protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency, @@ -231,6 +286,17 @@ /** * Creates a {@link PStmtKey} for the given arguments. * + * @param sql + * The SQL statement. + * @param resultSetType + * A result set type; one of ResultSet.TYPE_FORWARD_ONLY, + * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE. + * @param resultSetConcurrency + * A concurrency type; one of ResultSet.CONCUR_READ_ONLY or + * ResultSet.CONCUR_UPDATABLE. + * @param statementType + * The SQL statement type, prepared or callable. + * @return a key to uniquely identify a prepared statement. * @since 2.4.0 */ protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency, @@ -241,6 +307,12 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param statementType + * The SQL statement type, prepared or callable. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final StatementType statementType) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull(), statementType); @@ -248,6 +320,12 @@ /** * Creates a {@link PStmtKey} for the given arguments. + * + * @param sql + * The SQL statement. + * @param columnNames + * An array of column names indicating the columns that should be returned from the inserted row or rows. + * @return a key to uniquely identify a prepared statement. */ protected PStmtKey createKey(final String sql, final String columnNames[]) { return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), getSchemaOrNull(), columnNames); @@ -361,6 +439,9 @@ /** * Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original. + * @param sql + * The SQL statement. + * @return the normalized SQL statement. */ protected String normalizeSQL(final String sql) { return sql.trim(); diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSourceFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -120,7 +120,7 @@ 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 -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -98,7 +98,7 @@ /** 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 */ @@ -146,6 +146,8 @@ /** * 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) { @@ -520,8 +522,8 @@ } /** - * 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 +532,8 @@ } /** - * 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 +551,8 @@ } /** - * 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 +561,8 @@ } /** - * 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 -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -34,6 +34,7 @@ import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -87,19 +88,20 @@ /** * Returns a string representation of the metadata associated with the innermost delegate connection. */ + @SuppressWarnings("resource") @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,19 +109,14 @@ sb.append(meta.getUserName()); sb.append(", "); sb.append(meta.getDriverName()); - s = sb.toString(); + str = sb.toString(); } } } catch (final SQLException ex) { // Ignore } } - - if (s == null) { - s = super.toString(); - } - - return s; + return str != null ? str : super.toString(); } /** @@ -142,6 +139,7 @@ * connection to compare innermost delegate with * @return true if innermost delegate equals c */ + @SuppressWarnings("resource") public boolean innermostDelegateEquals(final Connection c) { final Connection innerCon = getInnermostDelegateInternal(); if (innerCon == null) { @@ -174,15 +172,16 @@ * * @return innermost delegate. */ + @SuppressWarnings("resource") 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; } /** @@ -251,6 +250,18 @@ throw e; } + /** + * Handles the given {@code SQLException}. + * + * @param The throwable type. + * @param e The SQLException + * @return the given {@code SQLException} + * @since 2.7.0 + */ + protected T handleExceptionNoThrow(final T e) { + return e; + } + private void initializeStatement(final DelegatingStatement ds) throws SQLException { if (defaultQueryTimeoutSeconds != null && defaultQueryTimeoutSeconds.intValue() != ds.getQueryTimeout()) { ds.setQueryTimeout(defaultQueryTimeoutSeconds.intValue()); @@ -606,23 +617,35 @@ } protected void passivate() throws SQLException { - // The JDBC spec requires that a Connection close any open + // The JDBC specification requires that a Connection close any open // Statement's when it is closed. // DBCP-288. Not all the traced objects will be statements final List traces = getTrace(); - if (traces != null && traces.size() > 0) { + if (traces != null && !traces.isEmpty()) { + final List thrown = new ArrayList<>(); final Iterator traceIter = traces.iterator(); while (traceIter.hasNext()) { final Object trace = traceIter.next(); if (trace instanceof Statement) { - ((Statement) trace).close(); + try { + ((Statement) trace).close(); + } catch (Exception e) { + thrown.add(e); + } } else if (trace instanceof ResultSet) { // DBCP-265: Need to close the result sets that are // generated via DatabaseMetaData - ((ResultSet) trace).close(); + try { + ((ResultSet) trace).close(); + } catch (Exception e) { + thrown.add(e); + } } } clearTrace(); + if (!thrown.isEmpty()) { + throw new SQLExceptionList(thrown); + } } setLastUsed(0); } diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java 2019-07-31 12:46:24.000000000 +0000 @@ -186,11 +186,11 @@ public void close() throws SQLException { try { if (statement != null) { - ((AbandonedTrace) statement).removeTrace(this); + removeThisTrace(statement); statement = null; } if (connection != null) { - ((AbandonedTrace) connection).removeTrace(this); + removeThisTrace(connection); connection = null; } resultSet.close(); diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.Statement; +import java.util.ArrayList; import java.util.List; /** @@ -125,35 +126,53 @@ if (isClosed()) { return; } + final List thrown = new ArrayList<>(); try { - try { - if (connection != null) { - connection.removeTrace(this); - connection = null; - } + if (connection != null) { + connection.removeTrace(this); + connection = null; + } - // The JDBC spec requires that a statement close any open - // ResultSet's when it is closed. - // FIXME The PreparedStatement we're wrapping should handle this for us. - // See bug 17301 for what could happen when ResultSets are closed twice. - final List resultSets = getTrace(); - if (resultSets != null) { - final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]); - for (final ResultSet element : set) { - element.close(); + // The JDBC spec requires that a statement close any open + // ResultSet's when it is closed. + // FIXME The PreparedStatement we're wrapping should handle this for us. + // See bug 17301 for what could happen when ResultSets are closed twice. + final List resultSetList = getTrace(); + if (resultSetList != null) { + final int size = resultSetList.size(); + final ResultSet[] resultSets = resultSetList.toArray(new ResultSet[size]); + for (final ResultSet resultSet : resultSets) { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + if (connection != null) { + // Does not rethrow e. + connection.handleExceptionNoThrow(e); + } + thrown.add(e); + } } - clearTrace(); } - - if (statement != null) { + clearTrace(); + } + if (statement != null) { + try { statement.close(); + } catch (Exception e) { + if (connection != null) { + // Does not rethrow e. + connection.handleExceptionNoThrow(e); + } + thrown.add(e); } - } catch (final SQLException e) { - handleException(e); } } finally { closed = true; statement = null; + if (!thrown.isEmpty()) { + throw new SQLExceptionList(thrown); + } } } @@ -615,7 +634,7 @@ } /* - * Note was protected prior to JDBC 4 + * Note: This method was protected prior to JDBC 4. */ @Override public boolean isClosed() throws SQLException { diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DriverConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -29,7 +29,9 @@ public class DriverConnectionFactory implements ConnectionFactory { private final String connectionString; + private final Driver driver; + private final Properties properties; /** diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DriverFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DriverFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/DriverFactory.java 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/DriverFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -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; + } + +} diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/Jdbc41Bridge.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/Jdbc41Bridge.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/Jdbc41Bridge.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/Jdbc41Bridge.java 2019-07-31 12:46:24.000000000 +0000 @@ -304,7 +304,7 @@ return (T) resultSet.getURL(columnLabel); } throw new SQLFeatureNotSupportedException( - String.format("resultSet=%s, columnLabel=%,d, type=%s", resultSet, columnLabel, type)); + String.format("resultSet=%s, columnLabel=%s, type=%s", resultSet, columnLabel, type)); } } diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -190,7 +190,7 @@ } try { - xaDataSourceInstance = (XADataSource) xaDataSourceClass.newInstance(); + xaDataSourceInstance = (XADataSource) xaDataSourceClass.getConstructor().newInstance(); } catch (final Exception t) { final String message = "Cannot create XA data source of class '" + xaDataSource + "'"; throw new SQLException(message, t); diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/ManagedDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -65,6 +65,10 @@ } /** + * Gets the transaction registry. + * + * @return The transaction registry. + * @see #setTransactionRegistry(TransactionRegistry) * @since 2.6.0 */ public TransactionRegistry getTransactionRegistry() { diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -29,9 +29,9 @@ import org.apache.commons.dbcp2.PoolingConnection; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.PooledObject; +import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; -import org.apache.commons.pool2.impl.DefaultPooledObject; /** * A {@link PoolableConnectionFactory} that creates {@link PoolableManagedConnection}s. diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/ObjectNameWrapper.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/ObjectNameWrapper.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/ObjectNameWrapper.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/ObjectNameWrapper.java 2019-07-31 12:46:24.000000000 +0000 @@ -18,6 +18,7 @@ package org.apache.commons.dbcp2; import java.lang.management.ManagementFactory; +import java.util.Objects; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; @@ -76,6 +77,14 @@ } } + /** + * @since 2.7.0 + */ + @Override + public String toString() { + return Objects.toString(objectName); + } + public void unregisterMBean() { if (MBEAN_SERVER == null || objectName == null) { return; diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -21,6 +21,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import org.apache.commons.pool2.KeyedObjectPool; @@ -67,9 +68,7 @@ // Remove from trace now because this statement will be // added by the activate method. - if (getConnectionInternal() != null) { - getConnectionInternal().removeTrace(this); - } + removeThisTrace(getConnectionInternal()); } /** @@ -115,21 +114,29 @@ @Override public void passivate() throws SQLException { setClosedInternal(true); - if (getConnectionInternal() != null) { - getConnectionInternal().removeTrace(this); - } + removeThisTrace(getConnectionInternal()); // The JDBC spec requires that a statement close any open // ResultSet's when it is closed. // FIXME The PreparedStatement we're wrapping should handle this for us. // See DBCP-10 for what could happen when ResultSets are closed twice. - final List resultSets = getTrace(); - if (resultSets != null) { - final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]); - for (final ResultSet element : set) { - element.close(); + final List resultSetList = getTrace(); + if (resultSetList != null) { + final List thrown = new ArrayList<>(); + final ResultSet[] resultSets = resultSetList.toArray(new ResultSet[resultSetList.size()]); + for (final ResultSet resultSet : resultSets) { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + thrown.add(e); + } + } } clearTrace(); + if (!thrown.isEmpty()) { + throw new SQLExceptionList(thrown); + } } super.passivate(); diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -32,9 +32,9 @@ import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.PooledObjectFactory; +import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; -import org.apache.commons.pool2.impl.DefaultPooledObject; /** * A {@link PooledObjectFactory} that creates {@link PoolableConnection}s. @@ -312,7 +312,7 @@ } } } - + /** * @return Whether to auto-commit on return. * @since 2.6.0 @@ -329,7 +329,7 @@ public boolean isEnableAutoCommitOnReturn() { return autoCommitOnReturn; } - + /** * True means that validation will fail immediately for connections that have previously thrown SQLExceptions with * SQL_STATE indicating fatal disconnection errors. @@ -342,14 +342,14 @@ public boolean isFastFailValidation() { return fastFailValidation; } - + /** * @return Whether to rollback on return. */ public boolean isRollbackOnReturn() { return rollbackOnReturn; } - + @Override public PooledObject makeObject() throws Exception { Connection conn = connectionFactory.createConnection(); @@ -410,7 +410,7 @@ return new DefaultPooledObject<>(pc); } - + @Override public void passivateObject(final PooledObject p) throws Exception { @@ -440,15 +440,15 @@ conn.passivate(); } - + public void setAutoCommitOnReturn(final boolean autoCommitOnReturn) { this.autoCommitOnReturn = autoCommitOnReturn; } - + public void setCacheState(final boolean cacheState) { this.cacheState = cacheState; } - + /** * Sets the SQL statements I use to initialize newly created {@link Connection}s. Using {@code null} turns off * connection initialization. @@ -459,7 +459,7 @@ public void setConnectionInitSql(final Collection connectionInitSqls) { this.connectionInitSqls = connectionInitSqls; } - + /** * Sets the default "auto commit" setting for borrowed {@link Connection}s * @@ -469,7 +469,7 @@ public void setDefaultAutoCommit(final Boolean defaultAutoCommit) { this.defaultAutoCommit = defaultAutoCommit; } - + /** * Sets the default "catalog" setting for borrowed {@link Connection}s * @@ -479,7 +479,7 @@ public void setDefaultCatalog(final String defaultCatalog) { this.defaultCatalog = defaultCatalog; } - + public void setDefaultQueryTimeout(final Integer defaultQueryTimeoutSeconds) { this.defaultQueryTimeoutSeconds = defaultQueryTimeoutSeconds; } @@ -492,7 +492,7 @@ public void setDefaultReadOnly(final Boolean defaultReadOnly) { this.defaultReadOnly = defaultReadOnly; } - + /** * Sets the default "schema" setting for borrowed {@link Connection}s * @@ -503,7 +503,7 @@ public void setDefaultSchema(final String defaultSchema) { this.defaultSchema = defaultSchema; } - + /** * Sets the default "Transaction Isolation" setting for borrowed {@link Connection}s * @@ -513,7 +513,7 @@ public void setDefaultTransactionIsolation(final int defaultTransactionIsolation) { this.defaultTransactionIsolation = defaultTransactionIsolation; } - + /** * @param disconnectionSqlCodes * The disconnection SQL codes. @@ -523,7 +523,7 @@ public void setDisconnectionSqlCodes(final Collection disconnectionSqlCodes) { this.disconnectionSqlCodes = disconnectionSqlCodes; } - + /** * @param autoCommitOnReturn Whether to auto-commit on return. * @deprecated Use {@link #setAutoCommitOnReturn(boolean)}. diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import org.apache.commons.pool2.KeyedObjectPool; @@ -29,6 +30,7 @@ * {@link PreparedStatement}s. *

* My {@link #close} method returns me to my containing pool. (See {@link PoolingConnection}.) + *

* * @param * the key type @@ -37,6 +39,7 @@ * @since 2.0 */ public class PoolablePreparedStatement extends DelegatingPreparedStatement { + /** * The {@link KeyedObjectPool} from which I was obtained. */ @@ -50,7 +53,7 @@ private volatile boolean batchAdded = false; /** - * Constructor + * Constructor. * * @param stmt * my underlying {@link PreparedStatement} @@ -69,9 +72,7 @@ // Remove from trace now because this statement will be // added by the activate method. - if (getConnectionInternal() != null) { - getConnectionInternal().removeTrace(this); - } + removeThisTrace(getConnectionInternal()); } /** @@ -128,21 +129,29 @@ clearBatch(); } setClosedInternal(true); - if (getConnectionInternal() != null) { - getConnectionInternal().removeTrace(this); - } + removeThisTrace(getConnectionInternal()); // The JDBC spec requires that a statement closes any open // ResultSet's when it is closed. // FIXME The PreparedStatement we're wrapping should handle this for us. // See bug 17301 for what could happen when ResultSets are closed twice. - final List resultSets = getTrace(); - if (resultSets != null) { - final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]); - for (final ResultSet element : set) { - element.close(); + final List resultSetList = getTrace(); + if (resultSetList != null) { + final List thrown = new ArrayList<>(); + final ResultSet[] resultSets = resultSetList.toArray(new ResultSet[resultSetList.size()]); + for (final ResultSet resultSet : resultSets) { + if (resultSet != null) { + try { + resultSet.close(); + } catch (Exception e) { + thrown.add(e); + } + } } clearTrace(); + if (!thrown.isEmpty()) { + throw new SQLExceptionList(thrown); + } } super.passivate(); diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/PoolingDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -75,7 +75,7 @@ * @since 2.1 */ @Override - public void close() throws Exception { + public void close() throws RuntimeException, SQLException { try { pool.close(); } catch (final RuntimeException rte) { diff -Nru commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/SQLExceptionList.java commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/SQLExceptionList.java --- commons-dbcp2-2.6.0/src/main/java/org/apache/commons/dbcp2/SQLExceptionList.java 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/main/java/org/apache/commons/dbcp2/SQLExceptionList.java 2019-07-31 12:46:24.000000000 +0000 @@ -0,0 +1,51 @@ +/* + * 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.SQLException; +import java.util.List; + +/** + * A SQLException based on a list of Throwable causes. + *

+ * The first exception in the list is used as this exception's cause and is accessible with the usual + * {@link #getCause()} while the complete list is accessible with {@link #getCauseList()}. + *

+ * + * @since 2.7.0 + */ +public class SQLExceptionList extends SQLException { + + private static final long serialVersionUID = 1L; + private final List causeList; + + /** + * Creates a new exception caused by a list of exceptions. + * + * @param causeList a list of cause exceptions. + */ + public SQLExceptionList(List causeList) { + super(String.format("%,d exceptions: %s", causeList.size(), causeList), causeList.get(0)); + this.causeList = causeList; + } + + public List getCauseList() { + return causeList; + } + +} diff -Nru commons-dbcp2-2.6.0/src/site/site.xml commons-dbcp2-2.7.0/src/site/site.xml --- commons-dbcp2-2.6.0/src/site/site.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/site.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,60 +1,61 @@ - - - - - - Commons DBCP - /images/dbcp-logo-white.png - /index.html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + Commons DBCP + /images/dbcp-logo-white.png + /index.html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/configuration.xml commons-dbcp2-2.7.0/src/site/xdoc/configuration.xml --- commons-dbcp2-2.6.0/src/site/xdoc/configuration.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/configuration.xml 2019-07-31 12:46:24.000000000 +0000 @@ -498,6 +498,14 @@ fastFailValidation is set to true. + + jmxName + + + Registers the DataSource as JMX MBean under specified name. The name has to conform to the JMX Object Name Syntax (see + javadoc). + + diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/download_dbcp.xml commons-dbcp2-2.7.0/src/site/xdoc/download_dbcp.xml --- commons-dbcp2-2.6.0/src/site/xdoc/download_dbcp.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/download_dbcp.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,246 +1,246 @@ - - - - - - Download Apache Commons DBCP - Apache Commons Documentation Team - - -
- -

- We recommend you use a mirror to download our release - builds, but you must verify the integrity of - the downloaded files using signatures downloaded from our main - distribution directories. Recent releases (48 hours) may not yet - be available from all the mirrors. -

- -

- You are currently using [preferred]. If you - encounter a problem with this mirror, please select another - mirror. If all mirrors are failing, there are backup - mirrors (at the end of the mirrors list) that should be - available. -

- [if-any logo][end] -

- -
-

- Other mirrors: - - -

-
- -

- It is essential that you - verify the integrity - of downloaded files, preferably using the PGP signature (*.asc files); - failing that using the SHA256 hash (*.sha256 checksum files). -

-

- The KEYS - file contains the public PGP keys used by Apache Commons developers - to sign releases. -

-
-
-
- - - - - - - - - - - - -
commons-dbcp2-2.6.0-bin.tar.gzsha256pgp
commons-dbcp2-2.6.0-bin.zipsha256pgp
-
- - - - - - - - - - - - -
commons-dbcp2-2.6.0-src.tar.gzsha256pgp
commons-dbcp2-2.6.0-src.zipsha256pgp
-
-
-
- - - - - - - - - - - - -
commons-dbcp2-2.4.0-bin.tar.gzsha256pgp
commons-dbcp2-2.4.0-bin.zipsha256pgp
-
- - - - - - - - - - - - -
commons-dbcp2-2.4.0-src.tar.gzsha256pgp
commons-dbcp2-2.4.0-src.zipsha256pgp
-
-
-
- - - - - - - - - - - - -
commons-dbcp-1.4-bin.tar.gzsha256pgp
commons-dbcp-1.4-bin.zipsha256pgp
-
- - - - - - - - - - - - -
commons-dbcp-1.4-src.tar.gzsha256pgp
commons-dbcp-1.4-src.zipsha256pgp
-
-
-
- - - - - - - - - - - - -
commons-dbcp-1.3${commons.release.4.binary.suffix}.tar.gzsha256pgp
commons-dbcp-1.3${commons.release.4.binary.suffix}.zipsha256pgp
-
- - - - - - - - - - - - -
commons-dbcp-1.3-src.tar.gzsha256pgp
commons-dbcp-1.3-src.zipsha256pgp
-
-
-
-

- Older releases can be obtained from the archives. -

- -
- -
+ + + + + + Download Apache Commons DBCP + Apache Commons Documentation Team + + +
+ +

+ We recommend you use a mirror to download our release + builds, but you must verify the integrity of + the downloaded files using signatures downloaded from our main + distribution directories. Recent releases (48 hours) may not yet + be available from all the mirrors. +

+ +

+ You are currently using [preferred]. If you + encounter a problem with this mirror, please select another + mirror. If all mirrors are failing, there are backup + mirrors (at the end of the mirrors list) that should be + available. +

+ [if-any logo][end] +

+ +
+

+ Other mirrors: + + +

+
+ +

+ It is essential that you + verify the integrity + of downloaded files, preferably using the PGP signature (*.asc files); + failing that using the SHA256 hash (*.sha256 checksum files). +

+

+ The KEYS + file contains the public PGP keys used by Apache Commons developers + to sign releases. +

+
+
+
+ + + + + + + + + + + + +
commons-dbcp2-2.7.0-bin.tar.gzsha256pgp
commons-dbcp2-2.7.0-bin.zipsha256pgp
+
+ + + + + + + + + + + + +
commons-dbcp2-2.7.0-src.tar.gzsha256pgp
commons-dbcp2-2.7.0-src.zipsha256pgp
+
+
+
+ + + + + + + + + + + + +
commons-dbcp2-2.4.0-bin.tar.gzsha256pgp
commons-dbcp2-2.4.0-bin.zipsha256pgp
+
+ + + + + + + + + + + + +
commons-dbcp2-2.4.0-src.tar.gzsha256pgp
commons-dbcp2-2.4.0-src.zipsha256pgp
+
+
+
+ + + + + + + + + + + + +
commons-dbcp-1.4-bin.tar.gzsha256pgp
commons-dbcp-1.4-bin.zipsha256pgp
+
+ + + + + + + + + + + + +
commons-dbcp-1.4-src.tar.gzsha256pgp
commons-dbcp-1.4-src.zipsha256pgp
+
+
+
+ + + + + + + + + + + + +
commons-dbcp-1.3${commons.release.4.binary.suffix}.tar.gzsha256pgp
commons-dbcp-1.3${commons.release.4.binary.suffix}.zipsha256pgp
+
+ + + + + + + + + + + + +
commons-dbcp-1.3-src.tar.gzsha256pgp
commons-dbcp-1.3-src.zipsha256pgp
+
+
+
+

+ Older releases can be obtained from the archives. +

+ +
+ +
diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/index.xml commons-dbcp2-2.7.0/src/site/xdoc/index.xml --- commons-dbcp2-2.6.0/src/site/xdoc/index.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/index.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,104 +1,106 @@ - - - - - - Overview - Commons Documentation Team - - - - -
- -

Many Apache projects support interaction with a relational database. -Creating a new connection for each user can be time consuming (often -requiring multiple seconds of clock time), in order to perform a database -transaction that might take milliseconds. Opening a connection per user -can be unfeasible in a publicly-hosted Internet application where the -number of simultaneous users can be very large. Accordingly, developers -often wish to share a "pool" of open connections between all of the -application's current users. The number of users actually performing -a request at any given time is usually a very small percentage of the -total number of active users, and during request processing is the only -time that a database connection is required. The application itself logs -into the DBMS, and handles any user account issues internally.

- -

There are several Database Connection Pools already available, both -within Apache products and elsewhere. This Commons package provides an -opportunity to coordinate the efforts required to create and maintain an -efficient, feature-rich package under the ASF license.

- -

The commons-dbcp2 package relies on code in the -commons-pool2 package to provide the underlying object pool -mechanisms that it utilizes.

- -

DBCP now comes in four different versions to support different versions of -JDBC. Here is how it works: -

    -
  • DBCP 2.6.0 compiles and runs under Java 8 only (JDBC 4.2)
  • -
  • DBCP 2.5.0 compiles and runs under Java 8 only (JDBC 4.2)
  • -
  • DBCP 2.4.0 compiles and runs under Java 7 only (JDBC 4.1)
  • -
  • DBCP 1.4 compiles and runs under Java 6 only (JDBC 4)
  • -
  • DBCP 1.3 compiles and runs under Java 1.4-5.0 only (JDBC 3)
  • -
-

-

DBCP 2.6.0 binaries should be used by applications running on Java 8 and above.

-

DBCP 2.5.0 binaries should be used by applications running under Java 8.

-

DBCP 2.4.0 binaries should be used by applications running under Java 7.

-

DBCP 1.4 binaries should be used by applications running under Java 6.

-

DBCP 1.3 should be used when running under Java 1.4 and 5.0.

- -

DBCP 2 is based on Commons Pool 2 and provides increased performance, JMX -support as well as numerous other new features compared to DBCP 1.x. Users -upgrading to 2.x should be aware that the Java package name has changed, as well -as the Maven co-ordinates, since DBCP 2.x is not binary compatible with DBCP -1.x. Users should also be aware that some configuration options (e.g. maxActive -to maxTotal) have been renamed to align them with the new names used by Commons -Pool 2.

- -

There is no difference in the codebase supporting DBCP 1.4.x and 1.3.x other -than that the code implementing methods added to support JDBC 4 has been -filtered out of the DBCP 1.3 sources.

- -
- -
-

- See the downloads page for information on - obtaining releases. -

-
- -
- -

The -Javadoc API documents -are available online. In particular, you should -read the package overview of the -org.apache.commons.dbcp2 -package for an overview of how to use DBCP.

- -

There are -several examples -of using DBCP available.

- -
- - -
+ + + + + + Overview + Commons Documentation Team + + + + +
+ +

Many Apache projects support interaction with a relational database. +Creating a new connection for each user can be time consuming (often +requiring multiple seconds of clock time), in order to perform a database +transaction that might take milliseconds. Opening a connection per user +can be unfeasible in a publicly-hosted Internet application where the +number of simultaneous users can be very large. Accordingly, developers +often wish to share a "pool" of open connections between all of the +application's current users. The number of users actually performing +a request at any given time is usually a very small percentage of the +total number of active users, and during request processing is the only +time that a database connection is required. The application itself logs +into the DBMS, and handles any user account issues internally.

+ +

There are several Database Connection Pools already available, both +within Apache products and elsewhere. This Commons package provides an +opportunity to coordinate the efforts required to create and maintain an +efficient, feature-rich package under the ASF license.

+ +

The commons-dbcp2 package relies on code in the +commons-pool2 package to provide the underlying object pool +mechanisms that it utilizes.

+ +

DBCP now comes in four different versions to support different versions of +JDBC. Here is how it works: +

    +
  • DBCP 2.7.0 compiles and runs under Java 8 only (JDBC 4.2)
  • +
  • DBCP 2.6.0 compiles and runs under Java 8 only (JDBC 4.2)
  • +
  • DBCP 2.5.0 compiles and runs under Java 8 only (JDBC 4.2)
  • +
  • DBCP 2.4.0 compiles and runs under Java 7 only (JDBC 4.1)
  • +
  • DBCP 1.4 compiles and runs under Java 6 only (JDBC 4)
  • +
  • DBCP 1.3 compiles and runs under Java 1.4-5.0 only (JDBC 3)
  • +
+

+

DBCP 2.7.0 binaries should be used by applications running on Java 8 and above.

+

DBCP 2.6.0 binaries should be used by applications running on Java 8 and above.

+

DBCP 2.5.0 binaries should be used by applications running under Java 8.

+

DBCP 2.4.0 binaries should be used by applications running under Java 7.

+

DBCP 1.4 binaries should be used by applications running under Java 6.

+

DBCP 1.3 should be used when running under Java 1.4 and 5.0.

+ +

DBCP 2 is based on Commons Pool 2 and provides increased performance, JMX +support as well as numerous other new features compared to DBCP 1.x. Users +upgrading to 2.x should be aware that the Java package name has changed, as well +as the Maven co-ordinates, since DBCP 2.x is not binary compatible with DBCP +1.x. Users should also be aware that some configuration options (e.g. maxActive +to maxTotal) have been renamed to align them with the new names used by Commons +Pool 2.

+ +

There is no difference in the codebase supporting DBCP 1.4.x and 1.3.x other +than that the code implementing methods added to support JDBC 4 has been +filtered out of the DBCP 1.3 sources.

+ +
+ +
+

+ See the downloads page for information on + obtaining releases. +

+
+ +
+ +

The +Javadoc API documents +are available online. In particular, you should +read the package overview of the +org.apache.commons.dbcp2 +package for an overview of how to use DBCP.

+ +

There are +several examples +of using DBCP available.

+ +
+ + +
diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/issue-tracking.xml commons-dbcp2-2.7.0/src/site/xdoc/issue-tracking.xml --- commons-dbcp2-2.6.0/src/site/xdoc/issue-tracking.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/issue-tracking.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,102 +1,102 @@ - - - - - - Apache Commons DBCP Issue tracking - Apache Commons Documentation Team - - - -
-

- Apache Commons DBCP uses ASF JIRA for tracking issues. - See the Apache Commons DBCP JIRA project page. -

- -

- To use JIRA you may need to create an account - (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically - created and you can use the Forgot Password - page to get a new password). -

- -

- If you would like to report a bug, or raise an enhancement request with - Apache Commons DBCP please do the following: -

    -
  1. Search existing open bugs. - If you find your issue listed then please add a comment with your details.
  2. -
  3. Search the mailing list archive(s). - You may find your issue or idea has already been discussed.
  4. -
  5. Decide if your issue is a bug or an enhancement.
  6. -
  7. Submit either a bug report - or enhancement request.
  8. -
-

- -

- Please also remember these points: -

    -
  • the more information you provide, the better we can help you
  • -
  • test cases are vital, particularly for any proposed enhancements
  • -
  • the developers of Apache Commons DBCP are all unpaid volunteers
  • -
-

- -

- For more information on subversion and creating patches see the - Apache Contributors Guide. -

- -

- You may also find these links useful: -

-

-
- -
+ + + + + + Apache Commons DBCP Issue tracking + Apache Commons Documentation Team + + + +
+

+ Apache Commons DBCP uses ASF JIRA for tracking issues. + See the Apache Commons DBCP JIRA project page. +

+ +

+ To use JIRA you may need to create an account + (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically + created and you can use the Forgot Password + page to get a new password). +

+ +

+ If you would like to report a bug, or raise an enhancement request with + Apache Commons DBCP please do the following: +

    +
  1. Search existing open bugs. + If you find your issue listed then please add a comment with your details.
  2. +
  3. Search the mailing list archive(s). + You may find your issue or idea has already been discussed.
  4. +
  5. Decide if your issue is a bug or an enhancement.
  6. +
  7. Submit either a bug report + or enhancement request.
  8. +
+

+ +

+ Please also remember these points: +

    +
  • the more information you provide, the better we can help you
  • +
  • test cases are vital, particularly for any proposed enhancements
  • +
  • the developers of Apache Commons DBCP are all unpaid volunteers
  • +
+

+ +

+ For more information on subversion and creating patches see the + Apache Contributors Guide. +

+ +

+ You may also find these links useful: +

+

+
+ +
diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/mail-lists.xml commons-dbcp2-2.7.0/src/site/xdoc/mail-lists.xml --- commons-dbcp2-2.6.0/src/site/xdoc/mail-lists.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/mail-lists.xml 2019-07-31 12:46:24.000000000 +0000 @@ -1,205 +1,205 @@ - - - - - - Apache Commons DBCP Mailing Lists - Apache Commons Documentation Team - - - -
-

- Apache Commons DBCP shares mailing lists with all the other - Commons Components. - To make it easier for people to only read messages related to components they are interested in, - the convention in Commons is to prefix the subject line of messages with the component's name, - for example: -

    -
  • [dbcp] Problem with the ...
  • -
-

-

- Questions related to the usage of Apache Commons DBCP should be posted to the - User List. -
- The Developer List - is for questions and discussion related to the development of Apache Commons DBCP. -
- Please do not cross-post; developers are also subscribed to the user list. -
- You must be subscribed to post to the mailing lists. Follow the Subscribe links below - to subscribe. -

-

- Note: please don't send patches or attachments to any of the mailing lists. - Patches are best handled via the Issue Tracking system. - Otherwise, please upload the file to a public server and include the URL in the mail. -

-
- -
-

- Please prefix the subject line of any messages for Apache Commons DBCP - with [dbcp] - thanks! -
-
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameSubscribeUnsubscribePostArchiveOther Archives
- Commons User List -

- Questions on using Apache Commons DBCP. -

-
SubscribeUnsubscribePostmail-archives.apache.orgmarkmail.org
- www.mail-archive.com
- news.gmane.org -
- Commons Developer List -

- Discussion of development of Apache Commons DBCP. -

-
SubscribeUnsubscribePostmail-archives.apache.orgmarkmail.org
- www.mail-archive.com
- news.gmane.org -
- Commons Issues List -

- Only for e-mails automatically generated by the issue tracking system. -

-
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
- www.mail-archive.com -
- Commons Commits List -

- Only for e-mails automatically generated by the source control sytem. -

-
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
- www.mail-archive.com -
- -
-
-

- Other mailing lists which you may find useful include: -

- - - - - - - - - - - - - - - - - - -
NameSubscribeUnsubscribePostArchiveOther Archives
- Apache Announce List -

- General announcements of Apache project releases. -

-
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
- old.nabble.com
- www.mail-archive.com
- news.gmane.org -
- -
- -
+ + + + + + Apache Commons DBCP Mailing Lists + Apache Commons Documentation Team + + + +
+

+ Apache Commons DBCP shares mailing lists with all the other + Commons Components. + To make it easier for people to only read messages related to components they are interested in, + the convention in Commons is to prefix the subject line of messages with the component's name, + for example: +

    +
  • [dbcp] Problem with the ...
  • +
+

+

+ Questions related to the usage of Apache Commons DBCP should be posted to the + User List. +
+ The Developer List + is for questions and discussion related to the development of Apache Commons DBCP. +
+ Please do not cross-post; developers are also subscribed to the user list. +
+ You must be subscribed to post to the mailing lists. Follow the Subscribe links below + to subscribe. +

+

+ Note: please don't send patches or attachments to any of the mailing lists. + Patches are best handled via the Issue Tracking system. + Otherwise, please upload the file to a public server and include the URL in the mail. +

+
+ +
+

+ Please prefix the subject line of any messages for Apache Commons DBCP + with [dbcp] - thanks! +
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameSubscribeUnsubscribePostArchiveOther Archives
+ Commons User List +

+ Questions on using Apache Commons DBCP. +

+
SubscribeUnsubscribePostmail-archives.apache.orgmarkmail.org
+ www.mail-archive.com
+ news.gmane.org +
+ Commons Developer List +

+ Discussion of development of Apache Commons DBCP. +

+
SubscribeUnsubscribePostmail-archives.apache.orgmarkmail.org
+ www.mail-archive.com
+ news.gmane.org +
+ Commons Issues List +

+ Only for e-mails automatically generated by the issue tracking system. +

+
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
+ www.mail-archive.com +
+ Commons Commits List +

+ Only for e-mails automatically generated by the source control sytem. +

+
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
+ www.mail-archive.com +
+ +
+
+

+ Other mailing lists which you may find useful include: +

+ + + + + + + + + + + + + + + + + + +
NameSubscribeUnsubscribePostArchiveOther Archives
+ Apache Announce List +

+ General announcements of Apache project releases. +

+
SubscribeUnsubscriberead onlymail-archives.apache.orgmarkmail.org
+ old.nabble.com
+ www.mail-archive.com
+ news.gmane.org +
+ +
+ +
diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/release-notes-1.1.xml commons-dbcp2-2.7.0/src/site/xdoc/release-notes-1.1.xml --- commons-dbcp2-2.6.0/src/site/xdoc/release-notes-1.1.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/release-notes-1.1.xml 2019-07-31 12:46:24.000000000 +0000 @@ -53,99 +53,99 @@
  • The following issues were resolved since v1.0: (see Bugzilla for complete description) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    IDDateSevStateSummary
    69342003-09-20BloDUPLSQLTransformer.java - infinite loop in getConnection
    70382002-03-18NorFIXEDBCP does not build under JDK 1.4
    77272002-04-20MajFIXEInfinite loop (stack overflow) in BasicDataSource
    77282002-04-20MajFIXEBasicDataSource cannot use many JDBC drivers
    86202002-04-29NorINVAClosed Connection Exception on setAutoCommit
    90732002-07-20NorFIXEBasicDataSource - invalid connections are not checked
    98502002-07-20NorFIXENo way to get at SQLException if connection to database fail
    105922002-07-20NorDUPLdataSource.getConnection never returns in Tomcat using DBCP
    106142002-07-20NorFIXEDBCP connection pooling broken in Tomcat-4.1.7 (regression)
    106882002-07-20MinFIXEVersion in the Manifest
    109692002-07-20MajFIXEBasicDataSource defaults are unusable
    115072002-08-06NorINVACleanup dead connections
    120472002-11-01NorINVAvalidationQuery + MSSQL
    124002002-11-07NorWORKsame connections
    124092002-11-01BloFIXEConnection can be closed twice
    127332003-02-06NorFIXE[DBCP][PATCH]Statement.getResultSet() doesn't return null if
    128692002-11-01MajFIXEAbandoned Connections are never closed
    130772002-11-07EnhFIXEJdbc2PoolDataSource issues
    131292002-11-01NorFIXECPDSConnectionFactory prints invalid error messages
    131552002-10-30NorDUPLunexpected "exhausted pool" error
    132352002-11-16BloFIXEreferenced UserPassKey instances get erroneously returned to
    139302003-03-06EnhFIXEAdding connection parameters to BasicDataSourceFactory
    139882003-03-17EnhDUPLpermission error makes connection loop
    142672003-04-28MajINVADBCP doesn't work on Tomcat 4.1.12 and Oracle JDBC driver
    145922002-11-15EnhINVADBCP must be robust against e.g. database shutdowns
    146632003-05-14NorREMITomcat5 server hangs when trying to get the database connect
    151232003-08-21MajFIXEIncorrect stack trace shown when abandoned connections are c
    155392003-02-06MajDUPLStrange Result Set on output
    162832003-02-01NorWONTInproper use of Exception
    165812003-03-06MajFIXEDeadlock in AbandonedObjectPool when firewall closes connect
    166292003-03-06NorFIXEorg.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource: setti
    169872003-08-11MajFIXErace condition in PoolableConnection.close()
    170152003-03-06NorFIXEGenericObjectPool.invalidateObject() doesn't work with Aband
    172002003-03-06MajFIXEDBCP: org.apache.commons.dbcp.cpdsadapter.PooledConnectionIm
    173012003-04-08NorWONTNPE in Oracle driver when using DBCP PoolingDataSource
    174562003-04-08EnhFIXEBasicDataSource should use commons-logging
    176352003-03-06MinFIXEPoolableConnectionFactory-Construction declared to throw Exc
    176772003-05-31MajINVAPooled connection architecture vulnerable to double use
    176782003-04-01MajFIXEDBCP Fails silently in many cases
    176802003-03-13MajINVAPoolableConnection.reallyClose() doesn't decrement active co
    179112003-04-07MajWONTProblem with getConnection() and Informix
    180122003-08-26EnhFIXEBasicDataSource doesn't include PreparedStmt Pooling
    184832003-04-08NorWONTAbandonedObjectPool.removeAbandoned never cleans up the trac
    185022003-03-30BloINVAjava.lang.ClassNotFoundException: org.apache.commons.pool.St
    185502003-08-25EnhFIXEAdd defaultTransactionIsolation to BasicDataSource
    188342003-04-08NorFIXEJdbc2PoolDataSource throws a RuntimeException when database
    189052003-08-11NorFIXECouldn't get connection (Jdbc2PoolDataSource)
    189212003-08-11EnhFIXEPer User methods not working in Jdbc2PoolDataSource
    189822003-04-13MajINVABinary distribution missing package
    193742003-08-11NorFIXEPotential for DelegateStatement, DelegateResultSet to be lef
    196142003-08-13MajFIXEPoor performance under load
    196152003-05-02MajINVAUnnecessary global synchronized in AbandonedObjectPool method
    197062003-08-26EnhWONTAdd Initial Commons Logging to DBCP
    206492003-08-11CriINVAdeadlock when acquiring connections from a pool
    211322003-08-11CriDUPLBroken pipe despite validation query set
    211822003-08-21NorINVA[dbcp] removing a webapp does not force connections closed
    212292003-08-11NorFIXEConnectionFactory throws SQLException but implementations do
    212732003-08-11NorFIXEMemory-leak like behaviour in DBCP due to warnings chained t
    214182003-08-11MinFIXEExample code
    214532003-08-11MajINVANullPointerException in DBCP when used for client-server ap
    214582003-08-11NorFIXEStatements and connections don't implement equals()/hashCode
    217482003-08-11NorFIXEBasicDataSource.close() throws NPE
    220782003-08-12NorFIXE[DBCP] testOnBorrow fails if setAutoCommit() throws an excep
    220792003-08-13NorFIXE[DBCP] if connection closed twice *closed* connection is ret
    222142003-08-11MajFIXEDelegating ResultSet causing NPE
    222292003-08-13CriFIXEFoul connection causes livelock of all pool operations
    225982003-08-21EnhFIXEminIdle Functionality for DBCP via Patches Posted for common
    227362003-08-29MajINVAvalidationQuery parameter hangs getConnection method.
    227502003-08-27NorFIXEBasicDataSource always sets testOnBorrow if given a validati
    227762003-09-20NorWONTDBCP should not be writing messages to stderr or stdout
    230662003-09-13MajFIXEDriverManager.getConnection() throws DbcpException
    230812003-09-20NorFIXEDBCP - Bad DB Validation Query Hangs Everything
    231382003-09-13NorFIXEgetDelegate no longer useful since v1.7 of PoolingDataSource
    231572003-09-20EnhFIXEadd defaultCatalog to BasicDataSource
    231852003-09-21NorWONTPoolableConnection.close() won't allow multiple close
    232912003-09-20NorFIXEimpossible to turn off all validation tests when a validatio
    232932003-09-20NorFIXEsetAutoCommit(true) when returning connection to the pool
    233042003-09-21NorFIXENullpointerException when no driverClassName is specified
    69342003-09-20BloDUPLSQLTransformer.java - infinite loop in getConnection
    70382002-03-18NorFIXEDBCP does not build under JDK 1.4
    77272002-04-20MajFIXEInfinite loop (stack overflow) in BasicDataSource
    77282002-04-20MajFIXEBasicDataSource cannot use many JDBC drivers
    86202002-04-29NorINVAClosed Connection Exception on setAutoCommit
    90732002-07-20NorFIXEBasicDataSource - invalid connections are not checked
    98502002-07-20NorFIXENo way to get at SQLException if connection to database fail
    105922002-07-20NorDUPLdataSource.getConnection never returns in Tomcat using DBCP
    106142002-07-20NorFIXEDBCP connection pooling broken in Tomcat-4.1.7 (regression)
    106882002-07-20MinFIXEVersion in the Manifest
    109692002-07-20MajFIXEBasicDataSource defaults are unusable
    115072002-08-06NorINVACleanup dead connections
    120472002-11-01NorINVAvalidationQuery + MSSQL
    124002002-11-07NorWORKsame connections
    124092002-11-01BloFIXEConnection can be closed twice
    127332003-02-06NorFIXE[DBCP][PATCH]Statement.getResultSet() doesn't return null if
    128692002-11-01MajFIXEAbandoned Connections are never closed
    130772002-11-07EnhFIXEJdbc2PoolDataSource issues
    131292002-11-01NorFIXECPDSConnectionFactory prints invalid error messages
    131552002-10-30NorDUPLunexpected "exhausted pool" error
    132352002-11-16BloFIXEreferenced UserPassKey instances get erroneously returned to
    139302003-03-06EnhFIXEAdding connection parameters to BasicDataSourceFactory
    139882003-03-17EnhDUPLpermission error makes connection loop
    142672003-04-28MajINVADBCP doesn't work on Tomcat 4.1.12 and Oracle JDBC driver
    145922002-11-15EnhINVADBCP must be robust against e.g. database shutdowns
    146632003-05-14NorREMITomcat5 server hangs when trying to get the database connect
    151232003-08-21MajFIXEIncorrect stack trace shown when abandoned connections are c
    155392003-02-06MajDUPLStrange Result Set on output
    162832003-02-01NorWONTInproper use of Exception
    165812003-03-06MajFIXEDeadlock in AbandonedObjectPool when firewall closes connect
    166292003-03-06NorFIXEorg.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource: setti
    169872003-08-11MajFIXErace condition in PoolableConnection.close()
    170152003-03-06NorFIXEGenericObjectPool.invalidateObject() doesn't work with Aband
    172002003-03-06MajFIXEDBCP: org.apache.commons.dbcp.cpdsadapter.PooledConnectionIm
    173012003-04-08NorWONTNPE in Oracle driver when using DBCP PoolingDataSource
    174562003-04-08EnhFIXEBasicDataSource should use commons-logging
    176352003-03-06MinFIXEPoolableConnectionFactory-Construction declared to throw Exc
    176772003-05-31MajINVAPooled connection architecture vulnerable to double use
    176782003-04-01MajFIXEDBCP Fails silently in many cases
    176802003-03-13MajINVAPoolableConnection.reallyClose() doesn't decrement active co
    179112003-04-07MajWONTProblem with getConnection() and Informix
    180122003-08-26EnhFIXEBasicDataSource doesn't include PreparedStmt Pooling
    184832003-04-08NorWONTAbandonedObjectPool.removeAbandoned never cleans up the trac
    185022003-03-30BloINVAjava.lang.ClassNotFoundException: org.apache.commons.pool.St
    185502003-08-25EnhFIXEAdd defaultTransactionIsolation to BasicDataSource
    188342003-04-08NorFIXEJdbc2PoolDataSource throws a RuntimeException when database
    189052003-08-11NorFIXECouldn't get connection (Jdbc2PoolDataSource)
    189212003-08-11EnhFIXEPer User methods not working in Jdbc2PoolDataSource
    189822003-04-13MajINVABinary distribution missing package
    193742003-08-11NorFIXEPotential for DelegateStatement, DelegateResultSet to be lef
    196142003-08-13MajFIXEPoor performance under load
    196152003-05-02MajINVAUnnecessary global synchronized in AbandonedObjectPool method
    197062003-08-26EnhWONTAdd Initial Commons Logging to DBCP
    206492003-08-11CriINVAdeadlock when acquiring connections from a pool
    211322003-08-11CriDUPLBroken pipe despite validation query set
    211822003-08-21NorINVA[dbcp] removing a webapp does not force connections closed
    212292003-08-11NorFIXEConnectionFactory throws SQLException but implementations do
    212732003-08-11NorFIXEMemory-leak like behaviour in DBCP due to warnings chained t
    214182003-08-11MinFIXEExample code
    214532003-08-11MajINVANullPointerException in DBCP when used for client-server ap
    214582003-08-11NorFIXEStatements and connections don't implement equals()/hashCode
    217482003-08-11NorFIXEBasicDataSource.close() throws NPE
    220782003-08-12NorFIXE[DBCP] testOnBorrow fails if setAutoCommit() throws an excep
    220792003-08-13NorFIXE[DBCP] if connection closed twice *closed* connection is ret
    222142003-08-11MajFIXEDelegating ResultSet causing NPE
    222292003-08-13CriFIXEFoul connection causes livelock of all pool operations
    225982003-08-21EnhFIXEminIdle Functionality for DBCP via Patches Posted for common
    227362003-08-29MajINVAvalidationQuery parameter hangs getConnection method.
    227502003-08-27NorFIXEBasicDataSource always sets testOnBorrow if given a validati
    227762003-09-20NorWONTDBCP should not be writing messages to stderr or stdout
    230662003-09-13MajFIXEDriverManager.getConnection() throws DbcpException
    230812003-09-20NorFIXEDBCP - Bad DB Validation Query Hangs Everything
    231382003-09-13NorFIXEgetDelegate no longer useful since v1.7 of PoolingDataSource
    231572003-09-20EnhFIXEadd defaultCatalog to BasicDataSource
    231852003-09-21NorWONTPoolableConnection.close() won't allow multiple close
    232912003-09-20NorFIXEimpossible to turn off all validation tests when a validatio
    232932003-09-20NorFIXEsetAutoCommit(true) when returning connection to the pool
    233042003-09-21NorFIXENullpointerException when no driverClassName is specified

  • The following issues were resolved since v1.1RC1: - - + +
    IDDateSevStateSummary
    227762003-09-30NorFIXEDBCP should not be writing messages to stderr or stdout (removed unneeded logging in AbandonedObjectPool)
    234912003-10-13CriFIXECan't configure PerUserPoolDataSource for use with tomcat, more...
    227762003-09-30NorFIXEDBCP should not be writing messages to stderr or stdout (removed unneeded logging in AbandonedObjectPool)
    234912003-10-13CriFIXECan't configure PerUserPoolDataSource for use with tomcat, more...

  • The following issues were resolved since v1.1RC2: - +
    IDDateSevStateSummary
    238432003-10-20BloFIXEPerUserPoolDataSource.getConnection(username, pw) may return connection under wrong username
    238432003-10-20BloFIXEPerUserPoolDataSource.getConnection(username, pw) may return connection under wrong username
  • diff -Nru commons-dbcp2-2.6.0/src/site/xdoc/release-notes-1.2.xml commons-dbcp2-2.7.0/src/site/xdoc/release-notes-1.2.xml --- commons-dbcp2-2.6.0/src/site/xdoc/release-notes-1.2.xml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/site/xdoc/release-notes-1.2.xml 2019-07-31 12:46:24.000000000 +0000 @@ -54,36 +54,36 @@
  • The following issues were resolved since v1.1: (see Bugzilla for complete description) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    IDDateSevStateSummary
    245622003-11-10EnhFIXEPoolingDriver needs a closePool method
    243282003-11-10NorFIXEPooledConnectionImpl ignores resultsetType and Concurrency
    246782003-11-14MajINVADelegatingStatement.getResultSet() never returns null
    250962003-11-30EnhFIXEPoolableConnectionFactory synchronized methods
    250012003-11-30NorFIXEOracle 9i and default isolation settings
    257622003-12-26NorFIXESharedPoolDataSource getConnection() throws ClassCastException
    250672003-12-26NorFIXEPlease give possibility to access ObjectPools from PoolingDriver
    257952003-12-29NorDUPLNumberFormatException: For input string: "myDB"
    257942003-12-29NorFIXEClassNotFoundException: org.apache.xerces.parsers.SAXParser
    249662004-01-06NorFIXENullPointer with Oracle 9 driver
    260722004-01-18NorFIXENull pointer exception being thrown in SQLNestedException
    262622004-01-20MinFIXEDBCP log message in tomcat has incorrect day
    264222004-01-25EnhFIXEAdd BasicDataSourceFactory.createDataSource(Properties properties)
    255142004-02-07EnhFIXEAdd initialSize parameter to do pre-loading of the connection
    240822004-02-28BloFIXENumberFormatException: For input string: "myDB"
    241362004-02-28NorFIXEClassCastException in DriverAdapterCPDS when setPoolPreparedStatements(true)
    272142004-02-29EnhFIXEbad &gt; entity in javadoc
    273202004-02-29NorFIXEDBCP 1.1 incompatible with Informix (driver doesn't support setReadOnly(...))
    274652004-03-07MajFIXEmemory leak in KeyedCPDSConnectionFactory
    269662004-03-07NorWORKConnectionpool's connections always returns same hashCode
    272462004-03-07NorFIXEPreparedStatement cache should be different depending on the Catalog
    274362004-03-08EnhFIXEWith Oracle jdbc driver, an unnecessary SQL "set transaction read write" is issued each time a connection is retrieved from the pool
    285792004-04-25NorFIXENumActive can become incorrect when removeAbandoned=true
    285802004-04-25EnhFIXEAbandonedObjectPool/Trace should log to stdout
    282512004-05-01NorFIXEReturning dead database connections to BasicDataSource
    286882004-05-01CriINVACant Deserialize the Class PerUserPoolDataSource
    288932004-05-12MinFIXEPoolableConnectionFactory has incomplete javadoc on validationQuery
    289122004-05-17MajFIXEConnection re-use conflates logical and physical connections
    290542004-05-20NorFIXEsetTestOnReturn(boolean)
    290552004-05-20NorFIXEAutoCommit and ReadOnly
    245622003-11-10EnhFIXEPoolingDriver needs a closePool method
    243282003-11-10NorFIXEPooledConnectionImpl ignores resultsetType and Concurrency
    246782003-11-14MajINVADelegatingStatement.getResultSet() never returns null
    250962003-11-30EnhFIXEPoolableConnectionFactory synchronized methods
    250012003-11-30NorFIXEOracle 9i and default isolation settings
    257622003-12-26NorFIXESharedPoolDataSource getConnection() throws ClassCastException
    250672003-12-26NorFIXEPlease give possibility to access ObjectPools from PoolingDriver
    257952003-12-29NorDUPLNumberFormatException: For input string: "myDB"
    257942003-12-29NorFIXEClassNotFoundException: org.apache.xerces.parsers.SAXParser
    249662004-01-06NorFIXENullPointer with Oracle 9 driver
    260722004-01-18NorFIXENull pointer exception being thrown in SQLNestedException
    262622004-01-20MinFIXEDBCP log message in tomcat has incorrect day
    264222004-01-25EnhFIXEAdd BasicDataSourceFactory.createDataSource(Properties properties)
    255142004-02-07EnhFIXEAdd initialSize parameter to do pre-loading of the connection
    240822004-02-28BloFIXENumberFormatException: For input string: "myDB"
    241362004-02-28NorFIXEClassCastException in DriverAdapterCPDS when setPoolPreparedStatements(true)
    272142004-02-29EnhFIXEbad &gt; entity in javadoc
    273202004-02-29NorFIXEDBCP 1.1 incompatible with Informix (driver doesn't support setReadOnly(...))
    274652004-03-07MajFIXEmemory leak in KeyedCPDSConnectionFactory
    269662004-03-07NorWORKConnectionpool's connections always returns same hashCode
    272462004-03-07NorFIXEPreparedStatement cache should be different depending on the Catalog
    274362004-03-08EnhFIXEWith Oracle jdbc driver, an unnecessary SQL "set transaction read write" is issued each time a connection is retrieved from the pool
    285792004-04-25NorFIXENumActive can become incorrect when removeAbandoned=true
    285802004-04-25EnhFIXEAbandonedObjectPool/Trace should log to stdout
    282512004-05-01NorFIXEReturning dead database connections to BasicDataSource
    286882004-05-01CriINVACant Deserialize the Class PerUserPoolDataSource
    288932004-05-12MinFIXEPoolableConnectionFactory has incomplete javadoc on validationQuery
    289122004-05-17MajFIXEConnection re-use conflates logical and physical connections
    290542004-05-20NorFIXEsetTestOnReturn(boolean)
    290552004-05-20NorFIXEAutoCommit and ReadOnly
  • diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,12 +17,13 @@ package org.apache.commons.dbcp2.cpdsadapter; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Properties; import java.io.PrintWriter; @@ -38,9 +39,9 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.datasources.SharedPoolDataSource; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for DriverAdapterCPDS @@ -49,7 +50,7 @@ private DriverAdapterCPDS pcds; - @Before + @BeforeEach public void setUp() throws Exception { pcds = new DriverAdapterCPDS(); pcds.setDriver("org.apache.commons.dbcp2.TesterDriver"); @@ -94,30 +95,30 @@ @Test public void testSimple() throws Exception { - final Connection conn = pcds.getPooledConnection().getConnection(); - assertNotNull(conn); - final PreparedStatement stmt = conn.prepareStatement("select * from dual"); - assertNotNull(stmt); - final ResultSet rset = stmt.executeQuery(); - assertNotNull(rset); - assertTrue(rset.next()); - rset.close(); - stmt.close(); - conn.close(); + try (final Connection conn = pcds.getPooledConnection().getConnection()) { + assertNotNull(conn); + try (final PreparedStatement stmt = conn.prepareStatement("select * from dual")) { + assertNotNull(stmt); + try (final ResultSet rset = stmt.executeQuery()) { + assertNotNull(rset); + assertTrue(rset.next()); + } + } + } } @Test public void testSimpleWithUsername() throws Exception { - final Connection conn = pcds.getPooledConnection("u1", "p1").getConnection(); - assertNotNull(conn); - final PreparedStatement stmt = conn.prepareStatement("select * from dual"); - assertNotNull(stmt); - final ResultSet rset = stmt.executeQuery(); - assertNotNull(rset); - assertTrue(rset.next()); - rset.close(); - stmt.close(); - conn.close(); + try (final Connection conn = pcds.getPooledConnection("u1", "p1").getConnection()) { + assertNotNull(conn); + try (final PreparedStatement stmt = conn.prepareStatement("select * from dual")) { + assertNotNull(stmt); + try (final ResultSet rset = stmt.executeQuery()) { + assertNotNull(rset); + assertTrue(rset.next()); + } + } + } } @Test @@ -169,12 +170,12 @@ assertEquals("bar", pcds.getConnectionProperties().getProperty("password")); } - @Test(expected=IllegalStateException.class) + @Test public void testSetConnectionPropertiesConnectionCalled() throws Exception { final Properties properties = new Properties(); // call to the connection pcds.getPooledConnection().close(); - pcds.setConnectionProperties(properties); + assertThrows(IllegalStateException.class, () -> pcds.setConnectionProperties(properties)); } @Test @@ -230,12 +231,13 @@ */ @Test public void testNullValidationQuery() throws Exception { - final SharedPoolDataSource spds = new SharedPoolDataSource(); - spds.setConnectionPoolDataSource(pcds); - spds.setDefaultTestOnBorrow(true); - final Connection c = spds.getConnection(); - c.close(); - spds.close(); + try (final SharedPoolDataSource spds = new SharedPoolDataSource()) { + spds.setConnectionPoolDataSource(pcds); + spds.setDefaultTestOnBorrow(true); + try (final Connection c = spds.getConnection()) { + // close right away + } + } } // https://issues.apache.org/jira/browse/DBCP-376 @@ -247,28 +249,29 @@ pcds.setMaxPreparedStatements(-1); pcds.setAccessToUnderlyingConnectionAllowed(true); - final SharedPoolDataSource spds = new SharedPoolDataSource(); - spds.setConnectionPoolDataSource(pcds); - spds.setMaxTotal(threads.length + 10); - spds.setDefaultMaxWaitMillis(-1); - spds.setDefaultMaxIdle(10); - spds.setDefaultAutoCommit(Boolean.FALSE); - - spds.setValidationQuery("SELECT 1"); - spds.setDefaultTimeBetweenEvictionRunsMillis(10000); - spds.setDefaultNumTestsPerEvictionRun(-1); - spds.setDefaultTestWhileIdle(true); - spds.setDefaultTestOnBorrow(true); - spds.setDefaultTestOnReturn(false); - - for (int i = 0; i < threads.length; i++) { - threads[i] = new ThreadDbcp367(spds); - threads[i].start(); - } - - for (int i = 0; i < threads.length; i++) { - threads[i].join(); - Assert.assertFalse("Thread " + i + " has failed",threads[i].isFailed()); + try (final SharedPoolDataSource spds = new SharedPoolDataSource()) { + spds.setConnectionPoolDataSource(pcds); + spds.setMaxTotal(threads.length + 10); + spds.setDefaultMaxWaitMillis(-1); + spds.setDefaultMaxIdle(10); + spds.setDefaultAutoCommit(Boolean.FALSE); + + spds.setValidationQuery("SELECT 1"); + spds.setDefaultTimeBetweenEvictionRunsMillis(10000); + spds.setDefaultNumTestsPerEvictionRun(-1); + spds.setDefaultTestWhileIdle(true); + spds.setDefaultTestOnBorrow(true); + spds.setDefaultTestOnReturn(false); + + for (int i = 0; i < threads.length; i++) { + threads[i] = new ThreadDbcp367(spds); + threads[i].start(); + } + + for (int i = 0; i < threads.length; i++) { + threads[i].join(); + Assertions.assertFalse(threads[i].isFailed(), "Thread " + i + " has failed"); + } } } @@ -301,9 +304,9 @@ } } - @Test(expected=SQLFeatureNotSupportedException.class) - public void testGetParentLogger() throws SQLFeatureNotSupportedException { - pcds.getParentLogger(); + @Test + public void testGetParentLogger() { + assertThrows(SQLFeatureNotSupportedException.class, pcds::getParentLogger); } @Test @@ -364,4 +367,16 @@ final Object o = pcds.getObjectInstance(ref, null, null, null); assertEquals(pcds.getDescription(), ((DriverAdapterCPDS) o).getDescription()); } + + @Test + public void testToStringWithoutConnectionProperties() throws ClassNotFoundException + { + final DriverAdapterCPDS cleanCpds = new DriverAdapterCPDS(); + cleanCpds.setDriver( "org.apache.commons.dbcp2.TesterDriver" ); + cleanCpds.setUrl( "jdbc:apache:commons:testdriver" ); + cleanCpds.setUser( "foo" ); + cleanCpds.setPassword( "bar" ); + + cleanCpds.toString(); + } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; @@ -28,8 +28,8 @@ import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS; import org.apache.commons.pool2.impl.GenericObjectPool; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -37,7 +37,7 @@ protected ConnectionPoolDataSourceProxy cpds = null; - @Before + @BeforeEach public void setUp() throws Exception { cpds = new ConnectionPoolDataSourceProxy(new DriverAdapterCPDS()); final DriverAdapterCPDS delegate = (DriverAdapterCPDS) cpds.getDelegate(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,7 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Hashtable; @@ -29,7 +29,7 @@ import javax.naming.StringRefAddr; import javax.naming.spi.ObjectFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ @@ -38,7 +38,7 @@ // Bugzilla Bug 24082: bug in InstanceKeyDataSourceFactory // There's a fatal bug in InstanceKeyDataSourceFactory that means you can't // instantiate more than one factory. - // http://issues.apache.org/bugzilla/show_bug.cgi?id=24082 + // https://issues.apache.org/bugzilla/show_bug.cgi?id=24082 @Test public void testJNDI2Pools() throws Exception { final Reference refObj = new Reference(SharedPoolDataSource.class.getName()); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestInstanceKeyDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestInstanceKeyDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestInstanceKeyDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestInstanceKeyDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,12 +17,13 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.PrintWriter; import java.sql.Connection; @@ -30,9 +31,9 @@ import java.util.Properties; import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -46,7 +47,7 @@ private final static String USER = "foo"; private final static String PASS = "bar"; - @Before + @BeforeEach public void setUp() throws ClassNotFoundException { pcds = new DriverAdapterCPDS(); pcds.setDriver(DRIVER); @@ -58,7 +59,7 @@ spds.setConnectionPoolDataSource(pcds); } - @After + @AfterEach public void tearDown() throws Exception { spds.close(); } @@ -102,16 +103,16 @@ assertEquals(pcds, spds.getConnectionPoolDataSource()); } - @Test(expected=IllegalStateException.class) + @Test public void testConnectionPoolDataSourceAlreadySet() { - spds.setConnectionPoolDataSource(new DriverAdapterCPDS()); + assertThrows(IllegalStateException.class, () -> spds.setConnectionPoolDataSource(new DriverAdapterCPDS())); } - @Test(expected=IllegalStateException.class) + @Test public void testConnectionPoolDataSourceAlreadySetUsingJndi() { spds = new SharedPoolDataSource(); spds.setDataSourceName("anything"); - spds.setConnectionPoolDataSource(new DriverAdapterCPDS()); + assertThrows(IllegalStateException.class, () -> spds.setConnectionPoolDataSource(new DriverAdapterCPDS())); } @Test @@ -122,16 +123,16 @@ assertEquals("anything", spds.getDataSourceName()); } - @Test(expected=IllegalStateException.class) + @Test public void testDataSourceNameAlreadySet() { - spds.setDataSourceName("anything"); + assertThrows(IllegalStateException.class, () -> spds.setDataSourceName("anything")); } - @Test(expected=IllegalStateException.class) + @Test public void testDataSourceNameAlreadySetUsingJndi() { spds = new SharedPoolDataSource(); spds.setDataSourceName("anything"); - spds.setDataSourceName("anything"); + assertThrows(IllegalStateException.class, () -> spds.setDataSourceName("anything")); } @Test @@ -141,10 +142,10 @@ assertEquals(Connection.TRANSACTION_READ_COMMITTED, spds.getDefaultTransactionIsolation()); } - @Test(expected=IllegalArgumentException.class) + @Test public void testDefaultTransactionIsolationInvalid() { assertEquals(InstanceKeyDataSource.UNKNOWN_TRANSACTIONISOLATION, spds.getDefaultTransactionIsolation()); - spds.setDefaultTransactionIsolation(Integer.MAX_VALUE); + assertThrows(IllegalArgumentException.class, () -> spds.setDefaultTransactionIsolation(Integer.MAX_VALUE)); } @Test @@ -153,9 +154,9 @@ assertEquals("anything", spds.getDescription()); } - @Test(expected=NullPointerException.class) + @Test public void testJndiNullProperties() { - spds.setJndiEnvironment(null); + assertThrows(NullPointerException.class, () -> spds.setJndiEnvironment(null)); } @Test @@ -210,11 +211,11 @@ assertEquals("anything", spds.getValidationQuery()); } - @Test(expected=IllegalStateException.class) + @Test public void testValidationQueryWithConnectionCalled() throws SQLException { spds.getConnection(); assertNull(spds.getValidationQuery()); - spds.setValidationQuery("anything"); + assertThrows(IllegalStateException.class, () -> spds.setValidationQuery("anything")); } @Test @@ -231,12 +232,11 @@ assertEquals(true, spds.isRollbackAfterValidation()); } - @Test(expected=IllegalStateException.class) + @Test public void testRollbackAfterValidationWithConnectionCalled() throws SQLException { spds.getConnection(); assertFalse(spds.isRollbackAfterValidation()); - spds.setRollbackAfterValidation(true); - assertEquals(true, spds.isRollbackAfterValidation()); + assertThrows(IllegalStateException.class, () -> spds.setRollbackAfterValidation(true)); } @Test diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; @@ -29,8 +29,8 @@ import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -38,7 +38,7 @@ protected ConnectionPoolDataSourceProxy cpds = null; - @Before + @BeforeEach public void setUp() throws Exception { cpds = new ConnectionPoolDataSourceProxy(new DriverAdapterCPDS()); final DriverAdapterCPDS delegate = (DriverAdapterCPDS) cpds.getDelegate(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -39,9 +39,9 @@ import org.apache.commons.dbcp2.TestConnectionPool; import org.apache.commons.dbcp2.TesterDriver; import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -56,7 +56,7 @@ private DataSource ds; - @Before + @BeforeEach public void setUp() throws Exception { user = "foo"; final DriverAdapterCPDS pcds = new DriverAdapterCPDS(); @@ -79,7 +79,7 @@ } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ((PerUserPoolDataSource) ds).close(); @@ -88,7 +88,7 @@ /** * Switching 'u1 to 'u2' and 'p1' to 'p2' will * exhibit the bug detailed in - * http://issues.apache.org/bugzilla/show_bug.cgi?id=18905 + * https://issues.apache.org/bugzilla/show_bug.cgi?id=18905 */ @Test public void testIncorrectPassword() throws Exception { @@ -426,8 +426,8 @@ final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(ds); - final byte[] b = baos.toByteArray(); out.close(); + final byte[] b = baos.toByteArray(); final ByteArrayInputStream bais = new ByteArrayInputStream(b); final ObjectInputStream in = new ObjectInputStream(bais); @@ -437,7 +437,7 @@ assertEquals( 1, ((PerUserPoolDataSource)obj).getNumIdle() ); } - // see issue http://issues.apache.org/bugzilla/show_bug.cgi?id=23843 + // see issue https://issues.apache.org/bugzilla/show_bug.cgi?id=23843 // unregistered user is in the same pool as without user name @Test public void testUnregisteredUser() throws Exception { @@ -469,7 +469,7 @@ assertEquals(1, tds.getNumIdle("u1")); } - // see issue http://issues.apache.org/bugzilla/show_bug.cgi?id=23843 + // see issue https://issues.apache.org/bugzilla/show_bug.cgi?id=23843 @Test public void testDefaultUser1() throws Exception { TesterDriver.addUser("mkh", "password"); @@ -490,7 +490,7 @@ } } - // see issue http://issues.apache.org/bugzilla/show_bug.cgi?id=23843 + // see issue https://issues.apache.org/bugzilla/show_bug.cgi?id=23843 @Test public void testDefaultUser2() throws Exception { TesterDriver.addUser("mkh", "password"); @@ -527,12 +527,12 @@ try { final Connection con4 = ds.getConnection(user, "bay"); // new password // Idle instances with old password should have been cleared - assertEquals("Should be no idle connections in the pool", - 0, ((PerUserPoolDataSource) ds).getNumIdle(user)); + assertEquals(0, ((PerUserPoolDataSource) ds).getNumIdle(user), + "Should be no idle connections in the pool"); con4.close(); // Should be one idle instance with new pwd - assertEquals("Should be one idle connection in the pool", - 1, ((PerUserPoolDataSource) ds).getNumIdle(user)); + assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), + "Should be one idle connection in the pool"); try (Connection c = ds.getConnection(user, "bar")) { // old password fail("Should have generated SQLException"); } catch (final SQLException expected) { @@ -540,8 +540,8 @@ final Connection con5 = ds.getConnection(user, "bay"); // take the idle one con3.close(); // Return a connection with the old password ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it - assertEquals("Should be one idle connection in the pool", - 1, ((PerUserPoolDataSource) ds).getNumIdle(user)); + assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), + "Should be one idle connection in the pool"); con5.close(); } finally { TesterDriver.addUser(user,"bar"); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPoolKey.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPoolKey.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPoolKey.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestPoolKey.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,11 +17,11 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for PoolKey. @@ -32,7 +32,7 @@ private PoolKey poolKey; private PoolKey anotherPoolKey; - @Before + @BeforeEach public void setUp() { poolKey = new PoolKey("ds", "user"); anotherPoolKey = new PoolKey(null, null); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.CallableStatement; import java.sql.Connection; @@ -36,8 +36,8 @@ import org.apache.commons.dbcp2.TestConnectionPool; import org.apache.commons.dbcp2.TesterDriver; import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -51,7 +51,7 @@ private DriverAdapterCPDS pcds; private DataSource ds; - @Before + @BeforeEach public void setUp() throws Exception { pcds = new DriverAdapterCPDS(); pcds.setDriver("org.apache.commons.dbcp2.TesterDriver"); @@ -697,12 +697,12 @@ TesterDriver.addUser("foo","bay"); // change the user/password setting try (Connection con4 = ds.getConnection("foo", "bay")) { // new password // Idle instances with old password should have been cleared - assertEquals("Should be no idle connections in the pool", - 0, ((SharedPoolDataSource) ds).getNumIdle()); + assertEquals(0, ((SharedPoolDataSource) ds).getNumIdle(), + "Should be no idle connections in the pool"); con4.close(); // Should be one idle instance with new pwd - assertEquals("Should be one idle connection in the pool", - 1, ((SharedPoolDataSource) ds).getNumIdle()); + assertEquals(1, ((SharedPoolDataSource) ds).getNumIdle(), + "Should be one idle connection in the pool"); try (Connection con4b = ds.getConnection("foo", "bar")) { // old password fail("Should have generated SQLException"); } catch (final SQLException expected) { @@ -710,8 +710,8 @@ final Connection con5 = ds.getConnection("foo", "bay"); // take the idle one con3.close(); // Return a connection with the old password ds.getConnection("foo", "bay").close(); // will try bad returned connection and destroy it - assertEquals("Should be one idle connection in the pool", - 1, ((SharedPoolDataSource) ds).getNumIdle()); + assertEquals(1, ((SharedPoolDataSource) ds).getNumIdle(), + "Should be one idle connection in the pool"); con5.close(); } finally { TesterDriver.addUser("foo","bar"); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,15 +17,15 @@ package org.apache.commons.dbcp2.datasources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import org.apache.commons.dbcp2.Utils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for UserPassKey. @@ -36,7 +36,7 @@ private UserPassKey userPassKey; private UserPassKey anotherUserPassKey; - @Before + @BeforeEach public void setUp() { userPassKey = new UserPassKey("user", "pass"); anotherUserPassKey = new UserPassKey((String) null, ""); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestBasicManagedDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestBasicManagedDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestBasicManagedDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestBasicManagedDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -24,7 +24,7 @@ import org.apache.geronimo.transaction.manager.TransactionManagerImpl; import org.h2.Driver; import org.h2.jdbcx.JdbcDataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.sql.XADataSource; import javax.transaction.Synchronization; @@ -34,10 +34,11 @@ import java.sql.Connection; import java.sql.SQLException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; /** * TestSuite for BasicManagedDataSource @@ -58,27 +59,27 @@ */ @Test public void testReallyClose() throws Exception { - final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource(); - basicManagedDataSource.setTransactionManager(new TransactionManagerImpl()); - basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver"); - basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver"); - basicManagedDataSource.setUsername("userName"); - basicManagedDataSource.setPassword("password"); - basicManagedDataSource.setMaxIdle(1); - // Create two connections - final ManagedConnection conn = (ManagedConnection) basicManagedDataSource.getConnection(); - assertNotNull(basicManagedDataSource.getTransactionRegistry().getXAResource(conn)); - final ManagedConnection conn2 = (ManagedConnection) basicManagedDataSource.getConnection(); - conn2.close(); // Return one connection to the pool - conn.close(); // No room at the inn - this will trigger reallyClose(), which should unregister - try { - basicManagedDataSource.getTransactionRegistry().getXAResource(conn); - fail("Expecting SQLException - XAResources orphaned"); - } catch (final SQLException ex) { - // expected + try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) { + basicManagedDataSource.setTransactionManager(new TransactionManagerImpl()); + basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver"); + basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver"); + basicManagedDataSource.setUsername("userName"); + basicManagedDataSource.setPassword("password"); + basicManagedDataSource.setMaxIdle(1); + // Create two connections + final ManagedConnection conn = (ManagedConnection) basicManagedDataSource.getConnection(); + assertNotNull(basicManagedDataSource.getTransactionRegistry().getXAResource(conn)); + final ManagedConnection conn2 = (ManagedConnection) basicManagedDataSource.getConnection(); + conn2.close(); // Return one connection to the pool + conn.close(); // No room at the inn - this will trigger reallyClose(), which should unregister + try { + basicManagedDataSource.getTransactionRegistry().getXAResource(conn); + fail("Expecting SQLException - XAResources orphaned"); + } catch (final SQLException ex) { + // expected + } + conn2.close(); } - conn2.close(); - basicManagedDataSource.close(); } @Test @@ -98,15 +99,15 @@ } } - @Test(expected=SQLException.class) + @Test public void testTransactionManagerNotSet() throws SQLException { try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) { - basicManagedDataSource.createConnectionFactory(); + assertThrows(SQLException.class, basicManagedDataSource::createConnectionFactory); } } @Test - public void testSetDriverName() throws SQLException, XAException { + public void testSetDriverName() throws SQLException { try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) { basicManagedDataSource.setDriverClassName("adams"); assertEquals("adams", basicManagedDataSource.getDriverClassName()); @@ -135,7 +136,7 @@ } } - @Test(expected=NullPointerException.class) + @Test public void testRuntimeExceptionsAreRethrown() throws SQLException, XAException { try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) { basicManagedDataSource.setTransactionManager(new TransactionManagerImpl()); @@ -145,7 +146,7 @@ basicManagedDataSource.setPassword("password"); basicManagedDataSource.setMaxIdle(1); // results in a NPE - basicManagedDataSource.createPoolableConnectionFactory(null); + assertThrows(NullPointerException.class, () -> basicManagedDataSource.createPoolableConnectionFactory(null)); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,7 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.PreparedStatement; @@ -28,10 +28,10 @@ import javax.transaction.RollbackException; import javax.transaction.Status; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple; import com.arjuna.ats.jta.common.jtaPropertyManager; @@ -62,7 +62,7 @@ private BasicManagedDataSource mds; - @Before + @BeforeEach public void setUp() throws Exception { jtaPropertyManager.getJTAEnvironmentBean().setLastResourceOptimisationInterfaceClassName( "org.apache.commons.dbcp2.managed.LocalXAConnectionFactory$LocalXAResource"); @@ -85,11 +85,11 @@ mds.setLogExpiredConnections(true); mds.setLifo(false); - final Connection conn = mds.getConnection(); - final PreparedStatement ps = conn.prepareStatement(CREATE_STMT); - ps.execute(); - ps.close(); - conn.close(); + try (final Connection conn = mds.getConnection()) { + try (final PreparedStatement ps = conn.prepareStatement(CREATE_STMT)) { + ps.execute(); + } + } } @Test @@ -120,7 +120,7 @@ } finally { mds.getTransactionManager().rollback(); } - Assert.assertEquals(0, mds.getNumActive()); + Assertions.assertEquals(0, mds.getNumActive()); } @Test @@ -138,12 +138,12 @@ fail("Should not work after timeout"); } catch (final SQLException e) { // Expected - Assert.assertEquals("Commit can not be set while enrolled in a transaction", e.getMessage()); + Assertions.assertEquals("Commit can not be set while enrolled in a transaction", e.getMessage()); } mds.getTransactionManager().rollback(); } - Assert.assertEquals(0, mds.getNumActive()); + Assertions.assertEquals(0, mds.getNumActive()); } @Test @@ -218,17 +218,17 @@ conn.close(); } } - Assert.assertEquals(0, mds.getNumActive()); + Assertions.assertEquals(0, mds.getNumActive()); } } - @After + @AfterEach public void tearDown() throws Exception { - final Connection conn = mds.getConnection(); - final PreparedStatement ps = conn.prepareStatement(DROP_STMT); - ps.execute(); - ps.close(); - conn.close(); + try (final Connection conn = mds.getConnection()) { + try (final PreparedStatement ps = conn.prepareStatement(DROP_STMT)) { + ps.execute(); + } + } if (mds != null) { mds.close(); } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestDataSourceXAConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,7 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; @@ -32,8 +32,8 @@ import org.apache.commons.dbcp2.TestBasicDataSource; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicManagedDataSource when using a @@ -46,7 +46,7 @@ public AtomicInteger closeCounter = new AtomicInteger(); @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); bmds = new BasicManagedDataSource(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestLocalXaResource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestLocalXaResource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestLocalXaResource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestLocalXaResource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,11 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Array; import java.sql.Blob; @@ -45,8 +46,8 @@ import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for LocalXAConnectionFactory$LocalXAResource @@ -56,7 +57,7 @@ private Connection conn; private LocalXAConnectionFactory.LocalXAResource resource; - @Before + @BeforeEach public void setUp() { conn = new TestConnection(); resource = new LocalXAConnectionFactory.LocalXAResource(conn); @@ -78,22 +79,22 @@ assertFalse(resource.isSameRM(new LocalXAConnectionFactory.LocalXAResource(conn))); } - @Test(expected=XAException.class) - public void testStartInvalidFlag() throws XAException { + @Test + public void testStartInvalidFlag() { // currently, valid values are TMNOFLAGS and TMRESUME - resource.start(null, XAResource.TMENDRSCAN); + assertThrows(XAException.class, () -> resource.start(null, XAResource.TMENDRSCAN)); } - @Test(expected=XAException.class) + @Test public void testStartNoFlagButAlreadyEnlisted() throws XAException { resource.start(new TestXid(), XAResource.TMNOFLAGS); - resource.start(new TestXid(), XAResource.TMNOFLAGS); + assertThrows(XAException.class, () -> resource.start(new TestXid(), XAResource.TMNOFLAGS)); } - @Test(expected=XAException.class) + @Test public void testStartNoFlagResumeButDifferentXid() throws XAException { resource.start(new TestXid(), XAResource.TMNOFLAGS); - resource.start(new TestXid(), XAResource.TMRESUME); + assertThrows(XAException.class, () -> resource.start(new TestXid(), XAResource.TMRESUME)); } @Test @@ -114,22 +115,22 @@ assertEquals(xid, resource.getXid()); } - @Test(expected=NullPointerException.class) + @Test public void testStartNoFlagResumeEndMissingXid() throws XAException { final Xid xid = new TestXid(); resource.start(xid, XAResource.TMNOFLAGS); resource.start(xid, XAResource.TMRESUME); // flag is never used in the end - resource.end(null, 0); + assertThrows(NullPointerException.class, () -> resource.end(null, 0)); } - @Test(expected=XAException.class) + @Test public void testStartNoFlagResumeEndDifferentXid() throws XAException { final Xid xid = new TestXid(); resource.start(xid, XAResource.TMNOFLAGS); resource.start(xid, XAResource.TMRESUME); // flag is never used in the end - resource.end(new TestXid(), 0); + assertThrows(XAException.class, () -> resource.end(new TestXid(), 0)); } @Test @@ -209,41 +210,41 @@ assertFalse(conn.getAutoCommit()); } - @Test(expected=XAException.class) - public void testStartFailsWhenCannotSetAutoCommit() throws XAException, SQLException { + @Test + public void testStartFailsWhenCannotSetAutoCommit() { final Xid xid = new TestXid(); ((TestConnection) conn).throwWhenSetAutoCommit = true; - resource.start(xid, XAResource.TMNOFLAGS); + assertThrows(XAException.class, () -> resource.start(xid, XAResource.TMNOFLAGS)); } - @Test(expected=NullPointerException.class) - public void testCommitMissingXid() throws SQLException, XAException { - resource.commit(null, false); + @Test + public void testCommitMissingXid() { + assertThrows(NullPointerException.class, () -> resource.commit(null, false)); } - @Test(expected=XAException.class) - public void testCommitNoTransaction() throws SQLException, XAException { + @Test + public void testCommitNoTransaction() throws SQLException { ((TestConnection) conn).closed = false; conn.setReadOnly(false); - resource.commit(new TestXid(), false); + assertThrows(XAException.class, () -> resource.commit(new TestXid(), false)); } - @Test(expected=XAException.class) + @Test public void testCommitInvalidXid() throws SQLException, XAException { final Xid xid = new TestXid(); ((TestConnection) conn).closed = false; conn.setReadOnly(false); resource.start(xid, XAResource.TMNOFLAGS); - resource.commit(new TestXid(), false); + assertThrows(XAException.class, () -> resource.commit(new TestXid(), false)); } - @Test(expected=XAException.class) + @Test public void testCommitConnectionClosed() throws SQLException, XAException { final Xid xid = new TestXid(); ((TestConnection) conn).closed = true; conn.setReadOnly(false); resource.start(xid, XAResource.TMNOFLAGS); - resource.commit(xid, false); + assertThrows(XAException.class, () -> resource.commit(xid, false)); } @Test @@ -266,18 +267,18 @@ assertTrue(((TestConnection) conn).committed); } - @Test(expected=NullPointerException.class) - public void testRollbackMissingXid() throws XAException { - resource.rollback(null); + @Test + public void testRollbackMissingXid() { + assertThrows(NullPointerException.class, () -> resource.rollback(null)); } - @Test(expected=XAException.class) + @Test public void testRollbackInvalidXid() throws SQLException, XAException { final Xid xid = new TestXid(); ((TestConnection) conn).closed = false; conn.setReadOnly(false); resource.start(xid, XAResource.TMNOFLAGS); - resource.rollback(new TestXid()); + assertThrows(XAException.class, () -> resource.rollback(new TestXid())); } @Test diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,7 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Field; import java.sql.Connection; @@ -42,9 +42,9 @@ import org.apache.commons.dbcp2.TesterDriver; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for ManagedConnection. @@ -57,7 +57,7 @@ protected TransactionManager transactionManager; - @Before + @BeforeEach public void setUp() throws Exception { // create a GeronimoTransactionManager for testing @@ -89,7 +89,7 @@ ds.setAccessToUnderlyingConnectionAllowed(true); } - @After + @AfterEach public void tearDown() throws Exception { pool.close(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,12 +17,12 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.CallableStatement; import java.sql.Connection; @@ -35,10 +35,10 @@ import javax.transaction.Transaction; import org.apache.commons.dbcp2.DelegatingConnection; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests ManagedDataSource with an active transaction in progress. @@ -46,14 +46,14 @@ public class TestManagedDataSourceInTx extends TestManagedDataSource { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); transactionManager.begin(); } @Override - @After + @AfterEach public void tearDown() throws Exception { if (transactionManager.getTransaction() != null) { transactionManager.commit(); @@ -86,12 +86,12 @@ conn[i] = newConnection(); for(int j=0;j) conn[j]).getInnermostDelegateInternal(), + Assertions.assertEquals(((DelegatingConnection) conn[j]).getInnermostDelegateInternal(), ((DelegatingConnection) conn[i]).getInnermostDelegateInternal()); } } @@ -174,7 +174,7 @@ assertNotNull(conn2); // shared connections should not have the same hashcode - Assert.assertNotEquals(conn1.hashCode(), conn2.hashCode()); + Assertions.assertNotEquals(conn1.hashCode(), conn2.hashCode()); } @Override @@ -308,11 +308,11 @@ final Connection connection = newConnection(); - assertFalse("Connection should be open", connection.isClosed()); + assertFalse(connection.isClosed(), "Connection should be open"); connection.close(); - assertTrue("Connection should be closed", connection.isClosed()); + assertTrue(connection.isClosed(), "Connection should be closed"); } @Override @@ -321,7 +321,7 @@ final Connection connection = newConnection(); // auto commit should be off - assertFalse("Auto-commit should be disabled", connection.getAutoCommit()); + assertFalse(connection.getAutoCommit(), "Auto-commit should be disabled"); // attempt to set auto commit try { @@ -332,7 +332,7 @@ } // make sure it is still disabled - assertFalse("Auto-commit should be disabled", connection.getAutoCommit()); + assertFalse(connection.getAutoCommit(), "Auto-commit should be disabled"); // close connection connection.close(); @@ -343,7 +343,7 @@ final Connection connection = newConnection(); // connection should be open - assertFalse("Connection should be open", connection.isClosed()); + assertFalse(connection.isClosed(), "Connection should be open"); // attempt commit directly try { @@ -354,7 +354,7 @@ } // make sure it is still open - assertFalse("Connection should be open", connection.isClosed()); + assertFalse(connection.isClosed(), "Connection should be open"); // close connection connection.close(); @@ -367,7 +367,7 @@ // NOTE: This test class uses connections that are read-only by default // connection should be read only - assertTrue("Connection be read-only", connection.isReadOnly()); + assertTrue(connection.isReadOnly(), "Connection be read-only"); // attempt to setReadOnly try { @@ -378,7 +378,7 @@ } // make sure it is still read-only - assertTrue("Connection be read-only", connection.isReadOnly()); + assertTrue(connection.isReadOnly(), "Connection be read-only"); // attempt to setReadonly try { @@ -389,7 +389,7 @@ } // make sure it is still read-only - assertTrue("Connection be read-only", connection.isReadOnly()); + assertTrue(connection.isReadOnly(), "Connection be read-only"); // close connection connection.close(); @@ -401,31 +401,31 @@ assertFalse(conn.isClosed()); assertFalse(isClosed(statement)); - assertSame("statement.getConnection() should return the exact same connection instance that was used to create the statement", - conn, statement.getConnection()); + assertSame(conn, statement.getConnection(), + "statement.getConnection() should return the exact same connection instance that was used to create the statement"); final ResultSet resultSet = statement.getResultSet(); assertFalse(isClosed(resultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, resultSet.getStatement()); + assertSame(statement, resultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); final ResultSet executeResultSet = statement.executeQuery("select * from dual"); assertFalse(isClosed(executeResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, executeResultSet.getStatement()); + assertSame(statement, executeResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); final ResultSet keysResultSet = statement.getGeneratedKeys(); assertFalse(isClosed(keysResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, keysResultSet.getStatement()); + assertSame(statement, keysResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); ResultSet preparedResultSet = null; if (statement instanceof PreparedStatement) { final PreparedStatement preparedStatement = (PreparedStatement) statement; preparedResultSet = preparedStatement.executeQuery(); assertFalse(isClosed(preparedResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, preparedResultSet.getStatement()); + assertSame(statement, preparedResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,11 +17,12 @@ */ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.commons.dbcp2.ConnectionFactory; import org.apache.commons.dbcp2.DelegatingConnection; @@ -33,10 +34,10 @@ import org.apache.commons.dbcp2.TesterDriver; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.transaction.TransactionManager; @@ -57,7 +58,7 @@ protected GenericObjectPool pool = null; protected TransactionManager transactionManager; - @Before + @BeforeEach public void setUp() throws Exception { // create a GeronimoTransactionManager for testing transactionManager = new TransactionManagerImpl(); @@ -90,7 +91,7 @@ } @Override - @After + @AfterEach public void tearDown() throws Exception { pool.close(); super.tearDown(); @@ -159,8 +160,8 @@ // Grab a new connection - should get c[0]'s closed connection // so should be delegate-equivalent final Connection con = newConnection(); - Assert.assertNotEquals(c[0], con); - Assert.assertEquals( + Assertions.assertNotEquals(c[0], con); + Assertions.assertEquals( ((DelegatingConnection) c[0]).getInnermostDelegateInternal(), ((DelegatingConnection) con).getInnermostDelegateInternal()); for (final Connection element : c) { @@ -182,8 +183,8 @@ // Grab a new connection - should get c[0]'s closed connection // so should be delegate-equivalent final Connection con = newConnection(); - Assert.assertNotEquals(c[0], con); - Assert.assertEquals( + Assertions.assertNotEquals(c[0], con); + Assertions.assertEquals( ((DelegatingConnection) c[0]).getInnermostDelegateInternal(), ((DelegatingConnection) con).getInnermostDelegateInternal()); for (final Connection element : c) { @@ -257,23 +258,23 @@ c2.close(); } - @Test(expected=IllegalStateException.class) + @Test public void testTransactionRegistryNotInitialized() throws Exception { try (ManagedDataSource ds = new ManagedDataSource<>(pool, null)) { - ds.getConnection(); + assertThrows(IllegalStateException.class, ds::getConnection); } } - @Test(expected=IllegalStateException.class) + @Test public void testSetTransactionRegistryAlreadySet() { final ManagedDataSource managed = (ManagedDataSource) ds; - managed.setTransactionRegistry(null); + assertThrows(IllegalStateException.class, () -> managed.setTransactionRegistry(null)); } - @Test(expected=NullPointerException.class) + @Test public void testSetNullTransactionRegistry() throws Exception { try (ManagedDataSource ds = new ManagedDataSource<>(pool, null)) { - ds.setTransactionRegistry(null); + assertThrows(NullPointerException.class, () -> ds.setTransactionRegistry(null)); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -18,10 +18,10 @@ package org.apache.commons.dbcp2.managed; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; @@ -36,9 +36,9 @@ import org.apache.commons.dbcp2.TesterDriver; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for PoolableManagedConnection. @@ -51,7 +51,7 @@ private Connection conn; private PoolableManagedConnection poolableManagedConnection; - @Before + @BeforeEach public void setUp() throws Exception { // create a GeronimoTransactionManager for testing transactionManager = new TransactionManagerImpl(); @@ -81,7 +81,7 @@ pool.setMaxWaitMillis(100); } - @After + @AfterEach public void tearDown() throws SQLException { if (conn != null && !conn.isClosed()) { conn.close(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestSynchronizationOrder.java 2019-07-31 12:46:24.000000000 +0000 @@ -22,9 +22,9 @@ import org.apache.commons.dbcp2.PoolableConnectionFactory; import org.apache.commons.dbcp2.TesterClassLoader; import org.apache.commons.pool2.impl.GenericObjectPool; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.sql.XAConnection; import javax.sql.XADataSource; @@ -48,8 +48,8 @@ import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; public class TestSynchronizationOrder { @@ -63,69 +63,75 @@ @Test public void testSessionSynchronization() throws Exception { - final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, xads); + final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, + xads); - final PoolableConnectionFactory factory = - new PoolableConnectionFactory(xaConnectionFactory, null); + final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null); factory.setValidationQuery("SELECT DUMMY FROM DUAL"); factory.setDefaultReadOnly(Boolean.TRUE); factory.setDefaultAutoCommit(Boolean.TRUE); // create the pool - final GenericObjectPool pool = new GenericObjectPool<>(factory); - factory.setPool(pool); - pool.setMaxTotal(10); - pool.setMaxWaitMillis(1000); - - // finally create the datasource - final ManagedDataSource ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry()); - ds.setAccessToUnderlyingConnectionAllowed(true); - - - transactionManager.begin(); - final DelegatingConnection connectionA = (DelegatingConnection) ds.getConnection(); - connectionA.close(); - transactionManager.commit(); - assertTrue(transactionManagerRegistered); - assertFalse(transactionSynchronizationRegistryRegistered); + try (final GenericObjectPool pool = new GenericObjectPool<>(factory)) { + factory.setPool(pool); + pool.setMaxTotal(10); + pool.setMaxWaitMillis(1000); + + // finally create the datasource + try (final ManagedDataSource ds = new ManagedDataSource<>(pool, + xaConnectionFactory.getTransactionRegistry())) { + ds.setAccessToUnderlyingConnectionAllowed(true); + + transactionManager.begin(); + try (final DelegatingConnection connectionA = (DelegatingConnection) ds.getConnection()) { + // close right away. + } + transactionManager.commit(); + assertTrue(transactionManagerRegistered); + assertFalse(transactionSynchronizationRegistryRegistered); + } + } } @Test public void testInterposedSynchronization() throws Exception { - final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, xads, transactionSynchronizationRegistry); + final DataSourceXAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(transactionManager, + xads, transactionSynchronizationRegistry); - final PoolableConnectionFactory factory = - new PoolableConnectionFactory(xaConnectionFactory, null); + final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null); factory.setValidationQuery("SELECT DUMMY FROM DUAL"); factory.setDefaultReadOnly(Boolean.TRUE); factory.setDefaultAutoCommit(Boolean.TRUE); // create the pool - final GenericObjectPool pool = new GenericObjectPool<>(factory); - factory.setPool(pool); - pool.setMaxTotal(10); - pool.setMaxWaitMillis(1000); - - // finally create the datasource - final ManagedDataSource ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry()); - ds.setAccessToUnderlyingConnectionAllowed(true); - - - transactionManager.begin(); - final DelegatingConnection connectionA = (DelegatingConnection) ds.getConnection(); - connectionA.close(); - transactionManager.commit(); - assertFalse(transactionManagerRegistered); - assertTrue(transactionSynchronizationRegistryRegistered); + try (final GenericObjectPool pool = new GenericObjectPool<>(factory)) { + factory.setPool(pool); + pool.setMaxTotal(10); + pool.setMaxWaitMillis(1000); + + // finally create the datasource + try (final ManagedDataSource ds = new ManagedDataSource<>(pool, + xaConnectionFactory.getTransactionRegistry())) { + ds.setAccessToUnderlyingConnectionAllowed(true); + + transactionManager.begin(); + try (final DelegatingConnection connectionA = (DelegatingConnection) ds.getConnection()) { + // Close right away. + } + transactionManager.commit(); + assertFalse(transactionManagerRegistered); + assertTrue(transactionSynchronizationRegistryRegistered); + } + } } - @After + @AfterEach public void tearDown() throws SQLException { bds.close(); bmds.close(); } - @Before + @BeforeEach public void setup() { transactionManager = new TransactionManager() { @@ -297,7 +303,7 @@ } }; xads = (XADataSource) Proxy.newProxyInstance( - InvocationHandler.class.getClassLoader(), + TestSynchronizationOrder.class.getClassLoader(), new Class[]{XADataSource.class}, handle); bmds.setXaDataSourceInstance(xads); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/managed/TestTransactionContext.java 2019-07-31 12:46:24.000000000 +0000 @@ -20,10 +20,12 @@ import java.sql.SQLException; import javax.transaction.xa.XAResource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; import org.apache.geronimo.transaction.manager.TransactionImpl; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * TestSuite for TransactionContext */ @@ -32,21 +34,22 @@ /** * JIRA: DBCP-428 */ - @Test(expected=SQLException.class) + @Test public void testSetSharedConnectionEnlistFailure() throws Exception { - final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource(); - basicManagedDataSource.setTransactionManager(new TransactionManagerImpl()); - basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver"); - basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver"); - basicManagedDataSource.setUsername("userName"); - basicManagedDataSource.setPassword("password"); - basicManagedDataSource.setMaxIdle(1); - final ManagedConnection conn = (ManagedConnection) basicManagedDataSource.getConnection(); - final UncooperativeTransaction transaction = new UncooperativeTransaction(); - final TransactionContext transactionContext = - new TransactionContext(basicManagedDataSource.getTransactionRegistry(), transaction); - transactionContext.setSharedConnection(conn); - basicManagedDataSource.close(); + try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) { + basicManagedDataSource.setTransactionManager(new TransactionManagerImpl()); + basicManagedDataSource.setDriverClassName("org.apache.commons.dbcp2.TesterDriver"); + basicManagedDataSource.setUrl("jdbc:apache:commons:testdriver"); + basicManagedDataSource.setUsername("userName"); + basicManagedDataSource.setPassword("password"); + basicManagedDataSource.setMaxIdle(1); + try (final ManagedConnection conn = (ManagedConnection) basicManagedDataSource.getConnection()) { + final UncooperativeTransaction transaction = new UncooperativeTransaction(); + final TransactionContext transactionContext = new TransactionContext( + basicManagedDataSource.getTransactionRegistry(), transaction); + assertThrows(SQLException.class, () -> transactionContext.setSharedConnection(conn)); + } + } } /** diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.PrintWriter; @@ -31,9 +31,9 @@ import java.sql.Statement; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicDataSource with abandoned connection trace enabled @@ -43,7 +43,7 @@ private StringWriter sw; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); // abandoned enabled but should not affect the basic tests @@ -95,7 +95,7 @@ conn1.close(); assertEquals(0, ds.getNumActive()); final String string = sw.toString(); - assertTrue(string, string.contains("testAbandonedClose")); + assertTrue(string.contains("testAbandonedClose"), string); } @Test @@ -132,7 +132,7 @@ } assertEquals(0, ds.getNumActive()); final String string = sw.toString(); - assertTrue(string, string.contains("testAbandonedCloseWithExceptions")); + assertTrue(string.contains("testAbandonedCloseWithExceptions"), string); } /** @@ -193,10 +193,10 @@ Statement st = conn1.createStatement()) { final String querySQL = "SELECT 1 FROM DUAL"; Thread.sleep(500); - Assert.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed + Assertions.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed Thread.sleep(800); final Connection conn2 = ds.getConnection(); // triggers abandoned cleanup - Assert.assertNotNull(st.executeQuery(querySQL)); // Should still be OK + Assertions.assertNotNull(st.executeQuery(querySQL)); // Should still be OK conn2.close(); Thread.sleep(500); st.executeUpdate(""); // Should also reset @@ -218,10 +218,10 @@ Statement st = conn1.createStatement()) { final String querySQL = "SELECT 1 FROM DUAL"; Thread.sleep(500); - Assert.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed + Assertions.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed Thread.sleep(800); final Connection conn2 = ds.getConnection(); // triggers abandoned cleanup - Assert.assertNotNull(st.executeQuery(querySQL)); // Should still be OK + Assertions.assertNotNull(st.executeQuery(querySQL)); // Should still be OK conn2.close(); Thread.sleep(500); st.executeLargeUpdate(""); // Should also reset @@ -256,11 +256,11 @@ @Test public void testGarbageCollectorCleanUp01() throws Exception { final DelegatingConnection conn = (DelegatingConnection) ds.getConnection(); - Assert.assertEquals(0, conn.getTrace().size()); + Assertions.assertEquals(0, conn.getTrace().size()); createStatement(conn); - Assert.assertEquals(1, conn.getTrace().size()); + Assertions.assertEquals(1, conn.getTrace().size()); System.gc(); - Assert.assertEquals(0, conn.getTrace().size()); + Assertions.assertEquals(0, conn.getTrace().size()); } /** @@ -277,11 +277,11 @@ final GenericKeyedObjectPool gkop = (GenericKeyedObjectPool) TesterUtils.getField(poolingConn, "pstmtPool"); - Assert.assertEquals(0, conn.getTrace().size()); - Assert.assertEquals(0, gkop.getNumActive()); + Assertions.assertEquals(0, conn.getTrace().size()); + Assertions.assertEquals(0, gkop.getNumActive()); createStatement(conn); - Assert.assertEquals(1, conn.getTrace().size()); - Assert.assertEquals(1, gkop.getNumActive()); + Assertions.assertEquals(1, conn.getTrace().size()); + Assertions.assertEquals(1, gkop.getNumActive()); System.gc(); // Finalization happens in a separate thread. Give the test time for // that to complete. @@ -290,13 +290,13 @@ Thread.sleep(100); count++; } - Assert.assertEquals(0, gkop.getNumActive()); - Assert.assertEquals(0, conn.getTrace().size()); + Assertions.assertEquals(0, gkop.getNumActive()); + Assertions.assertEquals(0, conn.getTrace().size()); } private void createStatement(final Connection conn) throws Exception{ final PreparedStatement ps = conn.prepareStatement(""); - Assert.assertNotNull(ps); + Assertions.assertNotNull(ps); } @@ -314,7 +314,7 @@ assertAndReset(conn); st.executeLargeBatch(); assertAndReset(conn); - Assert.assertNotNull(st.executeQuery("")); + Assertions.assertNotNull(st.executeQuery("")); assertAndReset(conn); st.executeUpdate(""); assertAndReset(conn); @@ -338,7 +338,7 @@ private void checkLastUsedPreparedStatement(final PreparedStatement ps, final DelegatingConnection conn) throws Exception { ps.execute(); assertAndReset(conn); - Assert.assertNotNull(ps.executeQuery()); + Assertions.assertNotNull(ps.executeQuery()); assertAndReset(conn); ps.executeUpdate(); assertAndReset(conn); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.management.ManagementFactory; import java.sql.Connection; @@ -33,7 +33,7 @@ import javax.naming.StringRefAddr; import org.apache.commons.pool2.impl.GenericObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicDataSourceFactory @@ -66,7 +66,7 @@ final BasicDataSourceFactory basicDataSourceFactory = new BasicDataSourceFactory(); basicDataSourceFactory.getObjectInstance(ref, null, null, null); final List messages = StackMessageLog.getAll(); - assertEquals(messages.toString(), 2, messages.size()); + assertEquals(2, messages.size(), messages.toString()); for (final String message : messages) { if (message.contains("maxWait")) { assertTrue(message.contains("use maxWaitMillis")); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,13 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.lang.management.ManagementFactory; @@ -35,11 +41,11 @@ import org.apache.commons.logging.LogFactory; import org.hamcrest.CoreMatchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicDataSource @@ -54,13 +60,13 @@ protected BasicDataSource ds = null; private static final String CATALOG = "test catalog"; - @BeforeClass + @BeforeAll public static void setUpClass() { // register a custom logger which supports inspection of the log messages LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.dbcp2.StackMessageLog"); } - @Before + @BeforeEach public void setUp() throws Exception { ds = createDataSource(); ds.setDriverClassName("org.apache.commons.dbcp2.TesterDriver"); @@ -84,7 +90,7 @@ } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ds.close(); @@ -195,11 +201,11 @@ @Test public void testTransactionIsolationBehavior() throws Exception { - final Connection conn = getConnection(); - assertNotNull(conn); - assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation()); - conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); - conn.close(); + try (final Connection conn = getConnection()) { + assertNotNull(conn); + assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation()); + conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); + } final Connection conn2 = getConnection(); assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn2.getTransactionIsolation()); @@ -238,14 +244,15 @@ ds.setAccessToUnderlyingConnectionAllowed(true); assertTrue(ds.isAccessToUnderlyingConnectionAllowed()); - final Connection conn = getConnection(); - Connection dconn = ((DelegatingConnection) conn).getDelegate(); - assertNotNull(dconn); + try (final Connection conn = getConnection()) { + Connection dconn = ((DelegatingConnection) conn).getDelegate(); + assertNotNull(dconn); - dconn = ((DelegatingConnection) conn).getInnermostDelegate(); - assertNotNull(dconn); + dconn = ((DelegatingConnection) conn).getInnermostDelegate(); + assertNotNull(dconn); - assertTrue(dconn instanceof TesterConnection); + assertTrue(dconn instanceof TesterConnection); + } } @Test @@ -289,8 +296,9 @@ ds.setTestOnBorrow(true); ds.setTestOnReturn(true); ds.setValidationQueryTimeout(0); - final Connection con = ds.getConnection(); - con.close(); + try (final Connection con = ds.getConnection()) { + // close right away. + } } @Test @@ -298,8 +306,9 @@ ds.setTestOnBorrow(true); ds.setTestOnReturn(true); ds.setValidationQueryTimeout(-1); - final Connection con = ds.getConnection(); - con.close(); + try (final Connection con = ds.getConnection()) { + // close right away. + } } @Test @@ -307,8 +316,9 @@ ds.setTestOnBorrow(true); ds.setTestOnReturn(true); ds.setValidationQueryTimeout(100); // Works for TesterStatement - final Connection con = ds.getConnection(); - con.close(); + try (final Connection con = ds.getConnection()) { + // close right away. + } } @Test @@ -464,7 +474,7 @@ ds.close(); // Exception must have been swallowed by the pool - verify it is logged final String message = StackMessageLog.popMessage(); - Assert.assertNotNull(message); + Assertions.assertNotNull(message); assertTrue(message.indexOf("bang") > 0); } catch (final SQLException ex) { assertTrue(ex.getMessage().indexOf("Cannot close") > 0); @@ -487,7 +497,7 @@ StackMessageLog.clear(); ds.close(); final String message = StackMessageLog.popMessage(); - Assert.assertNotNull(message); + Assertions.assertNotNull(message); assertTrue(message.indexOf("boom") > 0); } catch (final IllegalStateException ex) { assertTrue(ex.getMessage().indexOf("boom") > 0); // RTE is not wrapped by BDS#close @@ -552,16 +562,18 @@ @Test public void testInvalidateConnection() throws Exception { - ds.setMaxTotal(2); - final Connection conn1 = ds.getConnection(); - final Connection conn2 = ds.getConnection(); - ds.invalidateConnection(conn1); - assertTrue(conn1.isClosed()); - assertEquals(1, ds.getNumActive()); - assertEquals(0, ds.getNumIdle()); - final Connection conn3 = ds.getConnection(); - conn2.close(); - conn3.close(); + ds.setMaxTotal(2); + try (final Connection conn1 = ds.getConnection()) { + try (final Connection conn2 = ds.getConnection()) { + ds.invalidateConnection(conn1); + assertTrue(conn1.isClosed()); + assertEquals(1, ds.getNumActive()); + assertEquals(0, ds.getNumIdle()); + try (final Connection conn3 = ds.getConnection()) { + conn2.close(); + } + } + } } /** @@ -698,7 +710,7 @@ conn.close(); assertEquals(0, ds.getNumIdle()); final String message = StackMessageLog.popMessage(); - Assert.assertNotNull(message); + Assertions.assertNotNull(message); assertTrue(message.indexOf("exceeds the maximum permitted value") > 0); } finally { StackMessageLog.clear(); @@ -718,7 +730,7 @@ Thread.sleep(500); } assertEquals(0, ds.getNumIdle()); - assertTrue(StackMessageLog.getAll().toString(), StackMessageLog.isEmpty()); + assertTrue(StackMessageLog.isEmpty(), StackMessageLog.getAll().toString()); } finally { StackMessageLog.clear(); StackMessageLog.unLock(); @@ -865,9 +877,45 @@ final BasicDataSource ds = BasicDataSourceFactory.createDataSource(properties); final boolean original = ds.getConnectionPool().getLogAbandoned(); ds.setLogAbandoned(!original); - Assert.assertNotEquals(Boolean.valueOf(original), + Assertions.assertNotEquals(Boolean.valueOf(original), Boolean.valueOf(ds.getConnectionPool().getLogAbandoned())); } + + /** + * JIRA: DBCP-547 + * Verify that ConnectionFactory interface in BasicDataSource.createConnectionFactory(). + */ + @Test + public void testCreateConnectionFactory() throws Exception { + + /** not set ConnectionFactoryClassName */ + Properties properties = new Properties(); + properties.put("initialSize", "1"); + properties.put("driverClassName", "org.apache.commons.dbcp2.TesterDriver"); + properties.put("url", "jdbc:apache:commons:testdriver"); + properties.put("username", "foo"); + properties.put("password", "bar"); + BasicDataSource ds = BasicDataSourceFactory.createDataSource(properties); + Connection conn = ds.getConnection(); + assertNotNull(conn); + conn.close(); + ds.close(); + + /** set ConnectionFactoryClassName */ + properties = new Properties(); + properties.put("initialSize", "1"); + properties.put("driverClassName", "org.apache.commons.dbcp2.TesterDriver"); + properties.put("url", "jdbc:apache:commons:testdriver"); + properties.put("username", "foo"); + properties.put("password", "bar"); + properties.put("connectionFactoryClassName", "org.apache.commons.dbcp2.TesterConnectionFactory"); + ds = BasicDataSourceFactory.createDataSource(properties); + conn = ds.getConnection(); + assertNotNull(conn); + + conn.close(); + ds.close(); + } } /** diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestBasicDataSourceMXBean.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for BasicDataSourceMXBean. diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java 2019-07-31 12:46:24.000000000 +0000 @@ -27,16 +27,16 @@ import java.util.Random; import java.util.Stack; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; // XXX FIX ME XXX // this class still needs some cleanup, but at least @@ -49,7 +49,7 @@ */ public abstract class TestConnectionPool { - @After + @AfterEach public void tearDown() throws Exception { // Close any connections opened by the test while (!connections.isEmpty()) { @@ -281,31 +281,31 @@ assertFalse(conn.isClosed()); assertFalse(isClosed(statement)); - assertSame("statement.getConnection() should return the exact same connection instance that was used to create the statement", - conn, statement.getConnection()); + assertSame(conn,statement.getConnection(), + "statement.getConnection() should return the exact same connection instance that was used to create the statement"); final ResultSet resultSet = statement.getResultSet(); assertFalse(isClosed(resultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, resultSet.getStatement()); + assertSame(statement, resultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); final ResultSet executeResultSet = statement.executeQuery("select * from dual"); assertFalse(isClosed(executeResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, executeResultSet.getStatement()); + assertSame(statement, executeResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); final ResultSet keysResultSet = statement.getGeneratedKeys(); assertFalse(isClosed(keysResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, keysResultSet.getStatement()); + assertSame(statement, keysResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); ResultSet preparedResultSet = null; if (statement instanceof PreparedStatement) { final PreparedStatement preparedStatement = (PreparedStatement) statement; preparedResultSet = preparedStatement.executeQuery(); assertFalse(isClosed(preparedResultSet)); - assertSame("resultSet.getStatement() should return the exact same statement instance that was used to create the result set", - statement, preparedResultSet.getStatement()); + assertSame(statement, preparedResultSet.getStatement(), + "resultSet.getStatement() should return the exact same statement instance that was used to create the result set"); } @@ -426,7 +426,7 @@ final Connection con = newConnection(); final Connection underCon = ((DelegatingConnection) con).getInnermostDelegate(); - assertTrue("Failed to get connection", underCon != null); + assertTrue(underCon != null, "Failed to get connection"); boolean found = false; for (int j = 0; j < c.length; j++) { if (underCon == u[j]) { @@ -434,7 +434,7 @@ break; } } - assertTrue("New connection not from pool", found); + assertTrue(found, "New connection not from pool"); con.close(); } } @@ -442,30 +442,30 @@ @Test public void testAutoCommitBehavior() throws Exception { final Connection conn0 = newConnection(); - assertNotNull("connection should not be null", conn0); - assertTrue("autocommit should be true for conn0", conn0.getAutoCommit()); + assertNotNull(conn0, "connection should not be null"); + assertTrue(conn0.getAutoCommit(), "autocommit should be true for conn0"); final Connection conn1 = newConnection(); - assertTrue("autocommit should be true for conn1", conn1.getAutoCommit() ); + assertTrue(conn1.getAutoCommit(), "autocommit should be true for conn1"); conn1.close(); - assertTrue("autocommit should be true for conn0", conn0.getAutoCommit()); + assertTrue(conn0.getAutoCommit(), "autocommit should be true for conn0"); conn0.setAutoCommit(false); - assertFalse("autocommit should be false for conn0", conn0.getAutoCommit()); + assertFalse(conn0.getAutoCommit(), "autocommit should be false for conn0"); conn0.close(); final Connection conn2 = newConnection(); - assertTrue("autocommit should be true for conn2", conn2.getAutoCommit() ); + assertTrue(conn2.getAutoCommit(), "autocommit should be true for conn2"); final Connection conn3 = newConnection(); - assertTrue("autocommit should be true for conn3", conn3.getAutoCommit() ); + assertTrue(conn3.getAutoCommit(), "autocommit should be true for conn3"); conn2.close(); conn3.close(); } - /** "http://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */ + /** "https://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */ @Test public void testConnectionsAreDistinct() throws Exception { final Connection[] conn = new Connection[getMaxTotal()]; @@ -634,7 +634,7 @@ // Bugzilla Bug 24328: PooledConnectionImpl ignores resultsetType // and Concurrency if statement pooling is not enabled - // http://issues.apache.org/bugzilla/show_bug.cgi?id=24328 + // https://issues.apache.org/bugzilla/show_bug.cgi?id=24328 @Test public void testPrepareStatementOptions() throws Exception { @@ -844,11 +844,11 @@ System.out.println("NOTE: some threads did not run the code: "+didNotRun); } // Perform initial sanity check: - assertTrue("Expected some of the threads to fail",failed > 0); + assertTrue(failed > 0, "Expected some of the threads to fail"); // Assume that threads that did not run would have timed out. - assertEquals("WARNING: Expected half the threads to fail",pts.length/2,failed+didNotRun); + assertEquals(pts.length/2, failed+didNotRun, "WARNING: Expected half the threads to fail"); } else { - assertEquals("Did not expect any threads to fail",0,failed); + assertEquals(0, failed, "Did not expect any threads to fail"); } } private static int currentThreadCount = 0; diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestConstants.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestConstants.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestConstants.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestConstants.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for Constants. diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDataSourceConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDataSourceConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDataSourceConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDataSourceConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,8 +17,8 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.PrintWriter; import java.sql.Connection; @@ -28,8 +28,8 @@ import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test for DataSourceConnectionFactory. @@ -39,7 +39,7 @@ private DataSource datasource; private DataSourceConnectionFactory factory; - @Before + @BeforeEach public void setUp() { datasource = new TestDataSource(); factory = new DataSourceConnectionFactory(datasource); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -28,8 +28,8 @@ import java.sql.Connection; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" }) // BigDecimal methods, and casting for mocks public class TestDelegatingCallableStatement { @@ -38,7 +38,7 @@ private DelegatingCallableStatement delegate = null; private CallableStatement obj = null; - @Before + @BeforeEach public void setUp() throws Exception { conn = new TesterConnection("test", "test"); obj = mock(CallableStatement.class); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,53 +17,63 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ public class TestDelegatingConnection { - private DelegatingConnection conn = null; - private Connection delegateConn = null; - private Connection delegateConn2 = null; + /** + * Delegate that will throw RTE on toString + * Used to validate fix for DBCP-241 + */ + static class RTEGeneratingConnection extends TesterConnection { - @Before - public void setUp() throws Exception { - delegateConn = new TesterConnection("test", "test"); - delegateConn2 = new TesterConnection("test", "test"); - conn = new DelegatingConnection<>(delegateConn); - } + public RTEGeneratingConnection() { + super("",""); + } + + @Override + public String toString() { + throw new RuntimeException("bang!"); + } - @Test - public void testGetDelegate() throws Exception { - assertEquals(delegateConn,conn.getDelegate()); } - @Test - public void testConnectionToString() throws Exception { - final String s = conn.toString(); - assertNotNull(s); - assertTrue(s.length() > 0); + private DelegatingConnection delegatingConnection; + private Connection connection; + private Connection connection2; + private TesterStatement testerStatement; + private TesterResultSet testerResultSet; + + @BeforeEach + public void setUp() throws Exception { + connection = new TesterConnection("test", "test"); + connection2 = new TesterConnection("test", "test"); + delegatingConnection = new DelegatingConnection<>(connection); + testerStatement = new TesterStatement(delegatingConnection); + testerResultSet = new TesterResultSet(testerStatement); } @Test public void testCheckOpen() throws Exception { - conn.checkOpen(); - conn.close(); + delegatingConnection.checkOpen(); + delegatingConnection.close(); try { - conn.checkOpen(); + delegatingConnection.checkOpen(); fail("Expecting SQLException"); } catch (final SQLException ex) { // expected @@ -76,73 +86,118 @@ @Test public void testCheckOpenNull() throws Exception { try { - conn.close(); - conn.checkOpen(); + delegatingConnection.close(); + delegatingConnection.checkOpen(); fail("Expecting SQLException"); } catch (final SQLException ex) { assertTrue(ex.getMessage().endsWith("is closed.")); } try { - conn = new DelegatingConnection<>(null); - conn.setClosedInternal(true); - conn.checkOpen(); + delegatingConnection = new DelegatingConnection<>(null); + delegatingConnection.setClosedInternal(true); + delegatingConnection.checkOpen(); fail("Expecting SQLException"); } catch (final SQLException ex) { assertTrue(ex.getMessage().endsWith("is null.")); } try { - final PoolingConnection pc = new PoolingConnection(delegateConn2); + final PoolingConnection pc = new PoolingConnection(connection2); pc.setStatementPool(new GenericKeyedObjectPool<>(pc)); - conn = new DelegatingConnection<>(pc); + delegatingConnection = new DelegatingConnection<>(pc); pc.close(); - conn.close(); - try (PreparedStatement ps = conn.prepareStatement("")){} + delegatingConnection.close(); + try (PreparedStatement ps = delegatingConnection.prepareStatement("")){} fail("Expecting SQLException"); } catch (final SQLException ex) { assertTrue(ex.getMessage().endsWith("is closed.")); } try { - conn = new DelegatingConnection<>(new RTEGeneratingConnection()); - conn.close(); - conn.checkOpen(); + delegatingConnection = new DelegatingConnection<>(new RTEGeneratingConnection()); + delegatingConnection.close(); + delegatingConnection.checkOpen(); fail("Expecting SQLException"); } catch (final SQLException ex) { assertTrue(ex.getMessage().endsWith("is closed.")); } } - /** - * Delegate that will throw RTE on toString - * Used to validate fix for DBCP-241 - */ - static class RTEGeneratingConnection extends TesterConnection { - public RTEGeneratingConnection() { - super("",""); - } - @Override - public String toString() { - throw new RuntimeException("bang!"); - } + @Test + public void testConnectionToString() throws Exception { + final String s = delegatingConnection.toString(); + assertNotNull(s); + assertTrue(s.length() > 0); + } + @Test + public void testGetDelegate() throws Exception { + assertEquals(connection,delegatingConnection.getDelegate()); } @Test public void testIsClosed() throws Exception { - conn.checkOpen(); - assertFalse(conn.isClosed()); - conn.close(); - assertTrue(conn.isClosed()); + delegatingConnection.checkOpen(); + assertFalse(delegatingConnection.isClosed()); + delegatingConnection.close(); + assertTrue(delegatingConnection.isClosed()); } @Test public void testIsClosedNullDelegate() throws Exception { - conn.checkOpen(); - assertFalse(conn.isClosed()); - conn.setDelegate(null); - assertTrue(conn.isClosed()); + delegatingConnection.checkOpen(); + assertFalse(delegatingConnection.isClosed()); + delegatingConnection.setDelegate(null); + assertTrue(delegatingConnection.isClosed()); + } + + @Test + public void testPassivateWithResultSetCloseException() { + try { + testerResultSet.setSqlExceptionOnClose(true); + delegatingConnection.addTrace(testerResultSet); + delegatingConnection.passivate(); + Assertions.fail("Expected SQLExceptionList"); + } catch (SQLException e) { + Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size()); + } finally { + testerResultSet.setSqlExceptionOnClose(false); + } + } + + @Test + public void testPassivateWithResultSetCloseExceptionAndStatementCloseException() { + try { + testerStatement.setSqlExceptionOnClose(true); + testerResultSet.setSqlExceptionOnClose(true); + delegatingConnection.addTrace(testerStatement); + delegatingConnection.addTrace(testerResultSet); + delegatingConnection.passivate(); + Assertions.fail("Expected SQLExceptionList"); + } catch (SQLException e) { + Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertEquals(2, ((SQLExceptionList) e).getCauseList().size()); + } finally { + testerStatement.setSqlExceptionOnClose(false); + testerResultSet.setSqlExceptionOnClose(false); + } + } + + @Test + public void testPassivateWithStatementCloseException() { + try { + testerStatement.setSqlExceptionOnClose(true); + delegatingConnection.addTrace(testerStatement); + delegatingConnection.passivate(); + Assertions.fail("Expected SQLExceptionList"); + } catch (SQLException e) { + Assertions.assertTrue(e instanceof SQLExceptionList); + Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size()); + } finally { + testerStatement.setSqlExceptionOnClose(false); + } } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -29,8 +29,8 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test suite for {@link DelegatingDatabaseMetaData}. @@ -42,7 +42,7 @@ private DelegatingDatabaseMetaData delegate = null; private DatabaseMetaData obj = null; - @Before + @BeforeEach public void setUp() throws Exception { obj = mock(DatabaseMetaData.class); testConn = new TesterConnection("test", "test"); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,9 +17,9 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -27,8 +27,8 @@ import java.sql.PreparedStatement; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; @SuppressWarnings({ "deprecation", "rawtypes" }) // BigDecimal methods, and casting for mocks public class TestDelegatingPreparedStatement { @@ -38,7 +38,7 @@ private PreparedStatement obj = null; private DelegatingPreparedStatement delegate = null; - @Before + @BeforeEach public void setUp() throws Exception { testerConn = new TesterConnection("test", "test"); connection = new DelegatingConnection<>(testerConn); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -29,9 +29,9 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Tests for DelegatingResultSet. @@ -44,7 +44,7 @@ private ResultSet rs; private DelegatingResultSet delegate; - @Before + @BeforeEach public void setUp() { testConn = new TesterConnection("foo", "bar"); conn = new DelegatingConnection<>(testConn); @@ -179,7 +179,7 @@ } // FIXME: this appears to be a bug - @Ignore + @Disabled @Test public void testGetBigDecimalStringInteger() throws Exception { try { @@ -190,7 +190,7 @@ } // FIXME: this appears to be a bug - @Ignore + @Disabled @Test public void testGetBigDecimalIntegerInteger() throws Exception { try { @@ -1630,7 +1630,7 @@ } // FIXME this appears to be a bug - @Ignore + @Disabled @Test public void testUpdateObjectStringObjectInteger() throws Exception { try { @@ -1641,7 +1641,7 @@ } // FIXME: this appears to be a bug - @Ignore + @Disabled @Test public void testUpdateObjectIntegerObjectInteger() throws Exception { try { diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,54 +17,82 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.lang.reflect.Proxy; import java.sql.Connection; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestDelegatingStatement { - private DelegatingConnection conn = null; - private Connection delegateConn = null; - private Statement obj = null; - private DelegatingStatement delegate = null; + private static class TesterStatementNonWrapping extends TesterStatement { + + public TesterStatementNonWrapping(final Connection conn) { + super(conn); + } - @Before + @Override + public boolean isWrapperFor(final Class iface) throws SQLException { + return false; + } + } + + private DelegatingConnection delegatingConnection; + private TesterConnection testerConnection; + private Statement mockedStatement; + private DelegatingStatement delegatingStatement; + private DelegatingStatement delegatingTesterStatement; + private TesterResultSet testerResultSet; + private TesterStatement testerStatement; + + @BeforeEach public void setUp() throws Exception { - delegateConn = new TesterConnection("test", "test"); - conn = new DelegatingConnection<>(delegateConn); - obj = mock(Statement.class); - delegate = new DelegatingStatement(conn, obj); + testerConnection = new TesterConnection("test", "test"); + delegatingConnection = new DelegatingConnection<>(testerConnection); + mockedStatement = mock(Statement.class); + testerStatement = new TesterStatement(testerConnection); + delegatingStatement = new DelegatingStatement(delegatingConnection, mockedStatement); + delegatingTesterStatement = new DelegatingStatement(delegatingConnection, testerStatement); + testerResultSet = new TesterResultSet(mockedStatement); } @Test - public void testExecuteQueryReturnsNull() throws Exception { - assertNull(delegate.executeQuery("null")); + public void testAddBatchString() throws Exception { + try { + delegatingStatement.addBatch("foo"); + } catch (final SQLException e) { + } + verify(mockedStatement, times(1)).addBatch("foo"); } @Test - public void testGetDelegate() throws Exception { - assertEquals(obj,delegate.getDelegate()); + public void testCancel() throws Exception { + try { + delegatingStatement.cancel(); + } catch (final SQLException e) { + } + verify(mockedStatement, times(1)).cancel(); } @Test public void testCheckOpen() throws Exception { - delegate.checkOpen(); - delegate.close(); + delegatingStatement.checkOpen(); + delegatingStatement.close(); try { - delegate.checkOpen(); + delegatingStatement.checkOpen(); fail("Expecting SQLException"); } catch (final SQLException ex) { // expected @@ -72,222 +100,207 @@ } @Test - public void testIsWrapperFor() throws Exception { - final TesterConnection tstConn = new TesterConnection("test", "test"); - final TesterStatement tstStmt = new TesterStatementNonWrapping(tstConn); - final DelegatingConnection dconn = new DelegatingConnection<>(tstConn); - final DelegatingStatement stamt = new DelegatingStatement(dconn, tstStmt); - - final Class stmtProxyClass = Proxy.getProxyClass( - this.getClass().getClassLoader(), - Statement.class); - - assertTrue(stamt.isWrapperFor(DelegatingStatement.class)); - assertTrue(stamt.isWrapperFor(TesterStatement.class)); - assertFalse(stamt.isWrapperFor(stmtProxyClass)); - - stamt.close(); - } - - private static class TesterStatementNonWrapping extends TesterStatement { - - public TesterStatementNonWrapping(final Connection conn) { - super(conn); - } - - @Override - public boolean isWrapperFor(final Class iface) throws SQLException { - return false; - } - } - - @Test - public void testAddBatchString() throws Exception { + public void testClearBatch() throws Exception { try { - delegate.addBatch("foo"); + delegatingStatement.clearBatch(); } catch (final SQLException e) { } - verify(obj, times(1)).addBatch("foo"); + verify(mockedStatement, times(1)).clearBatch(); } @Test - public void testCancel() throws Exception { + public void testClearWarnings() throws Exception { try { - delegate.cancel(); + delegatingStatement.clearWarnings(); } catch (final SQLException e) { } - verify(obj, times(1)).cancel(); + verify(mockedStatement, times(1)).clearWarnings(); } @Test - public void testClearBatch() throws Exception { + public void testClose() throws Exception { try { - delegate.clearBatch(); + delegatingStatement.close(); } catch (final SQLException e) { } - verify(obj, times(1)).clearBatch(); + verify(mockedStatement, times(1)).close(); } @Test - public void testClearWarnings() throws Exception { + public void testCloseWithResultSetCloseException() throws Exception { try { - delegate.clearWarnings(); + testerResultSet.setSqlExceptionOnClose(true); + delegatingStatement.addTrace(testerResultSet); + delegatingStatement.close(); + Assertions.fail("Excpected a SQLExceptionList"); } catch (final SQLException e) { + Assertions.assertTrue(e instanceof SQLExceptionList); + } finally { + testerResultSet.setSqlExceptionOnClose(false); } - verify(obj, times(1)).clearWarnings(); + verify(mockedStatement, times(1)).close(); } @Test - public void testClose() throws Exception { + public void testCloseWithStatementCloseException() throws Exception { try { - delegate.close(); + testerStatement.setSqlExceptionOnClose(true); + delegatingTesterStatement.close(); + Assertions.fail("Excpected a SQLExceptionList"); } catch (final SQLException e) { + Assertions.assertTrue(e instanceof SQLExceptionList); + } finally { + testerStatement.setSqlExceptionOnClose(false); } - verify(obj, times(1)).close(); } @Test public void testCloseOnCompletion() throws Exception { try { - delegate.closeOnCompletion(); + delegatingStatement.closeOnCompletion(); } catch (final SQLException e) { } - verify(obj, times(1)).closeOnCompletion(); + verify(mockedStatement, times(1)).closeOnCompletion(); } @Test - public void testExecuteStringIntegerArray() throws Exception { + public void testExecuteBatch() throws Exception { try { - delegate.execute("foo", (int[]) null); + delegatingStatement.executeBatch(); } catch (final SQLException e) { } - verify(obj, times(1)).execute("foo", (int[]) null); + verify(mockedStatement, times(1)).executeBatch(); } @Test - public void testExecuteString() throws Exception { + public void testExecuteLargeBatch() throws Exception { try { - delegate.execute("foo"); + delegatingStatement.executeLargeBatch(); } catch (final SQLException e) { } - verify(obj, times(1)).execute("foo"); + verify(mockedStatement, times(1)).executeLargeBatch(); } @Test - public void testExecuteStringStringArray() throws Exception { + public void testExecuteLargeUpdateString() throws Exception { try { - delegate.execute("foo", (String[]) null); + delegatingStatement.executeLargeUpdate("foo"); } catch (final SQLException e) { } - verify(obj, times(1)).execute("foo", (String[]) null); + verify(mockedStatement, times(1)).executeLargeUpdate("foo"); } @Test - public void testExecuteStringInteger() throws Exception { + public void testExecuteLargeUpdateStringInteger() throws Exception { try { - delegate.execute("foo", 1); + delegatingStatement.executeLargeUpdate("foo", 1); } catch (final SQLException e) { } - verify(obj, times(1)).execute("foo", 1); + verify(mockedStatement, times(1)).executeLargeUpdate("foo", 1); } @Test - public void testExecuteBatch() throws Exception { + public void testExecuteLargeUpdateStringIntegerArray() throws Exception { try { - delegate.executeBatch(); + delegatingStatement.executeLargeUpdate("foo", (int[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeBatch(); + verify(mockedStatement, times(1)).executeLargeUpdate("foo", (int[]) null); } @Test - public void testExecuteLargeBatch() throws Exception { + public void testExecuteLargeUpdateStringStringArray() throws Exception { try { - delegate.executeLargeBatch(); + delegatingStatement.executeLargeUpdate("foo", (String[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeLargeBatch(); + verify(mockedStatement, times(1)).executeLargeUpdate("foo", (String[]) null); } @Test - public void testExecuteLargeUpdateStringInteger() throws Exception { + public void testExecuteQueryReturnsNull() throws Exception { + assertNull(delegatingStatement.executeQuery("null")); + } + + @Test + public void testExecuteQueryString() throws Exception { try { - delegate.executeLargeUpdate("foo", 1); + delegatingStatement.executeQuery("foo"); } catch (final SQLException e) { } - verify(obj, times(1)).executeLargeUpdate("foo", 1); + verify(mockedStatement, times(1)).executeQuery("foo"); } @Test - public void testExecuteLargeUpdateStringIntegerArray() throws Exception { + public void testExecuteString() throws Exception { try { - delegate.executeLargeUpdate("foo", (int[]) null); + delegatingStatement.execute("foo"); } catch (final SQLException e) { } - verify(obj, times(1)).executeLargeUpdate("foo", (int[]) null); + verify(mockedStatement, times(1)).execute("foo"); } @Test - public void testExecuteLargeUpdateString() throws Exception { + public void testExecuteStringInteger() throws Exception { try { - delegate.executeLargeUpdate("foo"); + delegatingStatement.execute("foo", 1); } catch (final SQLException e) { } - verify(obj, times(1)).executeLargeUpdate("foo"); + verify(mockedStatement, times(1)).execute("foo", 1); } @Test - public void testExecuteLargeUpdateStringStringArray() throws Exception { + public void testExecuteStringIntegerArray() throws Exception { try { - delegate.executeLargeUpdate("foo", (String[]) null); + delegatingStatement.execute("foo", (int[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeLargeUpdate("foo", (String[]) null); + verify(mockedStatement, times(1)).execute("foo", (int[]) null); } @Test - public void testExecuteQueryString() throws Exception { + public void testExecuteStringStringArray() throws Exception { try { - delegate.executeQuery("foo"); + delegatingStatement.execute("foo", (String[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeQuery("foo"); + verify(mockedStatement, times(1)).execute("foo", (String[]) null); } @Test - public void testExecuteUpdateStringIntegerArray() throws Exception { + public void testExecuteUpdateString() throws Exception { try { - delegate.executeUpdate("foo", (int[]) null); + delegatingStatement.executeUpdate("foo"); } catch (final SQLException e) { } - verify(obj, times(1)).executeUpdate("foo", (int[]) null); + verify(mockedStatement, times(1)).executeUpdate("foo"); } @Test - public void testExecuteUpdateStringStringArray() throws Exception { + public void testExecuteUpdateStringInteger() throws Exception { try { - delegate.executeUpdate("foo", (String[]) null); + delegatingStatement.executeUpdate("foo", 1); } catch (final SQLException e) { } - verify(obj, times(1)).executeUpdate("foo", (String[]) null); + verify(mockedStatement, times(1)).executeUpdate("foo", 1); } @Test - public void testExecuteUpdateString() throws Exception { + public void testExecuteUpdateStringIntegerArray() throws Exception { try { - delegate.executeUpdate("foo"); + delegatingStatement.executeUpdate("foo", (int[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeUpdate("foo"); + verify(mockedStatement, times(1)).executeUpdate("foo", (int[]) null); } @Test - public void testExecuteUpdateStringInteger() throws Exception { + public void testExecuteUpdateStringStringArray() throws Exception { try { - delegate.executeUpdate("foo", 1); + delegatingStatement.executeUpdate("foo", (String[]) null); } catch (final SQLException e) { } - verify(obj, times(1)).executeUpdate("foo", 1); + verify(mockedStatement, times(1)).executeUpdate("foo", (String[]) null); } /** @@ -299,163 +312,159 @@ @Test public void testGetConnection() throws Exception { try { - delegate.getConnection(); + delegatingStatement.getConnection(); } catch (final SQLException e) { } - verify(obj, times(0)).getConnection(); + verify(mockedStatement, times(0)).getConnection(); + } + + @Test + public void testGetDelegate() throws Exception { + assertEquals(mockedStatement,delegatingStatement.getDelegate()); } @Test public void testGetFetchDirection() throws Exception { try { - delegate.getFetchDirection(); + delegatingStatement.getFetchDirection(); } catch (final SQLException e) { } - verify(obj, times(1)).getFetchDirection(); + verify(mockedStatement, times(1)).getFetchDirection(); } @Test public void testGetFetchSize() throws Exception { try { - delegate.getFetchSize(); + delegatingStatement.getFetchSize(); } catch (final SQLException e) { } - verify(obj, times(1)).getFetchSize(); + verify(mockedStatement, times(1)).getFetchSize(); } @Test public void testGetGeneratedKeys() throws Exception { try { - delegate.getGeneratedKeys(); + delegatingStatement.getGeneratedKeys(); } catch (final SQLException e) { } - verify(obj, times(1)).getGeneratedKeys(); + verify(mockedStatement, times(1)).getGeneratedKeys(); } @Test public void testGetLargeMaxRows() throws Exception { try { - delegate.getLargeMaxRows(); + delegatingStatement.getLargeMaxRows(); } catch (final SQLException e) { } - verify(obj, times(1)).getLargeMaxRows(); + verify(mockedStatement, times(1)).getLargeMaxRows(); } @Test public void testGetLargeUpdateCount() throws Exception { try { - delegate.getLargeUpdateCount(); + delegatingStatement.getLargeUpdateCount(); } catch (final SQLException e) { } - verify(obj, times(1)).getLargeUpdateCount(); + verify(mockedStatement, times(1)).getLargeUpdateCount(); } @Test public void testGetMaxFieldSize() throws Exception { try { - delegate.getMaxFieldSize(); + delegatingStatement.getMaxFieldSize(); } catch (final SQLException e) { } - verify(obj, times(1)).getMaxFieldSize(); + verify(mockedStatement, times(1)).getMaxFieldSize(); } @Test public void testGetMaxRows() throws Exception { try { - delegate.getMaxRows(); + delegatingStatement.getMaxRows(); } catch (final SQLException e) { } - verify(obj, times(1)).getMaxRows(); + verify(mockedStatement, times(1)).getMaxRows(); } @Test - public void testGetMoreResultsInteger() throws Exception { + public void testGetMoreResults() throws Exception { try { - delegate.getMoreResults(1); + delegatingStatement.getMoreResults(); } catch (final SQLException e) { } - verify(obj, times(1)).getMoreResults(1); + verify(mockedStatement, times(1)).getMoreResults(); } @Test - public void testGetMoreResults() throws Exception { + public void testGetMoreResultsInteger() throws Exception { try { - delegate.getMoreResults(); + delegatingStatement.getMoreResults(1); } catch (final SQLException e) { } - verify(obj, times(1)).getMoreResults(); + verify(mockedStatement, times(1)).getMoreResults(1); } @Test public void testGetQueryTimeout() throws Exception { try { - delegate.getQueryTimeout(); + delegatingStatement.getQueryTimeout(); } catch (final SQLException e) { } - verify(obj, times(1)).getQueryTimeout(); + verify(mockedStatement, times(1)).getQueryTimeout(); } @Test public void testGetResultSet() throws Exception { try { - delegate.getResultSet(); + delegatingStatement.getResultSet(); } catch (final SQLException e) { } - verify(obj, times(1)).getResultSet(); + verify(mockedStatement, times(1)).getResultSet(); } @Test public void testGetResultSetConcurrency() throws Exception { try { - delegate.getResultSetConcurrency(); + delegatingStatement.getResultSetConcurrency(); } catch (final SQLException e) { } - verify(obj, times(1)).getResultSetConcurrency(); + verify(mockedStatement, times(1)).getResultSetConcurrency(); } @Test public void testGetResultSetHoldability() throws Exception { try { - delegate.getResultSetHoldability(); + delegatingStatement.getResultSetHoldability(); } catch (final SQLException e) { } - verify(obj, times(1)).getResultSetHoldability(); + verify(mockedStatement, times(1)).getResultSetHoldability(); } @Test public void testGetResultSetType() throws Exception { try { - delegate.getResultSetType(); + delegatingStatement.getResultSetType(); } catch (final SQLException e) { } - verify(obj, times(1)).getResultSetType(); + verify(mockedStatement, times(1)).getResultSetType(); } @Test public void testGetUpdateCount() throws Exception { try { - delegate.getUpdateCount(); + delegatingStatement.getUpdateCount(); } catch (final SQLException e) { } - verify(obj, times(1)).getUpdateCount(); + verify(mockedStatement, times(1)).getUpdateCount(); } @Test public void testGetWarnings() throws Exception { try { - delegate.getWarnings(); + delegatingStatement.getWarnings(); } catch (final SQLException e) { } - verify(obj, times(1)).getWarnings(); - } - - @Test - public void testIsCloseOnCompletion() throws Exception { - try { - delegate.isCloseOnCompletion(); - } catch (final SQLException e) { - } - verify(obj, times(1)).isCloseOnCompletion(); + verify(mockedStatement, times(1)).getWarnings(); } /** @@ -467,111 +476,138 @@ @Test public void testIsClosed() throws Exception { try { - delegate.isClosed(); + delegatingStatement.isClosed(); } catch (final SQLException e) { } - verify(obj, times(0)).isClosed(); + verify(mockedStatement, times(0)).isClosed(); + } + + @Test + public void testIsCloseOnCompletion() throws Exception { + try { + delegatingStatement.isCloseOnCompletion(); + } catch (final SQLException e) { + } + verify(mockedStatement, times(1)).isCloseOnCompletion(); } @Test public void testIsPoolable() throws Exception { try { - delegate.isPoolable(); + delegatingStatement.isPoolable(); } catch (final SQLException e) { } - verify(obj, times(1)).isPoolable(); + verify(mockedStatement, times(1)).isPoolable(); + } + + @Test + public void testIsWrapperFor() throws Exception { + final TesterConnection tstConn = new TesterConnection("test", "test"); + final TesterStatement tstStmt = new TesterStatementNonWrapping(tstConn); + final DelegatingConnection dconn = new DelegatingConnection<>(tstConn); + final DelegatingStatement stamt = new DelegatingStatement(dconn, tstStmt); + + final Class stmtProxyClass = Proxy.getProxyClass( + this.getClass().getClassLoader(), + Statement.class); + + assertTrue(stamt.isWrapperFor(DelegatingStatement.class)); + assertTrue(stamt.isWrapperFor(TesterStatement.class)); + assertFalse(stamt.isWrapperFor(stmtProxyClass)); + + stamt.close(); } @Test public void testSetCursorNameString() throws Exception { try { - delegate.setCursorName("foo"); + delegatingStatement.setCursorName("foo"); } catch (final SQLException e) { } - verify(obj, times(1)).setCursorName("foo"); + verify(mockedStatement, times(1)).setCursorName("foo"); } @Test public void testSetEscapeProcessingBoolean() throws Exception { try { - delegate.setEscapeProcessing(Boolean.TRUE); + delegatingStatement.setEscapeProcessing(Boolean.TRUE); } catch (final SQLException e) { } - verify(obj, times(1)).setEscapeProcessing(Boolean.TRUE); + verify(mockedStatement, times(1)).setEscapeProcessing(Boolean.TRUE); } @Test public void testSetFetchDirectionInteger() throws Exception { try { - delegate.setFetchDirection(1); + delegatingStatement.setFetchDirection(1); } catch (final SQLException e) { } - verify(obj, times(1)).setFetchDirection(1); + verify(mockedStatement, times(1)).setFetchDirection(1); } @Test public void testSetFetchSizeInteger() throws Exception { try { - delegate.setFetchSize(1); + delegatingStatement.setFetchSize(1); } catch (final SQLException e) { } - verify(obj, times(1)).setFetchSize(1); + verify(mockedStatement, times(1)).setFetchSize(1); } @Test public void testSetLargeMaxRowsLong() throws Exception { try { - delegate.setLargeMaxRows(1l); + delegatingStatement.setLargeMaxRows(1l); } catch (final SQLException e) { } - verify(obj, times(1)).setLargeMaxRows(1l); + verify(mockedStatement, times(1)).setLargeMaxRows(1l); } @Test public void testSetMaxFieldSizeInteger() throws Exception { try { - delegate.setMaxFieldSize(1); + delegatingStatement.setMaxFieldSize(1); } catch (final SQLException e) { } - verify(obj, times(1)).setMaxFieldSize(1); + verify(mockedStatement, times(1)).setMaxFieldSize(1); } @Test public void testSetMaxRowsInteger() throws Exception { try { - delegate.setMaxRows(1); + delegatingStatement.setMaxRows(1); } catch (final SQLException e) { } - verify(obj, times(1)).setMaxRows(1); + verify(mockedStatement, times(1)).setMaxRows(1); } @Test public void testSetPoolableBoolean() throws Exception { try { - delegate.setPoolable(Boolean.TRUE); + delegatingStatement.setPoolable(Boolean.TRUE); } catch (final SQLException e) { } - verify(obj, times(1)).setPoolable(Boolean.TRUE); + verify(mockedStatement, times(1)).setPoolable(Boolean.TRUE); } @Test public void testSetQueryTimeoutInteger() throws Exception { try { - delegate.setQueryTimeout(1); + delegatingStatement.setQueryTimeout(1); } catch (final SQLException e) { } - verify(obj, times(1)).setQueryTimeout(1); + verify(mockedStatement, times(1)).setQueryTimeout(1); } @Test public void testWrap() throws SQLException { - assertEquals(delegate, delegate.unwrap(Statement.class)); - assertEquals(delegate, delegate.unwrap(DelegatingStatement.class)); - assertEquals(obj, delegate.unwrap(obj.getClass())); - assertNull(delegate.unwrap(String.class)); - assertTrue(delegate.isWrapperFor(Statement.class)); - assertTrue(delegate.isWrapperFor(DelegatingStatement.class)); - assertTrue(delegate.isWrapperFor(obj.getClass())); - assertFalse(delegate.isWrapperFor(String.class)); + assertEquals(delegatingStatement, delegatingStatement.unwrap(Statement.class)); + assertEquals(delegatingStatement, delegatingStatement.unwrap(DelegatingStatement.class)); + assertEquals(mockedStatement, delegatingStatement.unwrap(mockedStatement.getClass())); + assertNull(delegatingStatement.unwrap(String.class)); + assertTrue(delegatingStatement.isWrapperFor(Statement.class)); + assertTrue(delegatingStatement.isWrapperFor(DelegatingStatement.class)); + assertTrue(delegatingStatement.isWrapperFor(mockedStatement.getClass())); + assertFalse(delegatingStatement.isWrapperFor(String.class)); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDriverConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDriverConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDriverConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDriverConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,13 +17,13 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.sql.SQLException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for DriverConnectionFactory. diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,8 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; @@ -27,9 +28,9 @@ import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** * This test *must* execute before all other tests to be effective as it tests @@ -40,12 +41,12 @@ private static final String KEY_JDBC_DRIVERS = "jdbc.drivers"; - @BeforeClass + @BeforeAll public static void beforeClass() { System.setProperty(KEY_JDBC_DRIVERS, "org.apache.commons.dbcp2.TesterDriver"); } - @AfterClass + @AfterAll public static void afterClass() { System.clearProperty(KEY_JDBC_DRIVERS); } @@ -67,22 +68,22 @@ testDriverManagerInit(false); } - @Test(expected=IndexOutOfBoundsException.class) // thrown by TestDriver due to missing user - public void testDriverManagerWithoutUser() throws SQLException { + @Test + public void testDriverManagerWithoutUser() { final DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", null, "pass"); - cf.createConnection(); + assertThrows(IndexOutOfBoundsException.class, cf::createConnection); // thrown by TestDriver due to missing user } - @Test(expected=SQLException.class) // thrown by TestDriver due to invalid password - public void testDriverManagerWithoutPassword() throws SQLException { + @Test + public void testDriverManagerWithoutPassword() { final DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", "user", (char[]) null); - cf.createConnection(); + assertThrows(SQLException.class, cf::createConnection); // thrown by TestDriver due to invalid password } - @Test(expected=ArrayIndexOutOfBoundsException.class) // thrown by TestDriver due to missing user - public void testDriverManagerWithoutCredentials() throws SQLException { + @Test + public void testDriverManagerWithoutCredentials() { final DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", null, (char[]) null); - cf.createConnection(); + assertThrows(ArrayIndexOutOfBoundsException.class, cf::createConnection); // thrown by TestDriver due to missing user } @Test diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterCallableStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -76,7 +76,7 @@ } /** - * @deprecated + * @deprecated See {@link CallableStatement#getBigDecimal(int,int)}. */ @Deprecated @Override diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterConnectionFactory.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterConnectionFactory.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterConnectionFactory.java 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterConnectionFactory.java 2019-07-31 12:46:24.000000000 +0000 @@ -0,0 +1,84 @@ +/* + * 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.Connection; +import java.sql.Driver; +import java.sql.SQLException; +import java.util.Properties; + +/** + * Dummy {@link ConnectionFactory} for testing purpose. + */ +public class TesterConnectionFactory implements ConnectionFactory { + + private final String connectionString; + private final Driver driver; + private final Properties properties; + + /** + * Constructs a connection factory for a given Driver. + * + * @param driver The Driver. + * @param connectString The connection string. + * @param properties The connection properties. + */ + public TesterConnectionFactory(final Driver driver, final String connectString, final Properties properties) { + this.driver = driver; + this.connectionString = connectString; + this.properties = properties; + } + + @Override + public Connection createConnection() throws SQLException { + Connection conn = driver.connect(connectionString, properties); + doSomething(conn); + return conn; + } + + private void doSomething(Connection conn) { + // do something + } + + /** + * @return The connection String. + */ + public String getConnectionString() { + return connectionString; + } + + /** + * @return The Driver. + */ + public Driver getDriver() { + return driver; + } + + /** + * @return The Properties. + */ + public Properties getProperties() { + return properties; + } + + @Override + public String toString() { + return this.getClass().getName() + " [" + String.valueOf(driver) + ";" + String.valueOf(connectionString) + ";" + + String.valueOf(properties) + "]"; + } +} diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -38,30 +38,45 @@ /** * A dummy {@link Connection}, for testing purposes. */ -public class TesterConnection implements Connection { +public class TesterConnection extends AbandonedTrace implements Connection { + protected boolean _open = true; protected boolean _autoCommit = true; protected int _transactionIsolation = 1; protected DatabaseMetaData _metaData = new TesterDatabaseMetaData(); - protected String _catalog = null; + protected String _catalog; protected String schema; - protected Map> _typeMap = null; - protected boolean _readOnly = false; - protected SQLWarning warnings = null; - protected String userName = null; + protected Map> _typeMap; + protected boolean _readOnly; + protected SQLWarning warnings; + protected String userName; protected Exception failure; + protected boolean sqlExceptionOnClose; - public TesterConnection(final String userName, + TesterConnection(final String userName, @SuppressWarnings("unused") final String password) { this.userName = userName; } - public String getUserName() { - return this.userName; + @Override + public void abort(final Executor executor) throws SQLException { + throw new SQLException("Not implemented."); } - public void setWarnings(final SQLWarning warning) { - this.warnings = warning; + protected void checkFailure() throws SQLException { + if (failure != null) { + if(failure instanceof SQLException) { + throw (SQLException)failure; + } + throw new SQLException("TesterConnection failure", failure); + } + } + + protected void checkOpen() throws SQLException { + if(!_open) { + throw new SQLException("Connection is closed."); + } + checkFailure(); } @Override @@ -85,208 +100,166 @@ } @Override - public Statement createStatement() throws SQLException { - checkOpen(); - return new TesterStatement(this); + public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException { + throw new SQLException("Not implemented."); } @Override - public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException { - checkOpen(); - return new TesterStatement(this); + public Blob createBlob() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public boolean getAutoCommit() throws SQLException { - checkOpen(); - return _autoCommit; + public Clob createClob() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public String getCatalog() throws SQLException { - checkOpen(); - return _catalog; + public NClob createNClob() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public DatabaseMetaData getMetaData() throws SQLException { - checkOpen(); - return _metaData; + public SQLXML createSQLXML() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public int getTransactionIsolation() throws SQLException { + public Statement createStatement() throws SQLException { checkOpen(); - return _transactionIsolation; + return new TesterStatement(this); } @Override - public Map> getTypeMap() throws SQLException { + public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException { checkOpen(); - return _typeMap; + return new TesterStatement(this); } @Override - public SQLWarning getWarnings() throws SQLException { - checkOpen(); - return warnings; + public Statement createStatement(final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) + throws SQLException { + return createStatement(); } @Override - public boolean isClosed() throws SQLException { - checkFailure(); - return !_open; + public Struct createStruct(final String typeName, final Object[] attributes) throws SQLException { + throw new SQLException("Not implemented."); } @Override - public boolean isReadOnly() throws SQLException { + public boolean getAutoCommit() throws SQLException { checkOpen(); - return _readOnly; + return _autoCommit; } @Override - public String nativeSQL(final String sql) throws SQLException { + public String getCatalog() throws SQLException { checkOpen(); - return sql; + return _catalog; } @Override - public CallableStatement prepareCall(final String sql) throws SQLException { - checkOpen(); - if ("warning".equals(sql)) { - setWarnings(new SQLWarning("warning in prepareCall")); - } - return new TesterCallableStatement(this, sql); + public Properties getClientInfo() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { - checkOpen(); - return new TesterCallableStatement(this, sql, resultSetType, resultSetConcurrency); + public String getClientInfo(final String name) throws SQLException { + throw new SQLException("Not implemented."); } @Override - public PreparedStatement prepareStatement(final String sql) throws SQLException { - checkOpen(); - if("null".equals(sql)) { - return null; - } if("invalid".equals(sql)) { - throw new SQLException("invalid query"); - } if ("broken".equals(sql)) { - throw new SQLException("broken connection"); - } - return new TesterPreparedStatement(this, sql); + public int getHoldability() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { + public DatabaseMetaData getMetaData() throws SQLException { checkOpen(); - return new TesterPreparedStatement(this, sql, resultSetType, resultSetConcurrency); + return _metaData; } @Override - public void rollback() throws SQLException { - checkOpen(); - if (isReadOnly()) { - throw new SQLException("Cannot rollback a readonly connection"); - } + public int getNetworkTimeout() throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setAutoCommit(final boolean autoCommit) throws SQLException { + public String getSchema() throws SQLException { checkOpen(); - _autoCommit = autoCommit; + return schema; } @Override - public void setCatalog(final String catalog) throws SQLException { + public int getTransactionIsolation() throws SQLException { checkOpen(); - _catalog = catalog; + return _transactionIsolation; } @Override - public void setReadOnly(final boolean readOnly) throws SQLException { + public Map> getTypeMap() throws SQLException { checkOpen(); - _readOnly = readOnly; + return _typeMap; } - @Override - public void setTransactionIsolation(final int level) throws SQLException { - checkOpen(); - _transactionIsolation = level; + public String getUserName() { + return this.userName; } @Override - public void setTypeMap(final Map> map) throws SQLException { + public SQLWarning getWarnings() throws SQLException { checkOpen(); - _typeMap = map; - } - - protected void checkOpen() throws SQLException { - if(!_open) { - throw new SQLException("Connection is closed."); - } - checkFailure(); - } - - protected void checkFailure() throws SQLException { - if (failure != null) { - if(failure instanceof SQLException) { - throw (SQLException)failure; - } - throw new SQLException("TesterConnection failure", failure); - } - } - - public void setFailure(final Exception failure) { - this.failure = failure; + return warnings; } @Override - public int getHoldability() throws SQLException { - throw new SQLException("Not implemented."); + public boolean isClosed() throws SQLException { + checkFailure(); + return !_open; } @Override - public void setHoldability(final int holdability) throws SQLException { - throw new SQLException("Not implemented."); + public boolean isReadOnly() throws SQLException { + checkOpen(); + return _readOnly; } - @Override - public java.sql.Savepoint setSavepoint() throws SQLException { - throw new SQLException("Not implemented."); + public boolean isSqlExceptionOnClose() { + return sqlExceptionOnClose; } @Override - public java.sql.Savepoint setSavepoint(final String name) throws SQLException { - throw new SQLException("Not implemented."); + public boolean isValid(final int timeout) throws SQLException { + return _open; } @Override - public void rollback(final java.sql.Savepoint savepoint) throws SQLException { + public boolean isWrapperFor(final Class iface) throws SQLException { throw new SQLException("Not implemented."); } @Override - public void releaseSavepoint(final java.sql.Savepoint savepoint) throws SQLException { - throw new SQLException("Not implemented."); + public String nativeSQL(final String sql) throws SQLException { + checkOpen(); + return sql; } @Override - public Statement createStatement(final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) - throws SQLException { - return createStatement(); + public CallableStatement prepareCall(final String sql) throws SQLException { + checkOpen(); + if ("warning".equals(sql)) { + setWarnings(new SQLWarning("warning in prepareCall")); + } + return new TesterCallableStatement(this, sql); } @Override - public PreparedStatement prepareStatement(final String sql, final int resultSetType, - final int resultSetConcurrency, - final int resultSetHoldability) - throws SQLException { + public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { checkOpen(); - return new TesterPreparedStatement(this, sql, resultSetType, resultSetConcurrency, resultSetHoldability); + return new TesterCallableStatement(this, sql, resultSetType, resultSetConcurrency); } @Override @@ -299,6 +272,19 @@ } @Override + public PreparedStatement prepareStatement(final String sql) throws SQLException { + checkOpen(); + if("null".equals(sql)) { + return null; + } if("invalid".equals(sql)) { + throw new SQLException("invalid query"); + } if ("broken".equals(sql)) { + throw new SQLException("broken connection"); + } + return new TesterPreparedStatement(this, sql); + } + + @Override public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException { checkOpen(); @@ -312,74 +298,95 @@ } @Override - public PreparedStatement prepareStatement(final String sql, final String columnNames[]) + public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { + checkOpen(); + return new TesterPreparedStatement(this, sql, resultSetType, resultSetConcurrency); + } + + @Override + public PreparedStatement prepareStatement(final String sql, final int resultSetType, + final int resultSetConcurrency, + final int resultSetHoldability) throws SQLException { - return new TesterPreparedStatement(this, sql, columnNames); + checkOpen(); + return new TesterPreparedStatement(this, sql, resultSetType, resultSetConcurrency, resultSetHoldability); } @Override - public boolean isWrapperFor(final Class iface) throws SQLException { - throw new SQLException("Not implemented."); + public PreparedStatement prepareStatement(final String sql, final String columnNames[]) + throws SQLException { + return new TesterPreparedStatement(this, sql, columnNames); } @Override - public T unwrap(final Class iface) throws SQLException { + public void releaseSavepoint(final java.sql.Savepoint savepoint) throws SQLException { throw new SQLException("Not implemented."); } @Override - public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException { - throw new SQLException("Not implemented."); + public void rollback() throws SQLException { + checkOpen(); + if (isReadOnly()) { + throw new SQLException("Cannot rollback a readonly connection"); + } } @Override - public Blob createBlob() throws SQLException { + public void rollback(final java.sql.Savepoint savepoint) throws SQLException { throw new SQLException("Not implemented."); } @Override - public Clob createClob() throws SQLException { - throw new SQLException("Not implemented."); + public void setAutoCommit(final boolean autoCommit) throws SQLException { + checkOpen(); + _autoCommit = autoCommit; } @Override - public NClob createNClob() throws SQLException { - throw new SQLException("Not implemented."); + public void setCatalog(final String catalog) throws SQLException { + checkOpen(); + _catalog = catalog; } @Override - public SQLXML createSQLXML() throws SQLException { - throw new SQLException("Not implemented."); + public void setClientInfo(final Properties properties) throws SQLClientInfoException { + throw new SQLClientInfoException(); } @Override - public Struct createStruct(final String typeName, final Object[] attributes) throws SQLException { - throw new SQLException("Not implemented."); + public void setClientInfo(final String name, final String value) throws SQLClientInfoException { + throw new SQLClientInfoException(); + } + + public void setFailure(final Exception failure) { + this.failure = failure; } @Override - public boolean isValid(final int timeout) throws SQLException { - return _open; + public void setHoldability(final int holdability) throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setClientInfo(final String name, final String value) throws SQLClientInfoException { - throw new SQLClientInfoException(); + public void setNetworkTimeout(final Executor executor, final int milliseconds) + throws SQLException { + throw new SQLException("Not implemented."); } @Override - public void setClientInfo(final Properties properties) throws SQLClientInfoException { - throw new SQLClientInfoException(); + public void setReadOnly(final boolean readOnly) throws SQLException { + checkOpen(); + _readOnly = readOnly; } @Override - public Properties getClientInfo() throws SQLException { + public java.sql.Savepoint setSavepoint() throws SQLException { throw new SQLException("Not implemented."); } @Override - public String getClientInfo(final String name) throws SQLException { + public java.sql.Savepoint setSavepoint(final String name) throws SQLException { throw new SQLException("Not implemented."); } @@ -389,25 +396,28 @@ this.schema= schema; } + public void setSqlExceptionOnClose(boolean sqlExceptionOnClose) { + this.sqlExceptionOnClose = sqlExceptionOnClose; + } + @Override - public String getSchema() throws SQLException { + public void setTransactionIsolation(final int level) throws SQLException { checkOpen(); - return schema; + _transactionIsolation = level; } @Override - public void abort(final Executor executor) throws SQLException { - throw new SQLException("Not implemented."); + public void setTypeMap(final Map> map) throws SQLException { + checkOpen(); + _typeMap = map; } - @Override - public void setNetworkTimeout(final Executor executor, final int milliseconds) - throws SQLException { - throw new SQLException("Not implemented."); + public void setWarnings(final SQLWarning warning) { + this.warnings = warning; } @Override - public int getNetworkTimeout() throws SQLException { + public T unwrap(final Class iface) throws SQLException { throw new SQLException("Not implemented."); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterPreparedStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -39,6 +39,7 @@ * A dummy {@link PreparedStatement}, for testing purposes. */ public class TesterPreparedStatement extends TesterStatement implements PreparedStatement { + private final ResultSetMetaData _resultSetMetaData = null; private String _sql = null; private String _catalog = null; diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterResultSet.java 2019-07-31 12:46:24.000000000 +0000 @@ -40,18 +40,16 @@ /** * A dummy {@link ResultSet}, for testing purposes. */ -public class TesterResultSet implements ResultSet { - protected int _type = ResultSet.TYPE_FORWARD_ONLY; +public class TesterResultSet extends AbandonedTrace implements ResultSet { + protected int _type = ResultSet.TYPE_FORWARD_ONLY; protected int _concurrency = ResultSet.CONCUR_READ_ONLY; - protected Object[][] _data = null; - protected int _currentRow = -1; protected Statement _statement = null; - protected int _rowsLeft = 2; protected boolean _open = true; + protected boolean _sqlExceptionOnClose = false; public TesterResultSet(final Statement stmt) { _statement = stmt; @@ -101,6 +99,10 @@ @Override public void close() throws SQLException { + if (_sqlExceptionOnClose) { + throw new SQLException("TestSQLExceptionOnClose"); + } + if (!_open) { return; } @@ -641,6 +643,10 @@ return _rowsLeft == 0; } + public boolean isSqlExceptionOnClose() { + return _sqlExceptionOnClose; + } + @Override public boolean isWrapperFor(final Class iface) throws SQLException { throw new SQLException("Not implemented."); @@ -720,6 +726,10 @@ checkOpen(); } + public void setSqlExceptionOnClose(final boolean sqlExceptionOnClose) { + this._sqlExceptionOnClose = sqlExceptionOnClose; + } + @Override public T unwrap(final Class iface) throws SQLException { throw new SQLException("Not implemented."); @@ -742,6 +752,7 @@ throw new SQLException("Not implemented."); } + @Override public void updateAsciiStream(final int columnIndex, final InputStream inputStream, final long length) throws SQLException { throw new SQLException("Not implemented."); @@ -754,7 +765,6 @@ checkOpen(); } - @Override public void updateAsciiStream(final String columnLabel, final InputStream inputStream) throws SQLException { throw new SQLException("Not implemented."); @@ -890,6 +900,7 @@ throw new SQLException("Not implemented."); } + @Override public void updateCharacterStream(final int columnIndex, final Reader reader, final long length) throws SQLException { throw new SQLException("Not implemented."); @@ -902,7 +913,6 @@ checkOpen(); } - @Override public void updateCharacterStream(final String columnLabel, final Reader reader) throws SQLException { throw new SQLException("Not implemented."); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterStatement.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterStatement.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TesterStatement.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TesterStatement.java 2019-07-31 12:46:24.000000000 +0000 @@ -26,34 +26,35 @@ /** * A dummy {@link Statement}, for testing purposes. */ -public class TesterStatement implements Statement { - protected Connection _connection = null; +public class TesterStatement extends AbandonedTrace implements Statement { + protected Connection _connection; protected boolean _open = true; - protected long _rowsUpdated = 1; - protected boolean _executeResponse = true; protected int _maxFieldSize = 1024; protected long _maxRows = 1024; - protected boolean _escapeProcessing = false; + protected boolean _escapeProcessing; protected int _queryTimeout = 1000; - protected String _cursorName = null; + protected String _cursorName; protected int _fetchDirection = 1; protected int _fetchSize = 1; protected int _resultSetConcurrency = 1; protected int _resultSetType = 1; private int _resultSetHoldability = 1; - protected ResultSet _resultSet = null; + protected ResultSet _resultSet; + protected boolean _sqlExceptionOnClose; public TesterStatement(final Connection conn) { _connection = conn; } + public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency) { _connection = conn; _resultSetType = resultSetType; _resultSetConcurrency = resultSetConcurrency; } + public TesterStatement(final Connection conn, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { _connection = conn; @@ -90,6 +91,10 @@ @Override public void close() throws SQLException { + if (_sqlExceptionOnClose) { + throw new SQLException("TestSQLExceptionOnClose"); + } + // calling close twice has no effect if (!_open) { return; @@ -331,6 +336,10 @@ throw new SQLException("Not implemented."); } + public boolean isSqlExceptionOnClose() { + return _sqlExceptionOnClose; + } + @Override public boolean isWrapperFor(final Class iface) throws SQLException { throw new SQLException("Not implemented."); @@ -389,6 +398,10 @@ _queryTimeout = seconds; } + public void setSqlExceptionOnClose(final boolean _sqlExceptionOnClose) { + this._sqlExceptionOnClose = _sqlExceptionOnClose; + } + @Override public T unwrap(final Class iface) throws SQLException { throw new SQLException("Not implemented."); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestJndi.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestJndi.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestJndi.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestJndi.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,7 +17,7 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Hashtable; @@ -28,9 +28,9 @@ import org.apache.commons.dbcp2.datasources.SharedPoolDataSource; import org.apache.commons.dbcp2.datasources.PerUserPoolDataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests JNID bind and lookup for DataSource implementations. @@ -43,12 +43,12 @@ 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; /** @@ -84,20 +84,20 @@ checkBind(dataSource); } - @Before + @BeforeEach public void setUp() throws Exception { context = getInitialContext(); context.createSubcontext(JNDI_SUBCONTEXT); } - @After + @AfterEach public void tearDown() throws Exception { context.unbind(JNDI_PATH); context.destroySubcontext(JNDI_SUBCONTEXT); } /** - * 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 @@ } /** - * Binds a DataSource into jndi. + * Binds a DataSource into JNDI. * * @throws Exception if creation or binding fails. */ @@ -117,9 +117,9 @@ } /** - * 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(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestLifetimeExceededException.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestLifetimeExceededException.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestLifetimeExceededException.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestLifetimeExceededException.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for LifetimeExceededException. diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestListException.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestListException.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestListException.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestListException.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,14 +17,14 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for ListException. diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestParallelCreationWithNoIdle.java 2019-07-31 12:46:24.000000000 +0000 @@ -1,160 +1,160 @@ -/* - * 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 org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * Test if the pooling if no idle objects are used - */ -public class TestParallelCreationWithNoIdle { - - - protected BasicDataSource ds = null; - private static final String CATALOG = "test catalog"; - - @BeforeClass - public static void setUpClass() { - // register a custom logger which supports inspection of the log messages - LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.dbcp2.StackMessageLog"); - } - - @Before - public void setUp() throws Exception { - ds = new BasicDataSource(); - ds.setDriverClassName("org.apache.commons.dbcp2.TesterConnectionDelayDriver"); - ds.setUrl("jdbc:apache:commons:testerConnectionDelayDriver:50"); - ds.setMaxTotal(10); - - // this one is actually very important. - // see DBCP-513 - ds.setMaxIdle(0); - - // wait a minute. Usually the test runs in ~ 1 second - // but often it's getting stuck ^^ - // you have one second to get a thread dump ;) - ds.setMaxWaitMillis(60000); - - ds.setDefaultAutoCommit(Boolean.TRUE); - ds.setDefaultReadOnly(Boolean.FALSE); - ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); - ds.setDefaultCatalog(CATALOG); - ds.setUsername("userName"); - ds.setPassword("password"); - ds.setValidationQuery("SELECT DUMMY FROM DUAL"); - ds.setConnectionInitSqls(Arrays.asList(new String[] { "SELECT 1", "SELECT 2"})); - ds.setDriverClassLoader(new TesterClassLoader()); - ds.setJmxName("org.apache.commons.dbcp2:name=test"); - } - - /** - * Fire up 100 Threads but only have 10 maxActive and forcedBlock. - * See - * @throws Exception - */ - @Test - public void testMassiveConcurrentInitBorrow() throws Exception { - final int numThreads = 200; - ds.setDriverClassName("org.apache.commons.dbcp2.TesterConnectionDelayDriver"); - ds.setUrl("jdbc:apache:commons:testerConnectionDelayDriver:20"); - ds.setInitialSize(8); - final List errors = Collections.synchronizedList(new ArrayList<>()); - - final Thread[] threads = new Thread[numThreads]; - for (int i = 0; i < numThreads; i++) { - threads[i] = new TestThread(2, 0, 50); - threads[i].setUncaughtExceptionHandler((t, e) -> errors.add(e)); - } - - for (int i = 0; i < numThreads; i++) { - threads[i].start(); - - if (i%4 == 0) { - Thread.sleep(20); - } - } - - for (int i = 0; i < numThreads; i++) { - threads[i].join(); - } - - assertEquals(0, errors.size()); - ds.close(); - } - - - - class TestThread extends Thread { - java.util.Random _random = new java.util.Random(); - final int iter; - final int delay; - final int delayAfter; - - - public TestThread(final int iter, final int delay, final int delayAfter) { - this.iter = iter; - this.delay = delay; - this.delayAfter = delayAfter; - } - - - @Override - public void run() { - // System.out.println("Thread started " + Thread.currentThread().toString()); - for (int i = 0; i < iter; i++) { - sleepMax(delay); - try (Connection conn = ds.getConnection(); - PreparedStatement stmt = conn.prepareStatement("select 'literal', SYSDATE from dual");) { - // System.out.println("Got Connection " + Thread.currentThread().toString()); - final ResultSet rset = stmt.executeQuery(); - rset.next(); - sleepMax(delayAfter); - rset.close(); - } catch (final Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - // System.out.println("Thread done " + Thread.currentThread().toString()); - } - - private void sleepMax(final int timeMax) { - if (timeMax == 0) { - return; - } - try { - Thread.sleep(_random.nextInt(timeMax)); - } catch(final Exception e) { - // ignored - } - } - } - -} +/* + * 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 org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Test if the pooling if no idle objects are used + */ +public class TestParallelCreationWithNoIdle { + + + protected BasicDataSource ds = null; + private static final String CATALOG = "test catalog"; + + @BeforeAll + public static void setUpClass() { + // register a custom logger which supports inspection of the log messages + LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.dbcp2.StackMessageLog"); + } + + @BeforeEach + public void setUp() throws Exception { + ds = new BasicDataSource(); + ds.setDriverClassName("org.apache.commons.dbcp2.TesterConnectionDelayDriver"); + ds.setUrl("jdbc:apache:commons:testerConnectionDelayDriver:50"); + ds.setMaxTotal(10); + + // this one is actually very important. + // see DBCP-513 + ds.setMaxIdle(0); + + // wait a minute. Usually the test runs in ~ 1 second + // but often it's getting stuck ^^ + // you have one second to get a thread dump ;) + ds.setMaxWaitMillis(60000); + + ds.setDefaultAutoCommit(Boolean.TRUE); + ds.setDefaultReadOnly(Boolean.FALSE); + ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); + ds.setDefaultCatalog(CATALOG); + ds.setUsername("userName"); + ds.setPassword("password"); + ds.setValidationQuery("SELECT DUMMY FROM DUAL"); + ds.setConnectionInitSqls(Arrays.asList(new String[] { "SELECT 1", "SELECT 2"})); + ds.setDriverClassLoader(new TesterClassLoader()); + ds.setJmxName("org.apache.commons.dbcp2:name=test"); + } + + /** + * Fire up 100 Threads but only have 10 maxActive and forcedBlock. + * See + * @throws Exception + */ + @Test + public void testMassiveConcurrentInitBorrow() throws Exception { + final int numThreads = 200; + ds.setDriverClassName("org.apache.commons.dbcp2.TesterConnectionDelayDriver"); + ds.setUrl("jdbc:apache:commons:testerConnectionDelayDriver:20"); + ds.setInitialSize(8); + final List errors = Collections.synchronizedList(new ArrayList<>()); + + final Thread[] threads = new Thread[numThreads]; + for (int i = 0; i < numThreads; i++) { + threads[i] = new TestThread(2, 0, 50); + threads[i].setUncaughtExceptionHandler((t, e) -> errors.add(e)); + } + + for (int i = 0; i < numThreads; i++) { + threads[i].start(); + + if (i%4 == 0) { + Thread.sleep(20); + } + } + + for (int i = 0; i < numThreads; i++) { + threads[i].join(); + } + + assertEquals(0, errors.size()); + ds.close(); + } + + + + class TestThread extends Thread { + java.util.Random _random = new java.util.Random(); + final int iter; + final int delay; + final int delayAfter; + + + public TestThread(final int iter, final int delay, final int delayAfter) { + this.iter = iter; + this.delay = delay; + this.delayAfter = delayAfter; + } + + + @Override + public void run() { + // System.out.println("Thread started " + Thread.currentThread().toString()); + for (int i = 0; i < iter; i++) { + sleepMax(delay); + try (Connection conn = ds.getConnection(); + PreparedStatement stmt = conn.prepareStatement("select 'literal', SYSDATE from dual");) { + // System.out.println("Got Connection " + Thread.currentThread().toString()); + final ResultSet rset = stmt.executeQuery(); + rset.next(); + sleepMax(delayAfter); + rset.close(); + } catch (final Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + // System.out.println("Thread done " + Thread.currentThread().toString()); + } + + private void sleepMax(final int timeMax) { + if (timeMax == 0) { + return; + } + try { + Thread.sleep(_random.nextInt(timeMax)); + } catch(final Exception e) { + // ignored + } + } + } + +} diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -16,19 +16,19 @@ */ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import org.apache.commons.pool2.impl.GenericObjectPool; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** */ @@ -36,7 +36,7 @@ private GenericObjectPool pool = null; - @Before + @BeforeEach public void setUp() throws Exception { final PoolableConnectionFactory factory = new PoolableConnectionFactory( new DriverConnectionFactory( @@ -50,7 +50,7 @@ factory.setPool(pool); } - @After + @AfterEach public void tearDown() { pool.close(); } @@ -60,13 +60,13 @@ // Grab a new connection from the pool final Connection c = pool.borrowObject(); - assertNotNull("Connection should be created and should not be null", c); - assertEquals("There should be exactly one active object in the pool", 1, pool.getNumActive()); + assertNotNull(c, "Connection should be created and should not be null"); + assertEquals(1, pool.getNumActive(), "There should be exactly one active object in the pool"); // Now return the connection by closing it c.close(); // Can't be null - assertEquals("There should now be zero active objects in the pool", 0, pool.getNumActive()); + assertEquals(0, pool.getNumActive(), "There should now be zero active objects in the pool"); } // Bugzilla Bug 33591: PoolableConnection leaks connections if the @@ -92,27 +92,26 @@ // should *NOT* be returned to the pool } - assertEquals("The pool should have no active connections", - 0, pool.getNumActive()); + assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); } @Test public void testClosingWrappedInDelegate() throws Exception { - Assert.assertEquals(0, pool.getNumActive()); + Assertions.assertEquals(0, pool.getNumActive()); final Connection conn = pool.borrowObject(); final DelegatingConnection outer = new DelegatingConnection<>(conn); - Assert.assertFalse(outer.isClosed()); - Assert.assertFalse(conn.isClosed()); - Assert.assertEquals(1, pool.getNumActive()); + Assertions.assertFalse(outer.isClosed()); + Assertions.assertFalse(conn.isClosed()); + Assertions.assertEquals(1, pool.getNumActive()); outer.close(); - Assert.assertTrue(outer.isClosed()); - Assert.assertTrue(conn.isClosed()); - Assert.assertEquals(0, pool.getNumActive()); - Assert.assertEquals(1, pool.getNumIdle()); + Assertions.assertTrue(outer.isClosed()); + Assertions.assertTrue(conn.isClosed()); + Assertions.assertEquals(0, pool.getNumActive()); + Assertions.assertEquals(1, pool.getNumIdle()); } @Test @@ -157,10 +156,8 @@ // verify that bad connection does not get returned to the pool conn.close(); // testOnReturn triggers validate, which should fail - assertEquals("The pool should have no active connections", - 0, pool.getNumActive()); - assertEquals("The pool should have no idle connections", - 0, pool.getNumIdle()); + assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); + assertEquals(0, pool.getNumIdle(), "The pool should have no idle connections"); } @Test @@ -187,9 +184,7 @@ // verify that bad connection does not get returned to the pool conn.close(); // testOnReturn triggers validate, which should fail - assertEquals("The pool should have no active connections", - 0, pool.getNumActive()); - assertEquals("The pool should have no idle connections", - 0, pool.getNumIdle()); + assertEquals(0, pool.getNumActive(), "The pool should have no active connections"); + assertEquals(0, pool.getNumIdle(), "The pool should have no idle connections"); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingConnection.java 2019-07-31 12:46:24.000000000 +0000 @@ -16,21 +16,21 @@ */ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class TestPoolingConnection { private PoolingConnection con = null; - @Before + @BeforeEach public void setUp() throws Exception { con = new PoolingConnection(new TesterConnection("test", "test")); final GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig<>(); @@ -44,7 +44,7 @@ con.setStatementPool(stmtPool); } - @After + @AfterEach public void tearDown() throws Exception { con.close(); con = null; diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,19 +17,19 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.util.Properties; import org.apache.commons.pool2.impl.GenericObjectPool; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for PoolingDataSource @@ -44,7 +44,7 @@ protected PoolingDataSource ds = null; private GenericObjectPool pool = null; - @Before + @BeforeEach public void setUp() throws Exception { final Properties props = new Properties(); props.setProperty("user", "userName"); @@ -66,7 +66,7 @@ } @Override - @After + @AfterEach public void tearDown() throws Exception { ds.close(); super.tearDown(); @@ -85,8 +85,8 @@ // Grab a new connection - should get c[0]'s closed connection // so should be delegate-equivalent final Connection con = newConnection(); - Assert.assertNotEquals(c[0], con); - Assert.assertEquals( + Assertions.assertNotEquals(c[0], con); + Assertions.assertEquals( ((DelegatingConnection) c[0]).getInnermostDelegateInternal(), ((DelegatingConnection) con).getInnermostDelegateInternal()); for (final Connection element : c) { diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,11 +17,11 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; @@ -36,10 +36,10 @@ import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for a {@link GenericObjectPool} based {@link PoolingDriver}. @@ -53,7 +53,7 @@ private PoolingDriver driver = null; - @Before + @BeforeEach public void setUp() throws Exception { final DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null); @@ -84,7 +84,7 @@ } @Override - @After + @AfterEach public void tearDown() throws Exception { driver.closePool("test"); super.tearDown(); @@ -101,7 +101,7 @@ new GenericObjectPool<>(pcf); pcf.setPool(connectionPool); final DataSource ds = new PoolingDataSource<>(connectionPool); - Assert.assertNotNull(ds); + Assertions.assertNotNull(ds); } @Test @@ -116,7 +116,7 @@ driver2.registerPool("example",connectionPool); } - /** "http://issues.apache.org/bugzilla/show_bug.cgi?id=28912" */ + /** "https://issues.apache.org/bugzilla/show_bug.cgi?id=28912" */ @Test public void testReportedBug28912() throws Exception { final Connection conn1 = getConnection(); @@ -137,7 +137,7 @@ assertFalse(conn2.isClosed()); } - /** "http://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */ + /** "https://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */ @Test public void testReportedBug12400() throws Exception { final GenericObjectPoolConfig config = new GenericObjectPoolConfig<>(); diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java 2019-07-31 12:46:24.000000000 +0000 @@ -16,17 +16,17 @@ */ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Statement; import java.util.Arrays; import org.apache.commons.dbcp2.PoolingConnection.StatementType; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Tests {@link PStmtKey}. @@ -40,35 +40,35 @@ */ @Test public void testCtorDifferentSchema() { - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema2")); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema2")); + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog1", "schema2", 0)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog1", "schema2", 0, 0)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0, null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), new PStmtKey("sql", "catalog1", "schema2", 0, 0, null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog1", "schema2", (int[]) null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog1", "schema2", new int[1])); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog1", "schema2", (String[]) null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog1", "schema2", new String[] {"A" })); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema2", StatementType.PREPARED_STATEMENT)); - Assert.assertNotEquals( + Assertions.assertNotEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog1", "schema2", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -78,35 +78,35 @@ */ @Test public void testCtorDifferentCatalog() { - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog2", "schema1")); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog2", "schema1")); + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog2", "schema1", 0)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog2", "schema1", 0, 0)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0, null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), new PStmtKey("sql", "catalog2", "schema1", 0, 0, null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog2", "schema1", (int[]) null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog2", "schema1", new int[1])); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog2", "schema1", (String[]) null)); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog2", "schema1", new String[] {"A" })); - Assert.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + Assertions.assertNotEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog2", "schema1", StatementType.PREPARED_STATEMENT)); - Assert.assertNotEquals( + Assertions.assertNotEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog2", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -116,35 +116,35 @@ */ @Test public void testCtorEquals() { - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema1")); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1"), new PStmtKey("sql", "catalog1", "schema1")); + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0), new PStmtKey("sql", "catalog1", "schema1", 0)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0), new PStmtKey("sql", "catalog1", "schema1", 0, 0)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0)); // - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, null)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, null), new PStmtKey("sql", "catalog1", "schema1", 0, 0, null)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", 0, 0, StatementType.PREPARED_STATEMENT)); // - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (int[]) null), new PStmtKey("sql", "catalog1", "schema1", (int[]) null)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new int[1]), new PStmtKey("sql", "catalog1", "schema1", new int[1])); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", (String[]) null), new PStmtKey("sql", "catalog1", "schema1", (String[]) null)); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" }), new PStmtKey("sql", "catalog1", "schema1", new String[] {"A" })); - Assert.assertEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), + Assertions.assertEquals(new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT), new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT)); - Assert.assertEquals( + Assertions.assertEquals( new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE), new PStmtKey("sql", "catalog1", "schema1", StatementType.PREPARED_STATEMENT, Integer.MAX_VALUE)); } @@ -158,10 +158,10 @@ public void testCtorStringStringArrayOfInts() { final int[] input = {0, 0 }; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assert.assertArrayEquals(input, pStmtKey.getColumnIndexes()); + Assertions.assertArrayEquals(input, pStmtKey.getColumnIndexes()); input[0] = 1; input[1] = 1; - Assert.assertFalse(Arrays.equals(input, pStmtKey.getColumnIndexes())); + Assertions.assertFalse(Arrays.equals(input, pStmtKey.getColumnIndexes())); } /** @@ -173,7 +173,7 @@ public void testCtorStringStringArrayOfNullInts() { final int[] input = null; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assert.assertArrayEquals(input, pStmtKey.getColumnIndexes()); + Assertions.assertArrayEquals(input, pStmtKey.getColumnIndexes()); } /** @@ -185,7 +185,7 @@ public void testCtorStringStringArrayOfNullStrings() { final String[] input = null; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assert.assertArrayEquals(input, pStmtKey.getColumnNames()); + Assertions.assertArrayEquals(input, pStmtKey.getColumnNames()); } /** @@ -197,10 +197,10 @@ public void testCtorStringStringArrayOfStrings() { final String[] input = {"A", "B" }; final PStmtKey pStmtKey = new PStmtKey("", "", "", input); - Assert.assertArrayEquals(input, pStmtKey.getColumnNames()); + Assertions.assertArrayEquals(input, pStmtKey.getColumnNames()); input[0] = "C"; input[1] = "D"; - Assert.assertFalse(Arrays.equals(input, pStmtKey.getColumnNames())); + Assertions.assertFalse(Arrays.equals(input, pStmtKey.getColumnNames())); } @Test diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPoolingBasicDataSource.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPoolingBasicDataSource.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPoolingBasicDataSource.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPoolingBasicDataSource.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,20 +17,20 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicDataSource with prepared statement pooling enabled @@ -38,7 +38,7 @@ public class TestPStmtPoolingBasicDataSource extends TestBasicDataSource { @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); // PoolPreparedStatements enabled, should not affect the basic tests @@ -77,8 +77,9 @@ // normal reuse of statement stmt1.close(); - final PreparedStatement stmt4 = conn.prepareStatement("select 'a' from dual"); - assertNotNull(stmt4); + try (final PreparedStatement stmt4 = conn.prepareStatement("select 'a' from dual")) { + assertNotNull(stmt4); + } } /** diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPooling.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPooling.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPooling.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestPStmtPooling.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,10 +17,10 @@ package org.apache.commons.dbcp2; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.DriverManager; @@ -34,8 +34,8 @@ import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * TestSuite for BasicDataSource with prepared statement pooling enabled @@ -44,7 +44,7 @@ @Test public void testStmtPool() throws Exception { - final DataSource ds = createPDS(); + final DataSource ds = createPoolingDataSource(); try (Connection conn = ds.getConnection()) { final Statement stmt1 = conn.prepareStatement("select 1 from dual"); final Statement ustmt1 = ((DelegatingStatement) stmt1).getInnermostDelegate(); @@ -63,7 +63,7 @@ */ @Test public void testMultipleClose() throws Exception { - final DataSource ds = createPDS(); + final DataSource ds = createPoolingDataSource(); PreparedStatement stmt1 = null; final Connection conn = ds.getConnection(); stmt1 = conn.prepareStatement("select 1 from dual"); @@ -75,7 +75,7 @@ final Connection conn2 = ds.getConnection(); final PreparedStatement stmt2 = conn2.prepareStatement("select 1 from dual"); // Confirm stmt2 now wraps the same PPS wrapped by stmt1 - Assert.assertSame(pps1, getPoolablePreparedStatement(stmt2)); + Assertions.assertSame(pps1, getPoolablePreparedStatement(stmt2)); stmt1.close(); // close should not cascade to PPS that stmt1 used to wrap assertTrue(!stmt2.isClosed()); stmt2.executeQuery(); // wrapped PPS needs to work here - pre DBCP-414 fix this throws @@ -101,7 +101,7 @@ } - private DataSource createPDS() throws Exception { + private DataSource createPoolingDataSource() throws Exception { DriverManager.registerDriver(new TesterDriver()); final ConnectionFactory connFactory = new DriverManagerConnectionFactory( "jdbc:apache:commons:testdriver","u1","p1"); @@ -220,7 +220,7 @@ ps.addBatch(); ps.close(); conn.close(); - Assert.assertFalse(inner.isClosed()); + Assertions.assertFalse(inner.isClosed()); ds.close(); } } diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestSQLExceptionList.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestSQLExceptionList.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestSQLExceptionList.java 1970-01-01 00:00:00.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestSQLExceptionList.java 2019-07-31 12:46:24.000000000 +0000 @@ -0,0 +1,38 @@ +/* + * 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.SQLTransientException; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class TestSQLExceptionList { + + @Test + public void testCause() { + final SQLTransientException cause = new SQLTransientException(); + final List list = Collections.singletonList(cause); + final SQLExceptionList sqlExceptionList = new SQLExceptionList(list); + Assertions.assertEquals(cause, sqlExceptionList.getCause()); + Assertions.assertEquals(list, sqlExceptionList.getCauseList()); + sqlExceptionList.printStackTrace(); + } +} diff -Nru commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestUtils.java commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestUtils.java --- commons-dbcp2-2.6.0/src/test/java/org/apache/commons/dbcp2/TestUtils.java 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/src/test/java/org/apache/commons/dbcp2/TestUtils.java 2019-07-31 12:46:24.000000000 +0000 @@ -17,14 +17,12 @@ package org.apache.commons.dbcp2; -import java.sql.Connection; - -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestUtils { @Test public void testClassLoads() { - Utils.closeQuietly((Connection) null); + Utils.closeQuietly((AutoCloseable) null); } } diff -Nru commons-dbcp2-2.6.0/.travis.yml commons-dbcp2-2.7.0/.travis.yml --- commons-dbcp2-2.6.0/.travis.yml 2019-02-15 15:02:23.000000000 +0000 +++ commons-dbcp2-2.7.0/.travis.yml 2019-07-31 12:46:24.000000000 +0000 @@ -17,6 +17,10 @@ sudo: false jdk: + - oraclejdk11 - openjdk8 - - oraclejdk8 + - openjdk11 + - openjdk12 + - openjdk-ea + \ No newline at end of file