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
|
@ -53,7 +53,7 @@ mod_name=Zontreck's Library Mod
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=GPLv3
|
mod_license=GPLv3
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1201.13.050624.1254
|
mod_version=1201.13.061824.1459
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -120,7 +120,12 @@ public class LibZontreck {
|
||||||
ALIVE=true;
|
ALIVE=true;
|
||||||
|
|
||||||
ServerConfig.init();
|
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;
|
CURRENT_SIDE = LogicalSide.SERVER;
|
||||||
|
|
||||||
|
@ -132,6 +137,8 @@ public class LibZontreck {
|
||||||
BlockRestoreQueueRegistry.init(level);
|
BlockRestoreQueueRegistry.init(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!DatabaseWrapper.hasDB)return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DatabaseMigrations.initMigrations();
|
DatabaseMigrations.initMigrations();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -8,10 +8,15 @@ import java.sql.*;
|
||||||
|
|
||||||
public class DatabaseWrapper {
|
public class DatabaseWrapper {
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
public static boolean hasDB = true;
|
||||||
|
|
||||||
private static DatabaseWrapper instance;
|
private static DatabaseWrapper instance;
|
||||||
|
|
||||||
public static DatabaseWrapper get() {
|
public static DatabaseWrapper get() {
|
||||||
|
if(!hasDB) {
|
||||||
|
throw new RuntimeException("Error: Database is not set up");
|
||||||
|
}
|
||||||
|
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
start();
|
start();
|
||||||
|
|
||||||
|
@ -48,6 +53,11 @@ public class DatabaseWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void invalidate() {
|
||||||
|
instance=null;
|
||||||
|
hasDB=false;
|
||||||
|
}
|
||||||
|
|
||||||
private void restart() {
|
private void restart() {
|
||||||
|
|
||||||
LibZontreck.LOGGER.info("Reconnecting to database...");
|
LibZontreck.LOGGER.info("Reconnecting to database...");
|
||||||
|
|
Reference in a new issue