Do not crash when no DB is present.
This commit is contained in:
parent
1ad275a970
commit
c3e2cc23c1
3 changed files with 19 additions and 2 deletions
|
@ -120,7 +120,12 @@ public class LibZontreck {
|
|||
ALIVE=true;
|
||||
|
||||
ServerConfig.init();
|
||||
DatabaseWrapper.start();
|
||||
try {
|
||||
DatabaseWrapper.start();
|
||||
}catch(RuntimeException e) {
|
||||
LOGGER.warn("Database not configured properly, it will not be available.");
|
||||
DatabaseWrapper.invalidate();
|
||||
}
|
||||
|
||||
CURRENT_SIDE = LogicalSide.SERVER;
|
||||
|
||||
|
@ -132,6 +137,8 @@ public class LibZontreck {
|
|||
BlockRestoreQueueRegistry.init(level);
|
||||
}
|
||||
|
||||
if(!DatabaseWrapper.hasDB)return;
|
||||
|
||||
try {
|
||||
DatabaseMigrations.initMigrations();
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -8,10 +8,15 @@ import java.sql.*;
|
|||
|
||||
public class DatabaseWrapper {
|
||||
private Connection connection;
|
||||
public static boolean hasDB = true;
|
||||
|
||||
private static DatabaseWrapper instance;
|
||||
|
||||
public static DatabaseWrapper get() {
|
||||
if(!hasDB) {
|
||||
throw new RuntimeException("Error: Database is not set up");
|
||||
}
|
||||
|
||||
if (instance == null)
|
||||
start();
|
||||
|
||||
|
@ -48,6 +53,11 @@ public class DatabaseWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void invalidate() {
|
||||
instance=null;
|
||||
hasDB=false;
|
||||
}
|
||||
|
||||
private void restart() {
|
||||
|
||||
LibZontreck.LOGGER.info("Reconnecting to database...");
|
||||
|
|
Reference in a new issue