OPENJPA-1764 Need to explicitly close dbcp.BasicDataSource instances, moved commons-dbcp test depend to parent pom and added closing of EMF in ContainerTest during test tearDown.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1002860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-09-29 21:43:11 +00:00
parent fce1fe0972
commit c7a08227a3
8 changed files with 48 additions and 40 deletions

View File

@ -69,22 +69,11 @@
<classifier>tests</classifier> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-logging</groupId> <groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId> <artifactId>commons-logging</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>jakarta-regexp</groupId> <groupId>jakarta-regexp</groupId>
<artifactId>jakarta-regexp</artifactId> <artifactId>jakarta-regexp</artifactId>

View File

@ -78,11 +78,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>validation-api</artifactId>

View File

@ -62,7 +62,11 @@
<dependency> <dependency>
<groupId>postgresql</groupId> <groupId>postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>8.4-701.jdbc3</version> <scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -29,6 +29,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.lib.conf.Configurable; import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration; import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.lib.util.Closeable;
import org.apache.openjpa.lib.util.ConcreteClassGenerator; import org.apache.openjpa.lib.util.ConcreteClassGenerator;
/** /**
@ -38,7 +39,7 @@ import org.apache.openjpa.lib.util.ConcreteClassGenerator;
* usage of Commons DBCP when available, use AutoDriverDataSource instead. * usage of Commons DBCP when available, use AutoDriverDataSource instead.
*/ */
public abstract class DBCPDriverDataSource public abstract class DBCPDriverDataSource
extends SimpleDriverDataSource implements Configurable { extends SimpleDriverDataSource implements Configurable, Closeable {
private static String DBCPPACKAGENAME = "org.apache.commons.dbcp"; private static String DBCPPACKAGENAME = "org.apache.commons.dbcp";
private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp.BasicDataSource"; private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp.BasicDataSource";
@ -67,6 +68,20 @@ extends SimpleDriverDataSource implements Configurable {
return getDBCPConnection(props); return getDBCPConnection(props);
} }
public void close() throws SQLException {
try {
if (_ds != null) {
if (isDBCPLoaded()) {
((org.apache.commons.dbcp.BasicDataSource)_dbcpClass.cast(_ds)).close();
}
}
} catch (ClassCastException cce) {
// no-op
} finally {
_ds = null;
}
}
protected Connection getDBCPConnection(Properties props) throws SQLException { protected Connection getDBCPConnection(Properties props) throws SQLException {
Connection con = getDBCPDataSource(props).getConnection(); Connection con = getDBCPDataSource(props).getConnection();
if (con == null) { if (con == null) {

View File

@ -134,7 +134,6 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<postgresql.version>8.4-701.jdbc3</postgresql.version>
<connection.driver.name>org.postgresql.Driver</connection.driver.name> <connection.driver.name>org.postgresql.Driver</connection.driver.name>
<!--<connection.url>jdbc:postgresql://localhost/openjpa</connection.url>--> <!--<connection.url>jdbc:postgresql://localhost/openjpa</connection.url>-->
<connection.url>${openjpa.postgresql.url}</connection.url> <connection.url>${openjpa.postgresql.url}</connection.url>
@ -740,11 +739,6 @@
<artifactId>openjpa-persistence</artifactId> <artifactId>openjpa-persistence</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections</artifactId>

View File

@ -68,6 +68,21 @@ public abstract class ContainerTest extends SingleEMFTestCase {
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
try {
if (emf != null && emf.isOpen()) {
// can't use AbstractPersistenceTestCase.closeEMF() due to using managed transactions
// closeAllOpenEMs(emf);
emf.close();
}
} catch (Exception e) {
// if a test failed, swallow any exceptions that happen
// during tear-down, as these just mask the original problem.
if (testResult.wasSuccessful()) {
throw e;
}
} finally {
emf = null;
}
} }
protected void commit() { protected void commit() {

View File

@ -143,7 +143,6 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<postgresql.version>8.3-603.jdbc3</postgresql.version>
<connection.driver.name>org.postgresql.Driver</connection.driver.name> <connection.driver.name>org.postgresql.Driver</connection.driver.name>
<connection.url>${openjpa.postgresql.url}</connection.url> <connection.url>${openjpa.postgresql.url}</connection.url>
<connection.username>${openjpa.postgresql.username}</connection.username> <connection.username>${openjpa.postgresql.username}</connection.username>
@ -675,16 +674,6 @@
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>jakarta-regexp</groupId> <groupId>jakarta-regexp</groupId>
<artifactId>jakarta-regexp</artifactId> <artifactId>jakarta-regexp</artifactId>

17
pom.xml
View File

@ -75,6 +75,7 @@
<derby.version>10.5.3.0_1</derby.version> <derby.version>10.5.3.0_1</derby.version>
<hsqldb.version>1.8.0.10</hsqldb.version> <hsqldb.version>1.8.0.10</hsqldb.version>
<mysql.version>5.1.12</mysql.version> <mysql.version>5.1.12</mysql.version>
<postgresql.version>8.4-701.jdbc3</postgresql.version>
<!-- other common versions --> <!-- other common versions -->
<slf4jVersion>1.6.1</slf4jVersion> <slf4jVersion>1.6.1</slf4jVersion>
</properties> </properties>
@ -595,6 +596,12 @@
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version> <version>${hsqldb.version}</version>
</dependency> </dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>jakarta-regexp</groupId> <groupId>jakarta-regexp</groupId>
<artifactId>jakarta-regexp</artifactId> <artifactId>jakarta-regexp</artifactId>
@ -639,16 +646,16 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>