From 2b0f1b4b23bbd6a15aecbd5d1308e7cbae6d655e Mon Sep 17 00:00:00 2001 From: ceze88 <70201650+ceze88@users.noreply.github.com> Date: Sun, 14 Aug 2022 11:53:38 +0200 Subject: [PATCH] Remove deprecated methods, fix MySQL --- pom.xml | 2 +- .../UltimateModeration.java | 7 +- .../database/DataManager.java | 287 ++++++++++-------- .../ultimatemoderation/settings/Settings.java | 1 + 4 files changed, 174 insertions(+), 123 deletions(-) diff --git a/pom.xml b/pom.xml index 2170651..06acd32 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,7 @@ com.songoda SongodaCore - 2.6.13 + 2.6.14-DEV compile diff --git a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java index cbefe40..8066683 100644 --- a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java +++ b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java @@ -106,8 +106,9 @@ public class UltimateModeration extends SongodaPlugin { String username = Settings.MYSQL_USERNAME.getString(); String password = Settings.MYSQL_PASSWORD.getString(); boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean(); + int poolSize = Settings.MYSQL_POOL_SIZE.getInt(); - this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL); + this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize); this.getLogger().info("Data handler connected using MySQL."); } else { this.databaseConnector = new SQLiteConnector(this); @@ -150,7 +151,7 @@ public class UltimateModeration extends SongodaPlugin { @Override public void onDataLoad() { - getDataManager().queueAsync(() -> { + getDataManager().runAsync(() -> { // Load data from DB this.dataManager.getTemplates((templates) -> { for (Template template : templates) { @@ -169,7 +170,7 @@ public class UltimateModeration extends SongodaPlugin { for (Ticket ticket : tickets.values()) this.ticketManager.addTicket(ticket); }); - }, "create"); + }); } @Override diff --git a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java index 7985009..709a646 100644 --- a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java @@ -13,6 +13,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.Plugin; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; @@ -30,36 +31,43 @@ public class DataManager extends DataManagerAbstract { } public void createTemplate(Template template) { - this.queueAsync(() -> this.databaseConnector.connect(connection -> { - String createTemplate = "INSERT INTO " + this.getTablePrefix() + "templates (punishment_type, duration, reason, name, creator) VALUES (?, ?, ?, ?, ?)"; - try (PreparedStatement statement = connection.prepareStatement(createTemplate)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()) { + String createTemplate = "INSERT INTO " + this.getTablePrefix() + "templates (punishment_type, duration, reason, name, creator) VALUES (?, ?, ?, ?, ?)"; + PreparedStatement statement = connection.prepareStatement(createTemplate); statement.setString(1, template.getPunishmentType().name()); statement.setLong(2, template.getDuration()); statement.setString(3, template.getReason()); statement.setString(4, template.getName()); statement.setString(5, template.getCreator().toString()); statement.executeUpdate(); - } - int templateId = this.lastInsertedId(connection, "templates"); - template.setId(templateId); - }), "create"); + int templateId = this.lastInsertedId(connection, "templates"); + template.setId(templateId); + } catch (Exception ex) { + ex.printStackTrace(); + } + }); } public void deleteTemplate(Template template) { - this.async(() -> this.databaseConnector.connect(connection -> { - String deleteTemplate = "DELETE FROM " + this.getTablePrefix() + "templates WHERE id = ?"; - try (PreparedStatement statement = connection.prepareStatement(deleteTemplate)) { + this.runAsync(() -> { + try (Connection connection = this.databaseConnector.getConnection()) { + String deleteTemplate = "DELETE FROM " + this.getTablePrefix() + "templates WHERE id = ?"; + PreparedStatement statement = connection.prepareStatement(deleteTemplate); statement.setLong(1, template.getId()); statement.executeUpdate(); + } catch (Exception ex) { + ex.printStackTrace(); } - })); + }); } public void getTemplates(Consumer> callback) { List