Fixed sql bug in FriendRepository

move/cleanup in RepoBase
This commit is contained in:
Jonathan Williams 2014-11-25 21:45:34 -08:00
parent 15d129d184
commit 06526d1e96
2 changed files with 7 additions and 4 deletions

View File

@ -84,13 +84,14 @@ public abstract class RepositoryBase implements Listener
protected int executeUpdate(String query, ResultSetCallable callable, Column<?>...columns) protected int executeUpdate(String query, ResultSetCallable callable, Column<?>...columns)
{ {
TimingManager.start(getClass().getName());
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
int affectedRows = 0; int affectedRows = 0;
try try
{ {
TimingManager.start(getClass().getName());
if (_connection == null || !_connection.isValid(1)) if (_connection == null || !_connection.isValid(1))
_connection = DriverManager.getConnection(_connectionString, _userName, _password); _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) protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
{ {
TimingManager.start(getClass().getName());
ResultSet resultSet = null; ResultSet resultSet = null;
try try
{ {
TimingManager.start(getClass().getName());
for (int i=0; i < columns.length; i++) for (int i=0; i < columns.length; i++)
{ {
columns[i].setValue(statement, i+1); columns[i].setValue(statement, i+1);
@ -211,7 +212,9 @@ public abstract class RepositoryBase implements Listener
columns[i].setValue(preparedStatement, i+1); columns[i].setValue(preparedStatement, i+1);
} }
TimingManager.start(getClass().getName());
affectedRows = preparedStatement.executeUpdate(); affectedRows = preparedStatement.executeUpdate();
TimingManager.stop(getClass().getName());
} }
catch (Exception exception) catch (Exception exception)
{ {

View File

@ -15,7 +15,7 @@ import mineplex.core.friend.FriendStatusType;
public class FriendRepository extends RepositoryBase 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 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 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 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 = ?;"; 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 = ?;";