mirror of https://github.com/apache/openjpa.git
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:
parent
fce1fe0972
commit
c7a08227a3
|
@ -69,22 +69,11 @@
|
|||
<classifier>tests</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
<version>${derby.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta-regexp</groupId>
|
||||
<artifactId>jakarta-regexp</artifactId>
|
||||
|
|
|
@ -78,11 +78,6 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
|
|
|
@ -62,7 +62,11 @@
|
|||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
|||
import org.apache.openjpa.lib.conf.Configurable;
|
||||
import org.apache.openjpa.lib.conf.Configuration;
|
||||
import org.apache.openjpa.lib.conf.Configurations;
|
||||
import org.apache.openjpa.lib.util.Closeable;
|
||||
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.
|
||||
*/
|
||||
public abstract class DBCPDriverDataSource
|
||||
extends SimpleDriverDataSource implements Configurable {
|
||||
extends SimpleDriverDataSource implements Configurable, Closeable {
|
||||
|
||||
private static String DBCPPACKAGENAME = "org.apache.commons.dbcp";
|
||||
private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp.BasicDataSource";
|
||||
|
@ -67,6 +68,20 @@ extends SimpleDriverDataSource implements Configurable {
|
|||
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 {
|
||||
Connection con = getDBCPDataSource(props).getConnection();
|
||||
if (con == null) {
|
||||
|
|
|
@ -134,7 +134,6 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<postgresql.version>8.4-701.jdbc3</postgresql.version>
|
||||
<connection.driver.name>org.postgresql.Driver</connection.driver.name>
|
||||
<!--<connection.url>jdbc:postgresql://localhost/openjpa</connection.url>-->
|
||||
<connection.url>${openjpa.postgresql.url}</connection.url>
|
||||
|
@ -740,11 +739,6 @@
|
|||
<artifactId>openjpa-persistence</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
|
|
|
@ -68,6 +68,21 @@ public abstract class ContainerTest extends SingleEMFTestCase {
|
|||
|
||||
@Override
|
||||
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() {
|
||||
|
|
|
@ -143,7 +143,6 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<postgresql.version>8.3-603.jdbc3</postgresql.version>
|
||||
<connection.driver.name>org.postgresql.Driver</connection.driver.name>
|
||||
<connection.url>${openjpa.postgresql.url}</connection.url>
|
||||
<connection.username>${openjpa.postgresql.username}</connection.username>
|
||||
|
@ -675,16 +674,6 @@
|
|||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
<groupId>jakarta-regexp</groupId>
|
||||
<artifactId>jakarta-regexp</artifactId>
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -75,6 +75,7 @@
|
|||
<derby.version>10.5.3.0_1</derby.version>
|
||||
<hsqldb.version>1.8.0.10</hsqldb.version>
|
||||
<mysql.version>5.1.12</mysql.version>
|
||||
<postgresql.version>8.4-701.jdbc3</postgresql.version>
|
||||
<!-- other common versions -->
|
||||
<slf4jVersion>1.6.1</slf4jVersion>
|
||||
</properties>
|
||||
|
@ -595,6 +596,12 @@
|
|||
<artifactId>hsqldb</artifactId>
|
||||
<version>${hsqldb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta-regexp</groupId>
|
||||
<artifactId>jakarta-regexp</artifactId>
|
||||
|
@ -639,16 +646,16 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.findbugs</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
Loading…
Reference in New Issue