diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index d1b3261d6..ae3f0928e 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -30,7 +30,6 @@ import snaq.db.ConnectionPool; public final class SQLDatabaseManager implements DatabaseManager { private static final String ALL_QUERY_VERSION = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy"; - private String connectionString; private String tablePrefix = Config.getInstance().getMySQLTablePrefix(); private final int POOL_FETCH_TIMEOUT = 0; // How long a method will wait for a connection. Since none are on main thread, we can safely say wait for as long as you like. @@ -40,31 +39,32 @@ public final class SQLDatabaseManager implements DatabaseManager { private ConnectionPool connectionPool; - protected SQLDatabaseManager() { - connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName(); + protected SQLDatabaseManager() throws ClassNotFoundException { + String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName() + ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName(); try { // Force driver to load if not yet loaded Class.forName("com.mysql.jdbc.Driver"); - Properties connectionProperties = new Properties(); - connectionProperties.put("user", Config.getInstance().getMySQLUserName()); - connectionProperties.put("password", Config.getInstance().getMySQLUserPassword()); - connectionProperties.put("autoReconnect", "false"); - connectionPool = new ConnectionPool("mcMMO-Pool", - 1 /*Minimum of one*/, - Config.getInstance().getMySQLMaxPoolSize() /*max pool size */, - Config.getInstance().getMySQLMaxConnections() /*max num connections*/, - 0 /* idle timeout of connections */, - connectionString, - connectionProperties); - connectionPool.init(); // Init first connection - connectionPool.registerShutdownHook(); // Auto release on jvm exit just in case } catch (ClassNotFoundException e) { - // TODO tft do something here everything will blow up e.printStackTrace(); + throw e; // aborts onEnable() } + Properties connectionProperties = new Properties(); + connectionProperties.put("user", Config.getInstance().getMySQLUserName()); + connectionProperties.put("password", Config.getInstance().getMySQLUserPassword()); + connectionProperties.put("autoReconnect", "false"); + connectionPool = new ConnectionPool("mcMMO-Pool", + 1 /*Minimum of one*/, + Config.getInstance().getMySQLMaxPoolSize() /*max pool size */, + Config.getInstance().getMySQLMaxConnections() /*max num connections*/, + 0 /* idle timeout of connections */, + connectionString, + connectionProperties); + connectionPool.init(); // Init first connection + connectionPool.registerShutdownHook(); // Auto release on jvm exit just in case + checkStructure(); }