SPR-7602 - Correctly shutdown Derby >= 10.6
The shutdown mechanism for in-memory databases has changed since 10.6. We now have to trigger 'drop' instead of 'shutdown'. Besides that we can skip purging the database manually in newer versions. git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3700 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
bb004e3ce7
commit
bff49b4c0d
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
@ -42,6 +43,8 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
|
||||||
|
|
||||||
// Error code that indicates successful shutdown
|
// Error code that indicates successful shutdown
|
||||||
private static final String SHUTDOWN_CODE = "08006";
|
private static final String SHUTDOWN_CODE = "08006";
|
||||||
|
private static final boolean IS_AT_LEAST_DOT_SIX = new EmbeddedDriver().getMinorVersion() >= 6;
|
||||||
|
private static final String SHUTDOWN_COMMAND = String.format("%s=true", IS_AT_LEAST_DOT_SIX ? "drop" : "shutdown");
|
||||||
|
|
||||||
private static DerbyEmbeddedDatabaseConfigurer INSTANCE;
|
private static DerbyEmbeddedDatabaseConfigurer INSTANCE;
|
||||||
|
|
||||||
|
|
@ -72,15 +75,16 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
|
||||||
|
|
||||||
public void shutdown(DataSource dataSource, String databaseName) {
|
public void shutdown(DataSource dataSource, String databaseName) {
|
||||||
try {
|
try {
|
||||||
new EmbeddedDriver().connect(
|
new EmbeddedDriver().connect(String.format(URL_TEMPLATE, databaseName, SHUTDOWN_COMMAND), new Properties());
|
||||||
String.format(URL_TEMPLATE, databaseName, "shutdown=true"), new Properties());
|
} catch (SQLException ex) {
|
||||||
}
|
|
||||||
catch (SQLException ex) {
|
if (!SHUTDOWN_CODE.equals(ex.getSQLState())) {
|
||||||
if (SHUTDOWN_CODE.equals(ex.getSQLState())) {
|
|
||||||
purgeDatabase(databaseName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
logger.warn("Could not shutdown in-memory Derby database", ex);
|
logger.warn("Could not shutdown in-memory Derby database", ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IS_AT_LEAST_DOT_SIX) {
|
||||||
|
purgeDatabase(databaseName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,5 +103,4 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
|
||||||
logger.warn("Could not purge in-memory Derby database", ex);
|
logger.warn("Could not purge in-memory Derby database", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue