From 423d9c88a0bf79e9121d20b4011dcc9e85fdc416 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 5 Mar 2019 13:36:29 +0200 Subject: [PATCH] [#943] Removed unnecessary Server UUID column from some queries --- .../access/queries/objects/WorldTimesQueries.java | 13 ++++++++----- .../java/com/djrapitops/plan/db/CommonDBTest.java | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java index 7f80fc076..1243ba289 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java @@ -40,15 +40,14 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.*; public class WorldTimesQueries { private static String worldColumn = "world"; + private static final String SELECT_WORLD_TIMES_JOIN_WORLD_NAME = WorldTable.TABLE_NAME + "." + WorldTable.NAME + " as " + worldColumn + + FROM + WorldTimesTable.TABLE_NAME + + INNER_JOIN + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + "." + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID; private static final String SELECT_WORLD_TIMES_STATEMENT_START = SELECT + "SUM(" + WorldTimesTable.SURVIVAL + ") as survival, " + "SUM(" + WorldTimesTable.CREATIVE + ") as creative, " + "SUM(" + WorldTimesTable.ADVENTURE + ") as adventure, " + - "SUM(" + WorldTimesTable.SPECTATOR + ") as spectator, " + - WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + ", " + - WorldTable.TABLE_NAME + "." + WorldTable.NAME + " as " + worldColumn + - FROM + WorldTimesTable.TABLE_NAME + - " INNER JOIN " + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + "." + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID; + "SUM(" + WorldTimesTable.SPECTATOR + ") as spectator, "; private WorldTimesQueries() { /* Static method class */ @@ -62,6 +61,7 @@ public class WorldTimesQueries { */ public static Query fetchServerTotalWorldTimes(UUID serverUUID) { String sql = SELECT_WORLD_TIMES_STATEMENT_START + + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + "=?" + GROUP_BY + worldColumn; @@ -96,6 +96,7 @@ public class WorldTimesQueries { */ public static Query fetchPlayerTotalWorldTimes(UUID playerUUID) { String sql = SELECT_WORLD_TIMES_STATEMENT_START + + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.USER_UUID + "=?" + GROUP_BY + worldColumn; @@ -130,6 +131,8 @@ public class WorldTimesQueries { */ public static Query> fetchPlayerWorldTimesOnServers(UUID playerUUID) { String sql = SELECT_WORLD_TIMES_STATEMENT_START + + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + ", " + + SELECT_WORLD_TIMES_JOIN_WORLD_NAME + WHERE + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.USER_UUID + "=?" + GROUP_BY + worldColumn + ", " + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID; diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java index d8a5c6c8c..0bb1e3b0f 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/CommonDBTest.java @@ -711,7 +711,7 @@ public abstract class CommonDBTest { } @Test - public void testSaveSessionsWorldTimes() { + public void worldTimesAreSavedWithSession() { saveTwoWorlds(); saveUserOne(); @@ -733,21 +733,21 @@ public abstract class CommonDBTest { } @Test - public void testGetUserWorldTimes() { - testSaveSessionsWorldTimes(); + public void playersWorldTimesMatchTotal() { + worldTimesAreSavedWithSession(); WorldTimes worldTimesOfUser = db.query(WorldTimesQueries.fetchPlayerTotalWorldTimes(playerUUID)); assertEquals(createWorldTimes(), worldTimesOfUser); } @Test - public void testGetServerWorldTimes() { - testSaveSessionsWorldTimes(); + public void serverWorldTimesMatchTotal() { + worldTimesAreSavedWithSession(); WorldTimes worldTimesOfServer = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID)); assertEquals(createWorldTimes(), worldTimesOfServer); } @Test - public void testGetServerWorldTimesNoSessions() { + public void emptyServerWorldTimesIsEmpty() { WorldTimes worldTimesOfServer = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID)); assertEquals(new WorldTimes(new HashMap<>()), worldTimesOfServer); }