提交 f3ae7bd9 编写于 作者: K Keith Donald

applied Joris's patch to shutdown Embedded Derby DB; adjusted manifest...

applied Joris's patch to shutdown Embedded Derby DB; adjusted manifest template to restrict derby version range from 10.5.1. to 10.6
上级 0c85f3df
......@@ -15,14 +15,16 @@
*/
package org.springframework.jdbc.datasource.embedded;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.derby.impl.io.VFMemoryStorageFactory;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.ClassUtils;
......@@ -47,9 +49,9 @@ public class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigur
}
/**
* Get the singleton {@link HsqlEmbeddedDatabaseConfigurer} instance.
* Get the singleton {@link DerbyEmbeddedDatabaseConfigurer} instance.
* @return the configurer
* @throws ClassNotFoundException if HSQL is not on the classpath
* @throws ClassNotFoundException if Derby is not on the classpath
*/
public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
if (INSTANCE == null) {
......@@ -75,22 +77,29 @@ public class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigur
shutdownDataSource.setUrl(String.format(URL_TEMPLATE, databaseName, "shutdown=true"));
connection = shutdownDataSource.getConnection();
} catch (SQLException e) {
if (e instanceof SQLNonTransientConnectionException) {
SQLNonTransientConnectionException ex = (SQLNonTransientConnectionException) e;
if (!SHUTDOWN_CODE.equals(ex.getSQLState())) {
logException(e);
}
if (SHUTDOWN_CODE.equals(e.getSQLState())) {
purgeDatabase(databaseName);
} else {
logException(e);
logger.warn("Could not shutdown in-memory Derby database", e);
}
} finally {
JdbcUtils.closeConnection(connection);
}
}
private void logException(SQLException e) {
if (logger.isWarnEnabled()) {
logger.warn("Could not shutdown in-memory Derby database", e);
/**
* Purges the in-memory database, to prevent it from hanging around after
* being shut down
* @param databaseName
*/
private void purgeDatabase(String databaseName) {
// TODO: update this code once Derby adds a proper way to remove an in-memory db
// (see http://wiki.apache.org/db-derby/InMemoryBackEndPrimer for details)
try {
VFMemoryStorageFactory.purgeDatabase(new File(databaseName).getCanonicalPath());
} catch (IOException ioe) {
logger.warn("Could not purge in-memory Derby database", ioe);
}
}
}
......@@ -32,9 +32,7 @@ public class EmbeddedDatabaseBuilderTests {
}
@Test
@Ignore
public void testBuildDerby() {
// TODO this fails when the whole suite runs b/c tables are not cleaned up
EmbeddedDatabaseBuilder builder = EmbeddedDatabaseBuilder.relativeTo(getClass());
EmbeddedDatabase db = builder.type(DERBY).script("db-schema-derby.sql").script("db-test-data.sql").build();
assertDatabaseCreatedAndShutdown(db);
......
......@@ -17,7 +17,7 @@ Import-Template:
javax.xml.*;version="0";resolution:=optional,
org.h2.*;version="[1.8.0, 2.0.0)";resolution:=optional,
org.hsqldb.*;version="[1.0.0, 2.0.0)";resolution:=optional,
org.apache.derby.*;version="[10.5.1, 11.0.0)";resolution:=optional,
org.apache.derby.*;version="[10.5.1, 10.6.0)";resolution:=optional,
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)",
org.springframework.beans.*;version="[3.0.0, 3.0.1)",
org.springframework.core.*;version="[3.0.0, 3.0.1)",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册