Skip to content

Commit

Permalink
H2 DevServices should not attempt to stop a stopped server
Browse files Browse the repository at this point in the history
(cherry picked from commit 17eb2fb)
  • Loading branch information
Sanne authored and gsmet committed Jun 22, 2021
1 parent 4e23423 commit 78a9136
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,28 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
new Closeable() {
@Override
public void close() throws IOException {
//make sure the DB is removed on close
try (Connection connection = DriverManager.getConnection(connectionUrl, "sa", "sa")) {
try (Statement statement = connection.createStatement()) {
statement.execute("SET DB_CLOSE_DELAY 0");
//Test first, to not make too much noise if the Server is dead already
//(perhaps we failed to start?)
if (tcpServer.isRunning(false)) {
//make sure the DB is removed on close
try (Connection connection = DriverManager.getConnection(
connectionUrl,
"sa",
"sa")) {
try (Statement statement = connection.createStatement()) {
statement.execute("SET DB_CLOSE_DELAY 0");
}
} catch (SQLException t) {
t.printStackTrace();
}
} catch (SQLException t) {
t.printStackTrace();
tcpServer.stop();
System.out.println(
"[INFO] H2 database was shut down; server status: " + tcpServer.getStatus());
} else {
System.out.println(
"[INFO] H2 database was NOT shut down as it appears it was down already; server status: "
+ tcpServer.getStatus());
}
tcpServer.stop();
System.out.println(
"[INFO] H2 database was shut down; server status: " + tcpServer.getStatus());
}
});
} catch (SQLException throwables) {
Expand Down

0 comments on commit 78a9136

Please sign in to comment.