Improve table creation logic

This commit is contained in:
Brokkonaut
2021-04-13 18:24:54 +02:00
parent fe7e244898
commit c20b677507
2 changed files with 12 additions and 6 deletions

View File

@ -842,14 +842,18 @@ class Updater {
} }
private void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException { private void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException {
if (!dbm.getTables(null, null, table, null).next()) { try (ResultSet tableResult = dbm.getTables(Config.mysqlDatabase, null, table, null)) {
if (!tableResult.next()) {
logblock.getLogger().log(Level.INFO, "Creating table " + table + "."); logblock.getLogger().log(Level.INFO, "Creating table " + table + ".");
state.execute("CREATE TABLE `" + table + "` " + query); state.execute("CREATE TABLE `" + table + "` " + query);
if (!dbm.getTables(null, null, table, null).next()) { try (ResultSet tableResultNew = dbm.getTables(Config.mysqlDatabase, null, table, null)) {
if (!tableResultNew.next()) {
throw new SQLException("Table " + table + " not found and failed to create"); throw new SQLException("Table " + table + " not found and failed to create");
} }
} }
} }
}
}
/** /**
* Update materials that were renamed * Update materials that were renamed

View File

@ -25,6 +25,7 @@ public class Config {
private static LoggingEnabledMapping superWorldConfig; private static LoggingEnabledMapping superWorldConfig;
private static Map<String, WorldConfig> worldConfigs; private static Map<String, WorldConfig> worldConfigs;
public static String url, user, password; public static String url, user, password;
public static String mysqlDatabase;
public static boolean mysqlUseSSL; public static boolean mysqlUseSSL;
public static boolean mysqlRequireSSL; public static boolean mysqlRequireSSL;
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun; public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
@ -175,7 +176,8 @@ public class Config {
ComparableVersion configVersion = new ComparableVersion(config.getString("version")); ComparableVersion configVersion = new ComparableVersion(config.getString("version"));
boolean oldConfig = configVersion.compareTo(new ComparableVersion(CURRENT_CONFIG_VERSION)) < 0; boolean oldConfig = configVersion.compareTo(new ComparableVersion(CURRENT_CONFIG_VERSION)) < 0;
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database"); mysqlDatabase = getStringIncludingInts(config, "mysql.database");
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + mysqlDatabase;
user = getStringIncludingInts(config, "mysql.user"); user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password"); password = getStringIncludingInts(config, "mysql.password");
mysqlUseSSL = config.getBoolean("mysql.useSSL", true); mysqlUseSSL = config.getBoolean("mysql.useSSL", true);