X Tutup
Skip to content

Commit b467f2c

Browse files
committed
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.
1 parent e211c09 commit b467f2c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.sql.SQLException;
2222
import java.util.Properties;
23+
2324
import javax.sql.DataSource;
2425

2526
import org.apache.commons.logging.Log;
@@ -42,6 +43,8 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
4243

4344
// Error code that indicates successful shutdown
4445
private static final String SHUTDOWN_CODE = "08006";
46+
private static final boolean IS_AT_LEAST_DOT_SIX = new EmbeddedDriver().getMinorVersion() >= 6;
47+
private static final String SHUTDOWN_COMMAND = String.format("%s=true", IS_AT_LEAST_DOT_SIX ? "drop" : "shutdown");
4548

4649
private static DerbyEmbeddedDatabaseConfigurer INSTANCE;
4750

@@ -72,15 +75,16 @@ public void configureConnectionProperties(ConnectionProperties properties, Strin
7275

7376
public void shutdown(DataSource dataSource, String databaseName) {
7477
try {
75-
new EmbeddedDriver().connect(
76-
String.format(URL_TEMPLATE, databaseName, "shutdown=true"), new Properties());
77-
}
78-
catch (SQLException ex) {
79-
if (SHUTDOWN_CODE.equals(ex.getSQLState())) {
80-
purgeDatabase(databaseName);
81-
}
82-
else {
78+
new EmbeddedDriver().connect(String.format(URL_TEMPLATE, databaseName, SHUTDOWN_COMMAND), new Properties());
79+
} catch (SQLException ex) {
80+
81+
if (!SHUTDOWN_CODE.equals(ex.getSQLState())) {
8382
logger.warn("Could not shutdown in-memory Derby database", ex);
83+
return;
84+
}
85+
86+
if (!IS_AT_LEAST_DOT_SIX) {
87+
purgeDatabase(databaseName);
8488
}
8589
}
8690
}
@@ -99,5 +103,4 @@ private void purgeDatabase(String databaseName) {
99103
logger.warn("Could not purge in-memory Derby database", ex);
100104
}
101105
}
102-
103106
}

0 commit comments

Comments
 (0)
X Tutup