From 06526d1e9656dc7ec7e8976f9db7ee6b9db4c997 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 25 Nov 2014 21:45:34 -0800 Subject: [PATCH] Fixed sql bug in FriendRepository move/cleanup in RepoBase --- .../src/mineplex/core/database/RepositoryBase.java | 9 ++++++--- .../src/mineplex/core/friend/data/FriendRepository.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index 9b140e670..3c105d20c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -84,13 +84,14 @@ public abstract class RepositoryBase implements Listener protected int executeUpdate(String query, ResultSetCallable callable, Column...columns) { - TimingManager.start(getClass().getName()); PreparedStatement preparedStatement = null; int affectedRows = 0; try { + TimingManager.start(getClass().getName()); + if (_connection == null || !_connection.isValid(1)) _connection = DriverManager.getConnection(_connectionString, _userName, _password); @@ -132,12 +133,12 @@ public abstract class RepositoryBase implements Listener protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column...columns) { - TimingManager.start(getClass().getName()); - ResultSet resultSet = null; try { + TimingManager.start(getClass().getName()); + for (int i=0; i < columns.length; i++) { columns[i].setValue(statement, i+1); @@ -211,7 +212,9 @@ public abstract class RepositoryBase implements Listener columns[i].setValue(preparedStatement, i+1); } + TimingManager.start(getClass().getName()); affectedRows = preparedStatement.executeUpdate(); + TimingManager.stop(getClass().getName()); } catch (Exception exception) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java index 6dff02e8b..fccf0db30 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java @@ -15,7 +15,7 @@ import mineplex.core.friend.FriendStatusType; public class FriendRepository extends RepositoryBase { private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));"; - private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = ?;"; + private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN "; private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget, status) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, ? FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;"; private static String UPDATE_MUTUAL_RECORD = "UPDATE accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid SET aF.status = ? WHERE tA.name = ? AND fA.name = ?;"; private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid WHERE fA.name = ? AND tA.name = ?;";