From c6745b410eabb75548c67660364db5e6072709fd Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 2 Mar 2020 13:41:38 +0800 Subject: [PATCH] Back to server thread Former-commit-id: d5e9bdf81b3aa9a2121b57662ef993ddb01b8f7c --- .../quickshop/Database/DatabaseHelper.java | 92 +++++++++---------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java index 95a81941c..42283d711 100644 --- a/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/quickshop/Database/DatabaseHelper.java @@ -56,77 +56,69 @@ public class DatabaseHelper { * Creates the database table 'shops'. */ private void createShopsTable() { - plugin.getDatabaseManager().add(() -> { - try { - Statement st = db.getConnection().createStatement(); - String createTable = "CREATE TABLE " + QuickShop.instance - .getDbPrefix() + "shops (owner VARCHAR(255) NOT NULL, price double(32, 2) NOT NULL, itemConfig TEXT CHARSET utf8 NOT NULL, x INTEGER(32) NOT NULL, y INTEGER(32) NOT NULL, z INTEGER(32) NOT NULL, world VARCHAR(32) NOT NULL, unlimited boolean, type boolean, PRIMARY KEY (x, y, z, world) );"; - st.execute(createTable); - } catch (SQLException e) { - e.printStackTrace(); - } - }); + try { + Statement st = db.getConnection().createStatement(); + String createTable = "CREATE TABLE " + QuickShop.instance + .getDbPrefix() + "shops (owner VARCHAR(255) NOT NULL, price double(32, 2) NOT NULL, itemConfig TEXT CHARSET utf8 NOT NULL, x INTEGER(32) NOT NULL, y INTEGER(32) NOT NULL, z INTEGER(32) NOT NULL, world VARCHAR(32) NOT NULL, unlimited boolean, type boolean, PRIMARY KEY (x, y, z, world) );"; + st.execute(createTable); + } catch (SQLException e) { + e.printStackTrace(); + } } /** * Creates the database table 'messages' * * @return Create failed or successed. - * @throws SQLException If the connection is invalid */ - private void createMessagesTable() throws SQLException { - plugin.getDatabaseManager().add(() -> { - try { - Statement st = db.getConnection().createStatement(); - String createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() - + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) NOT NULL, time BIGINT(32) NOT NULL );"; - if (plugin.getDatabase().getCore() instanceof MySQLCore) { - createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() - + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL , time BIGINT(32) NOT NULL );"; - } - st.execute(createTable); - } catch (SQLException e) { - e.printStackTrace(); + private void createMessagesTable() { + try { + Statement st = db.getConnection().createStatement(); + String createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() + + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) NOT NULL, time BIGINT(32) NOT NULL );"; + if (plugin.getDatabase().getCore() instanceof MySQLCore) { + createTable = "CREATE TABLE " + QuickShop.instance.getDbPrefix() + + "messages (owner VARCHAR(255) NOT NULL, message TEXT(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL , time BIGINT(32) NOT NULL );"; } - }); + st.execute(createTable); + } catch (SQLException e) { + e.printStackTrace(); + } } /** * Verifies that all required columns exist. */ private void checkColumns() { - plugin.getDatabaseManager().add(() -> { - PreparedStatement ps; + PreparedStatement ps; + try { + // V3.4.2 + ps = db.getConnection().prepareStatement("ALTER TABLE " + QuickShop.instance + .getDbPrefix() + "shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner"); + ps.execute(); + ps.close(); + } catch (SQLException e) { + //ignore + } + try { + // V3.4.3 + ps = db.getConnection().prepareStatement("ALTER TABLE " + QuickShop.instance + .getDbPrefix() + "messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message"); + ps.execute(); + ps.close(); + } catch (SQLException e) { + //ignore + } + if (QuickShop.instance.getDatabase().getCore() instanceof MySQLCore) { try { - // V3.4.2 ps = db.getConnection().prepareStatement("ALTER TABLE " + QuickShop.instance - .getDbPrefix() + "shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner"); + .getDbPrefix() + "messages MODIFY COLUMN message text CHARACTER SET utf8mb4 NOT NULL AFTER owner"); ps.execute(); ps.close(); } catch (SQLException e) { //ignore } - try { - // V3.4.3 - ps = db.getConnection().prepareStatement("ALTER TABLE " + QuickShop.instance - .getDbPrefix() + "messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message"); - ps.execute(); - ps.close(); - } catch (SQLException e) { - //ignore - } - if (QuickShop.instance.getDatabase().getCore() instanceof MySQLCore) { - try { - ps = db.getConnection().prepareStatement("ALTER TABLE " + QuickShop.instance - .getDbPrefix() + "messages MODIFY COLUMN message text CHARACTER SET utf8mb4 NOT NULL AFTER owner"); - ps.execute(); - ps.close(); - } catch (SQLException e) { - //ignore - } - } - }); - + } } public void cleanMessage(long weekAgo) {