diff --git a/gradle.properties b/gradle.properties index 7540185..2e5096f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1201.13.043024.1530 +mod_version=1201.13.050624.1254 # 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. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java index f0c1bc8..06baa78 100644 --- a/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java +++ b/src/main/java/dev/zontreck/libzontreck/memory/world/DatabaseWrapper.java @@ -14,6 +14,12 @@ public class DatabaseWrapper { public static DatabaseWrapper get() { if (instance == null) start(); + + try { + instance.sanityCheck(); + } catch (SQLException e) { + throw new RuntimeException(e); + } return instance; } @@ -42,6 +48,18 @@ public class DatabaseWrapper { } } + private void restart() { + + LibZontreck.LOGGER.info("Reconnecting to database..."); + LibZontreck.LOGGER.info("jdbc:db ://" + ServerConfig.database.user + "@" + ServerConfig.database.host + "/" + ServerConfig.database.database); + + try { + instance.connect(ServerConfig.database.host, ServerConfig.database.user, ServerConfig.database.password, ServerConfig.database.database); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + public void connect(String url, String username, String password, String database) throws SQLException { if(database.isBlank()) { @@ -85,6 +103,12 @@ public class DatabaseWrapper { } } + private void sanityCheck() throws SQLException { + if(connection.isClosed() || connection == null) { + restart(); + } + } + public ResultSet executeQuery(String query) throws SQLException { if (connection == null) { throw new SQLException("Connection not established.");