diff --git a/Core/src/main/java/com/craftaro/core/SongodaPlugin.java b/Core/src/main/java/com/craftaro/core/SongodaPlugin.java index 514e9fbf..d798f16f 100644 --- a/Core/src/main/java/com/craftaro/core/SongodaPlugin.java +++ b/Core/src/main/java/com/craftaro/core/SongodaPlugin.java @@ -18,6 +18,7 @@ import java.io.File; import java.sql.Connection; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -255,7 +256,7 @@ public Config getDatabaseConfig() { * @return DataManager for this plugin. */ public DataManager getDataManager() { - return dataManager; + return this.dataManager; } /** @@ -265,6 +266,10 @@ protected void initDatabase() { initDatabase(Collections.emptyList()); } + protected void initDatabase(DataMigration... migrations) { + initDatabase(Arrays.asList(migrations)); + } + /** * Initialize the DataManager for this plugin and convert from SQLite to H2 if needed. * @@ -281,9 +286,9 @@ protected void initDatabase(List migrations) { this.dataManager = new DataManager(this, migrations); } - if (dataManager.getDatabaseConnector().isInitialized()) { + if (this.dataManager.getDatabaseConnector().isInitialized()) { //Check if the type is SQLite - if (dataManager.getDatabaseConnector().getType() == DatabaseType.SQLITE) { + if (this.dataManager.getDatabaseConnector().getType() == DatabaseType.SQLITE) { //Let's convert it to H2 try { DataManager newDataManager = DataMigration.convert(this, DatabaseType.H2); @@ -291,8 +296,9 @@ protected void initDatabase(List migrations) { //Set the new data manager setDataManager(newDataManager); } - } catch (Exception e) { - e.printStackTrace(); + } catch (Exception ex) { + // Throwing for keeping backwards compatible – Not a fan of just logging a potential critical error here + throw new RuntimeException(ex); } } } @@ -305,10 +311,10 @@ protected void initDatabase(List migrations) { public void setDataManager(DataManager dataManager) { if (dataManager == null) throw new IllegalArgumentException("DataManager cannot be null!"); if (this.dataManager == dataManager) return; - //Make sure to shut down the old data manager. + + // Make sure to shut down the old data manager. if (this.dataManager != null) { this.dataManager.shutdown(); - this.dataManager = null; } this.dataManager = dataManager; }