From f4c24d2e26a9b74954b445b8a207ab8f09551da9 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 26 Mar 2020 15:26:55 +0100 Subject: [PATCH] Drop jobs config table, we don't need anymore --- .../com/gamingmesh/jobs/dao/JobsMySQL.java | 32 ++----------------- .../com/gamingmesh/jobs/dao/JobsSQLite.java | 30 ++--------------- 2 files changed, 6 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java index f4ecbb43..6e514c29 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java @@ -9,13 +9,11 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.dao.JobsManager.DataBaseType; public class JobsMySQL extends JobsDAO { - private String database; JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect) { super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?maxReconnects=1&useUnicode=true&character_set_server=utf8mb4&autoReconnect=" + autoReconnect + "&useSSL=" + ssl + "&verifyServerCertificate=" + certificate, username, password, prefix); - this.database = database; this.setDbType(DataBaseType.MySQL); } @@ -44,34 +42,10 @@ public class JobsMySQL extends JobsDAO { Jobs.consoleMsg("&cCould not run database updates! Could not connect to MySQL!"); return; } - PreparedStatement prest = null; - int rows = 0; - ResultSet res = null; - try { - // Check for config table - prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;"); - prest.setString(1, database); - prest.setString(2, getPrefix() + "config"); - res = prest.executeQuery(); - if (res.next()) - rows = res.getInt(1); - } finally { - close(res); - close(prest); - } - if (rows == 0) { - PreparedStatement insert = null; - try { - executeSQL("CREATE TABLE `" + getPrefix() + "config` (`key` varchar(50) NOT NULL PRIMARY KEY, `value` int NOT NULL);"); - - insert = conn.prepareStatement("INSERT INTO `" + getPrefix() + "config` (`key`, `value`) VALUES (?, ?);"); - insert.setString(1, "version"); - insert.setInt(2, 1); - insert.execute(); - } finally { - close(insert); - } + String name = getPrefix() + "config"; + if (isTable(name)) { + drop(name); } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java index 6c56d0a2..0c4cd3d7 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java @@ -46,33 +46,9 @@ public class JobsSQLite extends JobsDAO { return; } - PreparedStatement prest = null; - ResultSet res = null; - int rows = 0; - try { - // Check for config table - prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;"); - prest.setString(1, getPrefix() + "config"); - res = prest.executeQuery(); - if (res.next()) { - rows = res.getInt(1); - } - } finally { - close(res); - close(prest); - } - - if (rows == 0) { - PreparedStatement insert = null; - try { - executeSQL("CREATE TABLE `" + getPrefix() + "config` (`key` varchar(50) NOT NULL PRIMARY KEY, `value` int NOT NULL);"); - insert = conn.prepareStatement("INSERT INTO `" + getPrefix() + "config` (`key`, `value`) VALUES (?, ?);"); - insert.setString(1, "version"); - insert.setInt(2, 1); - insert.execute(); - } finally { - close(insert); - } + String name = getPrefix() + "config"; + if (isTable(name)) { + drop(name); } }