Jon is actually OCD

This commit is contained in:
AlexTheCoder 2017-05-11 21:34:41 -04:00
parent 1e93ad0b1e
commit 3023c64c35
1 changed files with 62 additions and 44 deletions

View File

@ -49,24 +49,30 @@ public class LeaderboardRepository extends RepositoryBase
{
UtilServer.runAsync(() ->
{
try (Connection c = getConnection(); PreparedStatement s = c.prepareStatement(UPDATE_STAT); PreparedStatement u = c.prepareStatement(UPDATE_STAT_ALL); PreparedStatement v = c.prepareStatement(INSERT_STAT); PreparedStatement w = c.prepareStatement(INSERT_STAT_ALL))
try (
Connection c = getConnection();
PreparedStatement updateStat = c.prepareStatement(UPDATE_STAT);
PreparedStatement updateAllStats = c.prepareStatement(UPDATE_STAT_ALL);
PreparedStatement insertStat = c.prepareStatement(INSERT_STAT);
PreparedStatement insertAllStats = c.prepareStatement(INSERT_STAT_ALL);
)
{
for (Integer accountId : stats.keySet())
{
for (Integer statId : stats.get(accountId).keySet())
{
s.setLong(1, stats.get(accountId).get(statId));
s.setInt(2, accountId);
s.setInt(3, statId);
s.addBatch();
u.setLong(1, stats.get(accountId).get(statId));
u.setInt(2, accountId);
u.setInt(3, statId);
u.addBatch();
updateStat.setLong(1, stats.get(accountId).get(statId));
updateStat.setInt(2, accountId);
updateStat.setInt(3, statId);
updateStat.addBatch();
updateAllStats.setLong(1, stats.get(accountId).get(statId));
updateAllStats.setInt(2, accountId);
updateAllStats.setInt(3, statId);
updateAllStats.addBatch();
}
}
int[] rowsAffected1 = s.executeBatch();
int[] rowsAffected2 = u.executeBatch();
int[] rowsAffected1 = updateStat.executeBatch();
int[] rowsAffected2 = updateAllStats.executeBatch();
int i = 0;
for (Integer accountId : stats.keySet())
{
@ -74,23 +80,23 @@ public class LeaderboardRepository extends RepositoryBase
{
if (rowsAffected1[i] < 1)
{
v.setInt(1, accountId);
v.setInt(2, statId);
v.setLong(3, stats.get(accountId).get(statId));
v.addBatch();
insertStat.setInt(1, accountId);
insertStat.setInt(2, statId);
insertStat.setLong(3, stats.get(accountId).get(statId));
insertStat.addBatch();
}
if (rowsAffected2[i] < 1)
{
w.setInt(1, accountId);
w.setInt(2, statId);
w.setLong(3, stats.get(accountId).get(statId));
w.addBatch();
insertAllStats.setInt(1, accountId);
insertAllStats.setInt(2, statId);
insertAllStats.setLong(3, stats.get(accountId).get(statId));
insertAllStats.addBatch();
}
i++;
}
}
v.executeBatch();
w.executeBatch();
insertStat.executeBatch();
insertAllStats.executeBatch();
}
catch (SQLException e)
{
@ -101,42 +107,48 @@ public class LeaderboardRepository extends RepositoryBase
public void insertStats(int accountId, Map<Integer, Long> stats)
{
try (Connection c = getConnection(); PreparedStatement s = c.prepareStatement(UPDATE_STAT); PreparedStatement u = c.prepareStatement(UPDATE_STAT_ALL); PreparedStatement v = c.prepareStatement(INSERT_STAT); PreparedStatement w = c.prepareStatement(INSERT_STAT_ALL))
try (
Connection c = getConnection();
PreparedStatement updateStat = c.prepareStatement(UPDATE_STAT);
PreparedStatement updateAllStats = c.prepareStatement(UPDATE_STAT_ALL);
PreparedStatement insertStat = c.prepareStatement(INSERT_STAT);
PreparedStatement insertAllStats = c.prepareStatement(INSERT_STAT_ALL);
)
{
for (Integer statId : stats.keySet())
{
s.setLong(1, stats.get(statId));
s.setInt(2, accountId);
s.setInt(3, statId);
s.addBatch();
u.setLong(1, stats.get(statId));
u.setInt(2, accountId);
u.setInt(3, statId);
u.addBatch();
updateStat.setLong(1, stats.get(statId));
updateStat.setInt(2, accountId);
updateStat.setInt(3, statId);
updateStat.addBatch();
updateAllStats.setLong(1, stats.get(statId));
updateAllStats.setInt(2, accountId);
updateAllStats.setInt(3, statId);
updateAllStats.addBatch();
}
int[] rowsAffected1 = s.executeBatch();
int[] rowsAffected2 = u.executeBatch();
int[] rowsAffected1 = updateStat.executeBatch();
int[] rowsAffected2 = updateAllStats.executeBatch();
int i = 0;
for (Integer statId : stats.keySet())
{
if (rowsAffected1[i] < 1)
{
v.setInt(1, accountId);
v.setInt(2, statId);
v.setLong(3, stats.get(statId));
v.addBatch();
insertStat.setInt(1, accountId);
insertStat.setInt(2, statId);
insertStat.setLong(3, stats.get(statId));
insertStat.addBatch();
}
if (rowsAffected2[i] < 1)
{
w.setInt(1, accountId);
w.setInt(2, statId);
w.setLong(3, stats.get(statId));
w.addBatch();
insertAllStats.setInt(1, accountId);
insertAllStats.setInt(2, statId);
insertAllStats.setLong(3, stats.get(statId));
insertAllStats.addBatch();
}
i++;
}
v.executeBatch();
w.executeBatch();
insertStat.executeBatch();
insertAllStats.executeBatch();
}
catch (SQLException e)
{
@ -147,7 +159,10 @@ public class LeaderboardRepository extends RepositoryBase
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
{
Map<String, Integer> names = new LinkedHashMap<>();
try (Connection c = getConnection(); Statement s = c.createStatement())
try (
Connection c = getConnection();
Statement s = c.createStatement();
)
{
s.execute(board.getType().getStatement(board.getStatIds(), board.getStart(), board.getSize()));
for (int i = 0; i < board.getStatIds().length; i++)
@ -193,7 +208,10 @@ public class LeaderboardRepository extends RepositoryBase
if (queryBuilder.length() > 0)
{
try (Connection c = getConnection(); Statement s = c.createStatement())
try (
Connection c = getConnection();
Statement s = c.createStatement();
)
{
s.execute(queryBuilder.toString());
int index = 0;