forked from LogBlock/LogBlock
Improve table creation logic
This commit is contained in:
@ -842,11 +842,15 @@ 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)) {
|
||||||
logblock.getLogger().log(Level.INFO, "Creating table " + table + ".");
|
if (!tableResult.next()) {
|
||||||
state.execute("CREATE TABLE `" + table + "` " + query);
|
logblock.getLogger().log(Level.INFO, "Creating table " + table + ".");
|
||||||
if (!dbm.getTables(null, null, table, null).next()) {
|
state.execute("CREATE TABLE `" + table + "` " + query);
|
||||||
throw new SQLException("Table " + table + " not found and failed to create");
|
try (ResultSet tableResultNew = dbm.getTables(Config.mysqlDatabase, null, table, null)) {
|
||||||
|
if (!tableResultNew.next()) {
|
||||||
|
throw new SQLException("Table " + table + " not found and failed to create");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user