Jon is actually OCD
This commit is contained in:
parent
1e93ad0b1e
commit
3023c64c35
@ -49,24 +49,30 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
UtilServer.runAsync(() ->
|
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 accountId : stats.keySet())
|
||||||
{
|
{
|
||||||
for (Integer statId : stats.get(accountId).keySet())
|
for (Integer statId : stats.get(accountId).keySet())
|
||||||
{
|
{
|
||||||
s.setLong(1, stats.get(accountId).get(statId));
|
updateStat.setLong(1, stats.get(accountId).get(statId));
|
||||||
s.setInt(2, accountId);
|
updateStat.setInt(2, accountId);
|
||||||
s.setInt(3, statId);
|
updateStat.setInt(3, statId);
|
||||||
s.addBatch();
|
updateStat.addBatch();
|
||||||
u.setLong(1, stats.get(accountId).get(statId));
|
updateAllStats.setLong(1, stats.get(accountId).get(statId));
|
||||||
u.setInt(2, accountId);
|
updateAllStats.setInt(2, accountId);
|
||||||
u.setInt(3, statId);
|
updateAllStats.setInt(3, statId);
|
||||||
u.addBatch();
|
updateAllStats.addBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[] rowsAffected1 = s.executeBatch();
|
int[] rowsAffected1 = updateStat.executeBatch();
|
||||||
int[] rowsAffected2 = u.executeBatch();
|
int[] rowsAffected2 = updateAllStats.executeBatch();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Integer accountId : stats.keySet())
|
for (Integer accountId : stats.keySet())
|
||||||
{
|
{
|
||||||
@ -74,23 +80,23 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
if (rowsAffected1[i] < 1)
|
if (rowsAffected1[i] < 1)
|
||||||
{
|
{
|
||||||
v.setInt(1, accountId);
|
insertStat.setInt(1, accountId);
|
||||||
v.setInt(2, statId);
|
insertStat.setInt(2, statId);
|
||||||
v.setLong(3, stats.get(accountId).get(statId));
|
insertStat.setLong(3, stats.get(accountId).get(statId));
|
||||||
v.addBatch();
|
insertStat.addBatch();
|
||||||
}
|
}
|
||||||
if (rowsAffected2[i] < 1)
|
if (rowsAffected2[i] < 1)
|
||||||
{
|
{
|
||||||
w.setInt(1, accountId);
|
insertAllStats.setInt(1, accountId);
|
||||||
w.setInt(2, statId);
|
insertAllStats.setInt(2, statId);
|
||||||
w.setLong(3, stats.get(accountId).get(statId));
|
insertAllStats.setLong(3, stats.get(accountId).get(statId));
|
||||||
w.addBatch();
|
insertAllStats.addBatch();
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.executeBatch();
|
insertStat.executeBatch();
|
||||||
w.executeBatch();
|
insertAllStats.executeBatch();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
@ -101,42 +107,48 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void insertStats(int accountId, Map<Integer, Long> stats)
|
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())
|
for (Integer statId : stats.keySet())
|
||||||
{
|
{
|
||||||
s.setLong(1, stats.get(statId));
|
updateStat.setLong(1, stats.get(statId));
|
||||||
s.setInt(2, accountId);
|
updateStat.setInt(2, accountId);
|
||||||
s.setInt(3, statId);
|
updateStat.setInt(3, statId);
|
||||||
s.addBatch();
|
updateStat.addBatch();
|
||||||
u.setLong(1, stats.get(statId));
|
updateAllStats.setLong(1, stats.get(statId));
|
||||||
u.setInt(2, accountId);
|
updateAllStats.setInt(2, accountId);
|
||||||
u.setInt(3, statId);
|
updateAllStats.setInt(3, statId);
|
||||||
u.addBatch();
|
updateAllStats.addBatch();
|
||||||
}
|
}
|
||||||
int[] rowsAffected1 = s.executeBatch();
|
int[] rowsAffected1 = updateStat.executeBatch();
|
||||||
int[] rowsAffected2 = u.executeBatch();
|
int[] rowsAffected2 = updateAllStats.executeBatch();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Integer statId : stats.keySet())
|
for (Integer statId : stats.keySet())
|
||||||
{
|
{
|
||||||
if (rowsAffected1[i] < 1)
|
if (rowsAffected1[i] < 1)
|
||||||
{
|
{
|
||||||
v.setInt(1, accountId);
|
insertStat.setInt(1, accountId);
|
||||||
v.setInt(2, statId);
|
insertStat.setInt(2, statId);
|
||||||
v.setLong(3, stats.get(statId));
|
insertStat.setLong(3, stats.get(statId));
|
||||||
v.addBatch();
|
insertStat.addBatch();
|
||||||
}
|
}
|
||||||
if (rowsAffected2[i] < 1)
|
if (rowsAffected2[i] < 1)
|
||||||
{
|
{
|
||||||
w.setInt(1, accountId);
|
insertAllStats.setInt(1, accountId);
|
||||||
w.setInt(2, statId);
|
insertAllStats.setInt(2, statId);
|
||||||
w.setLong(3, stats.get(statId));
|
insertAllStats.setLong(3, stats.get(statId));
|
||||||
w.addBatch();
|
insertAllStats.addBatch();
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
v.executeBatch();
|
insertStat.executeBatch();
|
||||||
w.executeBatch();
|
insertAllStats.executeBatch();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
@ -147,7 +159,10 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
|
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
|
||||||
{
|
{
|
||||||
Map<String, Integer> names = new LinkedHashMap<>();
|
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()));
|
s.execute(board.getType().getStatement(board.getStatIds(), board.getStart(), board.getSize()));
|
||||||
for (int i = 0; i < board.getStatIds().length; i++)
|
for (int i = 0; i < board.getStatIds().length; i++)
|
||||||
@ -193,7 +208,10 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
|
|
||||||
if (queryBuilder.length() > 0)
|
if (queryBuilder.length() > 0)
|
||||||
{
|
{
|
||||||
try (Connection c = getConnection(); Statement s = c.createStatement())
|
try (
|
||||||
|
Connection c = getConnection();
|
||||||
|
Statement s = c.createStatement();
|
||||||
|
)
|
||||||
{
|
{
|
||||||
s.execute(queryBuilder.toString());
|
s.execute(queryBuilder.toString());
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user