From 7aa6191a2756044426e8e1757616401590024773 Mon Sep 17 00:00:00 2001 From: Vankka Date: Sun, 25 Jun 2023 21:13:01 +0300 Subject: [PATCH] Move linked_accounts table name to constant, fixes mysql --- .../common/storage/impl/sql/SQLStorage.java | 12 +++++++----- .../common/storage/impl/sql/file/H2Storage.java | 2 +- .../common/storage/impl/sql/hikari/MySQLStorage.java | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java index 3c1eee7d..1402d627 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java @@ -31,6 +31,8 @@ import java.util.UUID; public abstract class SQLStorage implements Storage { + protected static final String LINKED_ACCOUNTS_TABLE_NAME = "linked_accounts"; + protected final DiscordSRV discordSRV; public SQLStorage(DiscordSRV discordSRV) { @@ -83,7 +85,7 @@ public abstract class SQLStorage implements Storage { @Override public @Nullable Long getUserId(@NotNull UUID player) { return useConnection(connection -> { - try (PreparedStatement statement = connection.prepareStatement("select USER_ID from " + tablePrefix() + "LINKED_ACCOUNTS where PLAYER_UUID = ?;")) { + try (PreparedStatement statement = connection.prepareStatement("select USER_ID from " + tablePrefix() + LINKED_ACCOUNTS_TABLE_NAME + " where PLAYER_UUID = ?;")) { statement.setString(1, player.toString()); try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { @@ -98,7 +100,7 @@ public abstract class SQLStorage implements Storage { @Override public @Nullable UUID getPlayerUUID(long userId) { return useConnection(connection -> { - try (PreparedStatement statement = connection.prepareStatement("select PLAYER_UUID from " + tablePrefix() + "LINKED_ACCOUNTS where USER_ID = ?;")) { + try (PreparedStatement statement = connection.prepareStatement("select PLAYER_UUID from " + tablePrefix() + LINKED_ACCOUNTS_TABLE_NAME + " where USER_ID = ?;")) { statement.setLong(1, userId); try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { @@ -117,7 +119,7 @@ public abstract class SQLStorage implements Storage { @Override public void createLink(@NotNull UUID player, long userId) { useConnection(connection -> { - try (PreparedStatement statement = connection.prepareStatement("insert into " + tablePrefix() + "LINKED_ACCOUNTS (PLAYER_UUID, USER_ID) values (?, ?);")) { + try (PreparedStatement statement = connection.prepareStatement("insert into " + tablePrefix() + LINKED_ACCOUNTS_TABLE_NAME + " (PLAYER_UUID, USER_ID) values (?, ?);")) { statement.setString(1, player.toString()); statement.setLong(2, userId); @@ -129,7 +131,7 @@ public abstract class SQLStorage implements Storage { @Override public void removeLink(@NotNull UUID player, long userId) { useConnection(connection -> { - try (PreparedStatement statement = connection.prepareStatement("delete " + tablePrefix() + "LINKED_ACCOUNTS where PLAYER_UUID = ?;")) { + try (PreparedStatement statement = connection.prepareStatement("delete " + tablePrefix() + LINKED_ACCOUNTS_TABLE_NAME + " where PLAYER_UUID = ?;")) { statement.setString(1, player.toString()); exceptEffectedRows(statement.executeUpdate(), 1); } @@ -140,7 +142,7 @@ public abstract class SQLStorage implements Storage { public int getLinkedAccountCount() { return useConnection(connection -> { try (Statement statement = connection.createStatement()) { - try (ResultSet resultSet = statement.executeQuery("select count(*) from " + tablePrefix() + "LINKED_ACCOUNTS;")) { + try (ResultSet resultSet = statement.executeQuery("select count(*) from " + tablePrefix() + LINKED_ACCOUNTS_TABLE_NAME + ";")) { if (resultSet.next()) { return resultSet.getInt(1); } diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java index 7faf0407..721259ac 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java @@ -102,7 +102,7 @@ public class H2Storage extends SQLStorage { public void createTables(Connection connection, String tablePrefix) throws SQLException { try (Statement statement = connection.createStatement()) { statement.execute( - "create table if not exists " + tablePrefix + "linked_accounts " + "create table if not exists " + tablePrefix + LINKED_ACCOUNTS_TABLE_NAME + " " + "(ID int not null auto_increment, " + "PLAYER_UUID varchar(36), " + "USER_ID bigint, " diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java index d9ba9bb2..93d49918 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java @@ -54,7 +54,7 @@ public class MySQLStorage extends HikariStorage { public void createTables(Connection connection, String tablePrefix) throws SQLException { try (Statement statement = connection.createStatement()) { statement.execute( - "create table if not exists " + tablePrefix + "linked_accounts " + "create table if not exists " + tablePrefix + LINKED_ACCOUNTS_TABLE_NAME + " " + "(ID int not null auto_increment, " + "PLAYER_UUID varchar(36), " + "USER_ID bigint, "