From 5dc7f3581aa326eb19a5766787a89c2a23878df9 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Tue, 13 Jun 2023 20:33:26 +0200 Subject: [PATCH 1/7] Add hikaricp dependency --- Core/build.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Core/build.gradle.kts b/Core/build.gradle.kts index c7b2172ac..c2ed27b55 100644 --- a/Core/build.gradle.kts +++ b/Core/build.gradle.kts @@ -44,6 +44,9 @@ dependencies { api(libs.arkitektonika) api("com.intellectualsites.paster:Paster") api("com.intellectualsites.informative-annotations:informative-annotations") + + // Database + implementation("com.zaxxer:HikariCP:5.0.1") } tasks.processResources { From 03ad2a5b2cc0fb7d867ead846f5b0aab5bcfd8eb Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Tue, 13 Jun 2023 20:55:42 +0200 Subject: [PATCH 2/7] Hard break database integration --- .../plotsquared/core/database/Database.java | 19 ----- .../com/plotsquared/core/database/MySQL.java | 71 +++++++------------ .../com/plotsquared/core/database/SQLite.java | 66 +++++++---------- 3 files changed, 51 insertions(+), 105 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/database/Database.java b/Core/src/main/java/com/plotsquared/core/database/Database.java index 9f20ad7da..4beee9256 100644 --- a/Core/src/main/java/com/plotsquared/core/database/Database.java +++ b/Core/src/main/java/com/plotsquared/core/database/Database.java @@ -31,25 +31,6 @@ import java.sql.Statement; */ public abstract class Database { - public abstract Connection forceConnection() throws SQLException, ClassNotFoundException; - - /** - * Opens a connection with the database. - * - * @return Opened connection - * @throws SQLException if the connection can not be opened - * @throws ClassNotFoundException if the driver cannot be found - */ - public abstract Connection openConnection() throws SQLException, ClassNotFoundException; - - /** - * Checks if a connection is open with the database. - * - * @return {@code true} if the connection is open - * @throws SQLException if the connection cannot be checked - */ - public abstract boolean checkConnection() throws SQLException; - /** * Gets the connection with the database. * diff --git a/Core/src/main/java/com/plotsquared/core/database/MySQL.java b/Core/src/main/java/com/plotsquared/core/database/MySQL.java index a8767b598..5b961dba3 100644 --- a/Core/src/main/java/com/plotsquared/core/database/MySQL.java +++ b/Core/src/main/java/com/plotsquared/core/database/MySQL.java @@ -20,6 +20,8 @@ package com.plotsquared.core.database; import com.plotsquared.core.configuration.Storage; import com.plotsquared.core.util.StringMan; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; import java.sql.Connection; import java.sql.DriverManager; @@ -35,12 +37,7 @@ import java.sql.Statement; */ public class MySQL extends Database { - private final String user; - private final String database; - private final String password; - private final String port; - private final String hostname; - private Connection connection; + private final HikariDataSource hikariDataSource; /** * Creates a new MySQL instance. @@ -52,66 +49,52 @@ public class MySQL extends Database { * @param password Password */ public MySQL(String hostname, String port, String database, String username, String password) { - this.hostname = hostname; - this.port = port; - this.database = database; - this.user = username; - this.password = password; - this.connection = null; - } - - @Override - public Connection forceConnection() throws SQLException { - this.connection = DriverManager.getConnection( - "jdbc:mysql://" + this.hostname + ':' + this.port + '/' + this.database + "?" - + StringMan.join(Storage.MySQL.PROPERTIES, "&"), this.user, this.password); - return this.connection; - } - - @Override - public Connection openConnection() throws SQLException { - if (checkConnection()) { - return this.connection; + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:mysql://" + hostname + ':' + port + '/' + database); + config.setUsername(username); + config.setPassword(password); + for (final String property : Storage.MySQL.PROPERTIES) { + if (property.contains("=")) { + String[] splittedProperty = property.split("="); + if (splittedProperty.length != 2) { + continue; + } + String key = splittedProperty[0]; + String value = splittedProperty[1]; + config.addDataSourceProperty(key,value); + } } - return forceConnection(); - } - - @Override - public boolean checkConnection() throws SQLException { - return (this.connection != null) && !this.connection.isClosed(); + this.hikariDataSource = new HikariDataSource(config); } @Override public Connection getConnection() { - return this.connection; + try { + return this.hikariDataSource.getConnection(); + } catch (SQLException e) { + throw new RuntimeException(e); + } } @Override public boolean closeConnection() throws SQLException { - if (this.connection == null) { + if (this.hikariDataSource == null) { return false; } - this.connection.close(); - this.connection = null; + this.hikariDataSource.close(); return true; } @Override public ResultSet querySQL(String query) throws SQLException { - if (checkConnection()) { - openConnection(); - } - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { return statement.executeQuery(query); } } @Override public int updateSQL(String query) throws SQLException { - if (checkConnection()) { - openConnection(); - } - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { return statement.executeUpdate(query); } } diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLite.java b/Core/src/main/java/com/plotsquared/core/database/SQLite.java index c34be4c59..67d634d7b 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLite.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLite.java @@ -19,13 +19,14 @@ package com.plotsquared.core.database; import com.plotsquared.core.PlotSquared; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -36,9 +37,7 @@ import java.sql.Statement; public class SQLite extends Database { private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + SQLite.class.getSimpleName()); - - private final String dbLocation; - private Connection connection; + private final HikariDataSource hikariDataSource; /** * Creates a new SQLite instance @@ -46,18 +45,10 @@ public class SQLite extends Database { * @param dbLocation Location of the Database (Must end in .db) */ public SQLite(File dbLocation) { - this.dbLocation = dbLocation.getAbsolutePath(); - } - - @Override - public Connection openConnection() throws SQLException, ClassNotFoundException { - if (checkConnection()) { - return this.connection; - } if (!PlotSquared.platform().getDirectory().exists()) { PlotSquared.platform().getDirectory().mkdirs(); } - File file = new File(this.dbLocation); + File file = dbLocation; if (!file.exists()) { try { file.createNewFile(); @@ -65,56 +56,47 @@ public class SQLite extends Database { LOGGER.error("Unable to create database"); } } - Class.forName("org.sqlite.JDBC"); - this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation); - return this.connection; - } - - @Override - public boolean checkConnection() throws SQLException { - return (this.connection != null) && !this.connection.isClosed(); + try { + Class.forName("org.sqlite.JDBC"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:sqlite:" + dbLocation); + config.setDriverClassName("org.sqlite.JDBC"); + this.hikariDataSource = new HikariDataSource(config); } @Override public Connection getConnection() { - return this.connection; + try { + return this.hikariDataSource.getConnection(); + } catch (SQLException e) { + throw new RuntimeException(e); + } } @Override public boolean closeConnection() throws SQLException { - if (this.connection == null) { + if (this.hikariDataSource == null) { return false; } - this.connection.close(); - this.connection = null; + this.hikariDataSource.close(); return true; } @Override - public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException { - if (checkConnection()) { - openConnection(); - } - try (Statement statement = this.connection.createStatement()) { + public ResultSet querySQL(String query) throws SQLException { + try (Statement statement = this.getConnection().createStatement()) { return statement.executeQuery(query); } } @Override - public int updateSQL(String query) throws SQLException, ClassNotFoundException { - if (checkConnection()) { - openConnection(); - } - try (Statement statement = this.connection.createStatement()) { + public int updateSQL(String query) throws SQLException { + try (Statement statement = this.getConnection().createStatement()) { return statement.executeUpdate(query); } } - @Override - public Connection forceConnection() throws SQLException, ClassNotFoundException { - Class.forName("org.sqlite.JDBC"); - this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbLocation); - return this.connection; - } - } From fe05317a760bb54cbc4680e668a0817709f72ac2 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Tue, 13 Jun 2023 20:55:55 +0200 Subject: [PATCH 3/7] Use getConnection() instead of one single connection --- .../bukkit/uuid/SQLiteUUIDService.java | 5 - .../plotsquared/core/database/SQLManager.java | 233 +++++++++--------- 2 files changed, 112 insertions(+), 126 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java index 9193b4f0a..12a4cbbd4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java @@ -45,11 +45,6 @@ public class SQLiteUUIDService implements UUIDService, Consumer> clusterTasks; - // Private - private Connection connection; private boolean closed = false; /** @@ -153,7 +151,6 @@ public class SQLManager implements AbstractDB { this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; this.database = database; - this.connection = database.openConnection(); this.mySQL = database instanceof MySQL; this.globalTasks = new ConcurrentLinkedQueue<>(); this.notifyTasks = new ConcurrentLinkedQueue<>(); @@ -228,13 +225,13 @@ public class SQLManager implements AbstractDB { public boolean isValid() { try { - if (connection.isClosed()) { + if (getConnection().isClosed()) { return false; } } catch (SQLException e) { return false; } - try (PreparedStatement stmt = this.connection.prepareStatement("SELECT 1")) { + try (PreparedStatement stmt = this.getConnection().prepareStatement("SELECT 1")) { stmt.execute(); return true; } catch (Throwable e) { @@ -243,13 +240,8 @@ public class SQLManager implements AbstractDB { } public void reconnect() { - try { - close(); - SQLManager.this.closed = false; - SQLManager.this.connection = database.forceConnection(); - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } + close(); + SQLManager.this.closed = false; } public synchronized Queue getGlobalTasks() { @@ -369,8 +361,8 @@ public class SQLManager implements AbstractDB { public boolean sendBatch() { try { if (!getGlobalTasks().isEmpty()) { - if (this.connection.getAutoCommit()) { - this.connection.setAutoCommit(false); + if (this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(false); } Runnable task = getGlobalTasks().remove(); if (task != null) { @@ -391,8 +383,8 @@ public class SQLManager implements AbstractDB { int count = -1; if (!this.plotTasks.isEmpty()) { count = Math.max(count, 0); - if (this.connection.getAutoCommit()) { - this.connection.setAutoCommit(false); + if (this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(false); } String method = null; PreparedStatement statement = null; @@ -446,8 +438,8 @@ public class SQLManager implements AbstractDB { } if (!this.playerTasks.isEmpty()) { count = Math.max(count, 0); - if (this.connection.getAutoCommit()) { - this.connection.setAutoCommit(false); + if (this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(false); } String method = null; PreparedStatement statement = null; @@ -491,8 +483,8 @@ public class SQLManager implements AbstractDB { } if (!this.clusterTasks.isEmpty()) { count = Math.max(count, 0); - if (this.connection.getAutoCommit()) { - this.connection.setAutoCommit(false); + if (this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(false); } String method = null; PreparedStatement statement = null; @@ -540,8 +532,8 @@ public class SQLManager implements AbstractDB { return true; } if (count != -1) { - if (!this.connection.getAutoCommit()) { - this.connection.setAutoCommit(true); + if (!this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(true); } } if (!this.clusterTasks.isEmpty()) { @@ -562,7 +554,7 @@ public class SQLManager implements AbstractDB { } public Connection getConnection() { - return this.connection; + return this.database.getConnection(); } /** @@ -584,7 +576,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement(SQLManager.this.SET_OWNER); + return SQLManager.this.getConnection().prepareStatement(SQLManager.this.SET_OWNER); } }); } @@ -609,7 +601,7 @@ public class SQLManager implements AbstractDB { final ArrayList denied = new ArrayList<>(); // Populating structures - try (PreparedStatement stmt = SQLManager.this.connection + try (PreparedStatement stmt = SQLManager.this.getConnection() .prepareStatement(SQLManager.this.GET_ALL_PLOTS); ResultSet result = stmt.executeQuery()) { while (result.next()) { @@ -640,7 +632,7 @@ public class SQLManager implements AbstractDB { () -> createTiers(trusted, "trusted", () -> createTiers(denied, "denied", () -> { try { - SQLManager.this.connection.commit(); + SQLManager.this.getConnection().commit(); } catch (SQLException e) { e.printStackTrace(); } @@ -654,7 +646,7 @@ public class SQLManager implements AbstractDB { } catch (SQLException e) { LOGGER.warn("Failed to set all flags and member tiers for plots", e); try { - SQLManager.this.connection.commit(); + SQLManager.this.getConnection().commit(); } catch (SQLException e1) { e1.printStackTrace(); } @@ -663,7 +655,7 @@ public class SQLManager implements AbstractDB { } catch (Exception e) { LOGGER.warn("Warning! Failed to set all helper for plots", e); try { - SQLManager.this.connection.commit(); + SQLManager.this.getConnection().commit(); } catch (SQLException e1) { e1.printStackTrace(); } @@ -724,7 +716,7 @@ public class SQLManager implements AbstractDB { } public void createFlags(Map ids, List plots, Runnable whenDone) { - try (final PreparedStatement preparedStatement = this.connection.prepareStatement( + try (final PreparedStatement preparedStatement = this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) { for (final Plot plot : plots) { @@ -849,13 +841,13 @@ public class SQLManager implements AbstractDB { if (last == -1) { last = subList.size(); statement = mod.getCreateMySQL(subList.size()); - preparedStmt = this.connection.prepareStatement(statement); + preparedStmt = this.getConnection().prepareStatement(statement); } if (subList.size() != last || count % 5000 == 0 && count > 0) { preparedStmt.executeBatch(); preparedStmt.close(); statement = mod.getCreateMySQL(subList.size()); - preparedStmt = this.connection.prepareStatement(statement); + preparedStmt = this.getConnection().prepareStatement(statement); } for (int i = 0; i < subList.size(); i++) { count++; @@ -891,13 +883,13 @@ public class SQLManager implements AbstractDB { if (last == -1) { last = subList.size(); statement = mod.getCreateSQLite(subList.size()); - preparedStmt = this.connection.prepareStatement(statement); + preparedStmt = this.getConnection().prepareStatement(statement); } if (subList.size() != last || count % 5000 == 0 && count > 0) { preparedStmt.executeBatch(); preparedStmt.clearParameters(); statement = mod.getCreateSQLite(subList.size()); - preparedStmt = this.connection.prepareStatement(statement); + preparedStmt = this.getConnection().prepareStatement(statement); } for (int i = 0; i < subList.size(); i++) { count++; @@ -914,7 +906,7 @@ public class SQLManager implements AbstractDB { e.printStackTrace(); LOGGER.error("2: | {}", objList.get(0).getClass().getCanonicalName()); LOGGER.error("Could not bulk save!"); - try (PreparedStatement preparedStmt = this.connection + try (PreparedStatement preparedStmt = this.getConnection() .prepareStatement(mod.getCreateSQL())) { for (T obj : objList) { mod.setSQL(preparedStmt, obj); @@ -932,7 +924,7 @@ public class SQLManager implements AbstractDB { } public void createSettings(final ArrayList myList, final Runnable whenDone) { - try (final PreparedStatement preparedStatement = this.connection.prepareStatement( + try (final PreparedStatement preparedStatement = this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`" + "(`plot_plot_id`,`biome`,`rain`,`custom_time`,`time`,`deny_entry`,`alias`,`merged`,`position`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)")) { @@ -1060,7 +1052,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( SQLManager.this.CREATE_PLOT_SAFE, Statement.RETURN_GENERATED_KEYS ); @@ -1088,7 +1080,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"); } @@ -1112,9 +1104,9 @@ public class SQLManager implements AbstractDB { return; } try { - if (!this.connection.getAutoCommit()) { - this.connection.commit(); - this.connection.setAutoCommit(true); + if (!this.getConnection().getAutoCommit()) { + this.getConnection().commit(); + this.getConnection().setAutoCommit(true); } } catch (SQLException e) { e.printStackTrace(); @@ -1135,7 +1127,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection + return SQLManager.this.getConnection() .prepareStatement(SQLManager.this.CREATE_PLOT, Statement.RETURN_GENERATED_KEYS); } @@ -1161,7 +1153,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"); } @@ -1179,7 +1171,7 @@ public class SQLManager implements AbstractDB { String[] tables = new String[]{"plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted", "plot_rating", "plot_settings", "cluster", "player_meta", "plot_flags"}; - DatabaseMetaData meta = this.connection.getMetaData(); + DatabaseMetaData meta = this.getConnection().getMetaData(); int create = 0; for (String s : tables) { ResultSet set = meta.getTables(null, null, this.prefix + s, new String[]{"TABLE"}); @@ -1193,7 +1185,7 @@ public class SQLManager implements AbstractDB { return; } boolean addConstraint = create == tables.length; - try (Statement stmt = this.connection.createStatement()) { + try (Statement stmt = this.getConnection().createStatement()) { if (this.mySQL) { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" + "`id` INT(11) NOT NULL AUTO_INCREMENT," + "`plot_id_x` INT(11) NOT NULL," @@ -1339,7 +1331,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = ?"); } @@ -1359,7 +1351,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ?"); } @@ -1379,7 +1371,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ?"); } @@ -1399,7 +1391,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ?"); } @@ -1417,7 +1409,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?"); } @@ -1437,7 +1429,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_rating` WHERE `plot_plot_id` = ?"); } @@ -1465,7 +1457,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?"); } }); @@ -1487,7 +1479,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"); } @@ -1505,7 +1497,7 @@ public class SQLManager implements AbstractDB { return cluster.temp; } int c_id; - try (PreparedStatement stmt = this.connection.prepareStatement( + try (PreparedStatement stmt = this.getConnection().prepareStatement( "SELECT `id` FROM `" + this.prefix + "cluster` WHERE `pos1_x` = ? AND `pos1_z` = ? AND `pos2_x` = ? AND `pos2_z` = ? AND `world` = ? ORDER BY `timestamp` ASC")) { stmt.setInt(1, cluster.getP1().getX()); @@ -1545,7 +1537,7 @@ public class SQLManager implements AbstractDB { return plot.temp; } int id; - try (PreparedStatement statement = this.connection.prepareStatement( + try (PreparedStatement statement = this.getConnection().prepareStatement( "SELECT `id` FROM `" + this.prefix + "plot` WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND world = ? ORDER BY `timestamp` ASC")) { statement.setInt(1, plot.getId().getX()); @@ -1576,13 +1568,13 @@ public class SQLManager implements AbstractDB { public void updateTables(int[] oldVersion) { try { if (this.mySQL && !PlotSquared.get().checkVersion(oldVersion, 3, 3, 2)) { - try (Statement stmt = this.connection.createStatement()) { + try (Statement stmt = this.getConnection().createStatement()) { stmt.executeUpdate( "ALTER TABLE `" + this.prefix + "plots` DROP INDEX `unique_alias`"); } catch (SQLException ignored) { } } - DatabaseMetaData data = this.connection.getMetaData(); + DatabaseMetaData data = this.getConnection().getMetaData(); ResultSet rs = data.getColumns(null, null, this.prefix + "plot_comments", "plot_plot_id"); if (rs.next()) { @@ -1590,7 +1582,7 @@ public class SQLManager implements AbstractDB { rs = data.getColumns(null, null, this.prefix + "plot_comments", "hashcode"); if (!rs.next()) { rs.close(); - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { statement.addBatch("DROP TABLE `" + this.prefix + "plot_comments`"); if (Storage.MySQL.USE) { statement.addBatch( @@ -1611,7 +1603,7 @@ public class SQLManager implements AbstractDB { } statement.executeBatch(); } catch (SQLException ignored) { - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { statement.addBatch("ALTER IGNORE TABLE `" + this.prefix + "plot_comments` ADD `inbox` VARCHAR(11) DEFAULT `public`"); statement.addBatch("ALTER IGNORE TABLE `" + this.prefix @@ -1625,7 +1617,7 @@ public class SQLManager implements AbstractDB { rs.close(); rs = data.getColumns(null, null, this.prefix + "plot_denied", "plot_plot_id"); if (rs.next()) { - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { statement.executeUpdate("DELETE FROM `" + this.prefix + "plot_denied` WHERE `plot_plot_id` NOT IN (SELECT `id` FROM `" + this.prefix + "plot`)"); @@ -1634,7 +1626,7 @@ public class SQLManager implements AbstractDB { } rs.close(); - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { for (String table : new String[]{"plot_denied", "plot_helpers", "plot_trusted"}) { ResultSet result = statement.executeQuery( @@ -1706,7 +1698,7 @@ public class SQLManager implements AbstractDB { @Override public boolean convertFlags() { final Map> flagMap = new HashMap<>(); - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { try (ResultSet resultSet = statement .executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) { while (resultSet.next()) { @@ -1736,7 +1728,7 @@ public class SQLManager implements AbstractDB { } LOGGER.info("Loaded {} plot flag collections...", flagMap.size()); LOGGER.info("Attempting to store these flags in the new table..."); - try (final PreparedStatement preparedStatement = this.connection.prepareStatement( + try (final PreparedStatement preparedStatement = this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) { @@ -1821,7 +1813,7 @@ public class SQLManager implements AbstractDB { /* * Getting plots */ - try (Statement statement = this.connection.createStatement()) { + try (Statement statement = this.getConnection().createStatement()) { int id; String o; UUID user; @@ -2155,7 +2147,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?"); } @@ -2170,7 +2162,7 @@ public class SQLManager implements AbstractDB { final int id2 = getId(plot2); final PlotId pos1 = plot1.getId(); final PlotId pos2 = plot2.getId(); - try (final PreparedStatement preparedStatement = this.connection.prepareStatement( + try (final PreparedStatement preparedStatement = this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot` SET `plot_id_x` = ?, `plot_id_z` = ? WHERE `id` = ?")) { preparedStatement.setInt(1, pos1.getX()); @@ -2205,7 +2197,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot` SET `plot_id_x` = ?, `plot_id_z` = ?, `world` = ? WHERE `id` = ?"); } @@ -2236,7 +2228,7 @@ public class SQLManager implements AbstractDB { + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?) " + "ON CONFLICT(`plot_id`,`flag`) DO UPDATE SET `value` = ?"; } - return SQLManager.this.connection.prepareStatement(statement); + return SQLManager.this.getConnection().prepareStatement(statement); } }); } @@ -2252,7 +2244,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_flags` WHERE `plot_id` = ? AND `flag` = ?"); } @@ -2270,7 +2262,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?"); } @@ -2307,27 +2299,27 @@ public class SQLManager implements AbstractDB { idstr.append(stmt_prefix).append(id); stmt_prefix = " OR `plot_plot_id` = "; } - PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); - stmt = SQLManager.this.connection.prepareStatement( + stmt = SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); - stmt = SQLManager.this.connection.prepareStatement( + stmt = SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); - stmt = SQLManager.this.connection.prepareStatement( + stmt = SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr); stmt.executeUpdate(); stmt.close(); - stmt = SQLManager.this.connection.prepareStatement( + stmt = SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = " + idstr2); stmt.executeUpdate(); @@ -2346,7 +2338,7 @@ public class SQLManager implements AbstractDB { @Override public void purge(final PlotArea area, final Set plots) { addGlobalTask(() -> { - try (PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + try (PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + SQLManager.this.prefix + "plot` WHERE `world` = ?")) { stmt.setString(1, area.toString()); @@ -2385,7 +2377,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?"); } @@ -2413,11 +2405,11 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { if (plot != null) { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `comment` = ? AND `inbox` = ? AND `sender` = ?"); } - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `comment` = ? AND `inbox` = ? AND `sender` = ?"); } @@ -2441,11 +2433,11 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { if (plot != null) { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); } - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_comments` `inbox` = ?"); } }); @@ -2471,11 +2463,11 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { if (plot != null) { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "SELECT * FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ? AND `inbox` = ?"); } - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "SELECT * FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `inbox` = ?"); } @@ -2526,7 +2518,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_comments` (`world`, `hashcode`, `comment`, `inbox`, `timestamp`, `sender`) VALUES(?,?,?,?,?,?)"); } @@ -2544,7 +2536,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); } @@ -2562,7 +2554,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); } @@ -2580,7 +2572,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); } @@ -2598,7 +2590,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); } @@ -2616,7 +2608,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); } @@ -2634,7 +2626,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); } @@ -2644,7 +2636,7 @@ public class SQLManager implements AbstractDB { @Override public HashMap getRatings(Plot plot) { HashMap map = new HashMap<>(); - try (PreparedStatement statement = this.connection.prepareStatement( + try (PreparedStatement statement = this.getConnection().prepareStatement( "SELECT `rating`, `player` FROM `" + this.prefix + "plot_rating` WHERE `plot_plot_id` = ? ")) { statement.setInt(1, getId(plot)); @@ -2674,7 +2666,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_rating` (`plot_plot_id`, `rating`, `player`) VALUES(?,?,?)"); } @@ -2692,7 +2684,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster_settings` WHERE `cluster_id` = ?"); } @@ -2705,7 +2697,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster_helpers` WHERE `cluster_id` = ?"); } @@ -2718,7 +2710,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster_invited` WHERE `cluster_id` = ?"); } @@ -2731,7 +2723,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster` WHERE `id` = ?"); } }); @@ -2759,11 +2751,11 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { if (replace) { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "player_meta` SET `value` = ? WHERE `uuid` = ? AND `key` = ?"); } else { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "player_meta`(`uuid`, `key`, `value`) VALUES(?, ? ,?)"); } @@ -2782,7 +2774,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "player_meta` WHERE `uuid` = ? AND `key` = ?"); } @@ -2799,7 +2791,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "SELECT * FROM `" + SQLManager.this.prefix + "player_meta` WHERE `uuid` = ? ORDER BY `meta_id` ASC"); } @@ -2856,7 +2848,7 @@ public class SQLManager implements AbstractDB { /* * Getting clusters */ - try (Statement stmt = this.connection.createStatement()) { + try (Statement stmt = this.getConnection().createStatement()) { ResultSet resultSet = stmt.executeQuery("SELECT * FROM `" + this.prefix + "cluster`"); PlotCluster cluster; @@ -2987,7 +2979,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "cluster_settings` SET `alias` = ? WHERE `cluster_id` = ?"); } @@ -3006,7 +2998,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster_helpers` WHERE `cluster_id` = ? AND `user_uuid` = ?"); } @@ -3024,7 +3016,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "cluster_helpers` (`cluster_id`, `user_uuid`) VALUES(?,?)"); } @@ -3046,7 +3038,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( SQLManager.this.CREATE_CLUSTER, Statement.RETURN_GENERATED_KEYS ); @@ -3077,7 +3069,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "cluster_settings`(`cluster_id`, `alias`) VALUES(?, ?)"); } @@ -3104,7 +3096,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "cluster` SET `pos1_x` = ?, `pos1_z` = ?, `pos2_x` = ?, `pos2_z` = ? WHERE `id` = ?"); } @@ -3122,7 +3114,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "cluster_settings` SET `position` = ? WHERE `cluster_id` = ?"); } @@ -3140,7 +3132,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.database.getConnection().prepareStatement( "DELETE FROM `" + SQLManager.this.prefix + "cluster_invited` WHERE `cluster_id` = ? AND `user_uuid` = ?"); } @@ -3158,7 +3150,7 @@ public class SQLManager implements AbstractDB { @Override public PreparedStatement get() throws SQLException { - return SQLManager.this.connection.prepareStatement( + return SQLManager.this.getConnection().prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "cluster_invited` (`cluster_id`, `user_uuid`) VALUES(?,?)"); } @@ -3167,12 +3159,11 @@ public class SQLManager implements AbstractDB { @Override public boolean deleteTables() { - try (Statement stmt = this.connection.createStatement(); - PreparedStatement statement = this.connection + try (Statement stmt = this.getConnection().createStatement(); + PreparedStatement statement = this.getConnection() .prepareStatement("DROP TABLE `" + this.prefix + "plot`")) { close(); this.closed = false; - SQLManager.this.connection = this.database.forceConnection(); stmt.addBatch("DROP TABLE `" + this.prefix + "cluster_invited`"); stmt.addBatch("DROP TABLE `" + this.prefix + "cluster_helpers`"); stmt.addBatch("DROP TABLE `" + this.prefix + "cluster`"); @@ -3185,7 +3176,7 @@ public class SQLManager implements AbstractDB { stmt.executeBatch(); stmt.clearBatch(); statement.executeUpdate(); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } @@ -3207,8 +3198,8 @@ public class SQLManager implements AbstractDB { } } try { - if (this.connection.getAutoCommit()) { - this.connection.setAutoCommit(false); + if (this.getConnection().getAutoCommit()) { + this.getConnection().setAutoCommit(false); } } catch (SQLException e) { e.printStackTrace(); @@ -3327,7 +3318,7 @@ public class SQLManager implements AbstractDB { ) { addGlobalTask(() -> { if (min == null) { - try (PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + try (PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot` SET `world` = ? WHERE `world` = ?")) { stmt.setString(1, newWorld); @@ -3336,7 +3327,7 @@ public class SQLManager implements AbstractDB { } catch (SQLException e) { e.printStackTrace(); } - try (PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + try (PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "cluster` SET `world` = ? WHERE `world` = ?")) { stmt.setString(1, newWorld); @@ -3346,7 +3337,7 @@ public class SQLManager implements AbstractDB { e.printStackTrace(); } } else { - try (PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + try (PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) { stmt.setString(1, newWorld); @@ -3359,7 +3350,7 @@ public class SQLManager implements AbstractDB { } catch (SQLException e) { e.printStackTrace(); } - try (PreparedStatement stmt = SQLManager.this.connection.prepareStatement( + try (PreparedStatement stmt = SQLManager.this.getConnection().prepareStatement( "UPDATE `" + SQLManager.this.prefix + "cluster` SET `world` = ? WHERE `world` = ? AND `pos1_x` <= ? AND `pos1_z` <= ? AND `pos2_x` >= ? AND `pos2_z` >= ?")) { stmt.setString(1, newWorld); @@ -3379,7 +3370,7 @@ public class SQLManager implements AbstractDB { @Override public void replaceUUID(final UUID old, final UUID now) { addGlobalTask(() -> { - try (Statement stmt = SQLManager.this.connection.createStatement()) { + try (Statement stmt = SQLManager.this.getConnection().createStatement()) { stmt.executeUpdate( "UPDATE `" + SQLManager.this.prefix + "cluster` SET `owner` = '" + now .toString() + "' WHERE `owner` = '" + old.toString() + '\''); @@ -3408,7 +3399,7 @@ public class SQLManager implements AbstractDB { public void close() { try { this.closed = true; - this.connection.close(); + this.getConnection().close(); } catch (SQLException e) { e.printStackTrace(); } From 0d6bcc4c6abfe148b6a68a0981585a091740ba68 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Tue, 13 Jun 2023 21:09:44 +0200 Subject: [PATCH 4/7] Cleanup java docs --- Core/src/main/java/com/plotsquared/core/database/Database.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/database/Database.java b/Core/src/main/java/com/plotsquared/core/database/Database.java index 4beee9256..e27cdf2ea 100644 --- a/Core/src/main/java/com/plotsquared/core/database/Database.java +++ b/Core/src/main/java/com/plotsquared/core/database/Database.java @@ -53,7 +53,6 @@ public abstract class Database { * @param query Query to be run * @return the results of the query * @throws SQLException If the query cannot be executed - * @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()} */ public abstract ResultSet querySQL(String query) throws SQLException, ClassNotFoundException; @@ -65,7 +64,6 @@ public abstract class Database { * @param query Query to be run * @return Result Code, see {@link Statement#executeUpdate(String)} * @throws SQLException If the query cannot be executed - * @throws ClassNotFoundException If the driver cannot be found; see {@link #openConnection()} */ public abstract int updateSQL(String query) throws SQLException, ClassNotFoundException; From 93267997b8d12cacab0669730dbac26ef7df3bc6 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Tue, 13 Jun 2023 21:13:00 +0200 Subject: [PATCH 5/7] Remove unsued imports --- Core/src/main/java/com/plotsquared/core/database/MySQL.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/database/MySQL.java b/Core/src/main/java/com/plotsquared/core/database/MySQL.java index 5b961dba3..dce8d2765 100644 --- a/Core/src/main/java/com/plotsquared/core/database/MySQL.java +++ b/Core/src/main/java/com/plotsquared/core/database/MySQL.java @@ -19,12 +19,10 @@ package com.plotsquared.core.database; import com.plotsquared.core.configuration.Storage; -import com.plotsquared.core.util.StringMan; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; From 1f85e68bd1193635fc4b0cf72ed4ded9c1ec5c40 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sun, 26 Nov 2023 22:38:46 +0100 Subject: [PATCH 6/7] Use version catalog --- Core/build.gradle.kts | 2 +- gradle/libs.versions.toml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/build.gradle.kts b/Core/build.gradle.kts index b8914c6eb..ba3d0d716 100644 --- a/Core/build.gradle.kts +++ b/Core/build.gradle.kts @@ -46,7 +46,7 @@ dependencies { api(libs.informativeAnnotations) // Database - implementation("com.zaxxer:HikariCP:5.0.1") + implementation(libs.hikaricp) } tasks.processResources { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9f77d4d61..e1350e17d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,7 @@ paperlib = "1.0.8" informative-annotations = "1.4" vault = "1.7.1" serverlib = "2.3.4" +hikaricp = "5.0.1" # Gradle plugins shadow = "8.1.1" @@ -77,6 +78,7 @@ informativeAnnotations = { group = "com.intellectualsites.informative-annotation paperlib = { group = "io.papermc", name = "paperlib", version.ref = "paperlib" } vault = { group = "com.github.MilkBowl", name = "VaultAPI", version.ref = "vault" } serverlib = { group = "dev.notmyfault.serverlib", name = "ServerLib", version.ref = "serverlib" } +hikaricp = { group = "com.zaxxer", name = "HikariCP", version.ref = "hikaricp"} [plugins] shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } From 2b34e1007a159d6f85bc49c0fe5da33490fa0699 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sun, 26 Nov 2023 22:43:09 +0100 Subject: [PATCH 7/7] Remove unused code of line that creates a compile issue --- Core/src/main/java/com/plotsquared/core/database/SQLManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index ebd8dfe99..c8bab327e 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -154,7 +154,6 @@ public class SQLManager implements AbstractDB { this.plotListener = plotListener; this.worldConfiguration = worldConfiguration; this.database = database; - this.connection = database.openConnection(); final DatabaseMetaData databaseMetaData = this.connection.getMetaData(); this.supportsGetGeneratedKeys = databaseMetaData.supportsGetGeneratedKeys(); this.mySQL = database instanceof MySQL;