diff --git a/Plan/common/src/main/java/com/djrapitops/plan/api/CommonAPI.java b/Plan/common/src/main/java/com/djrapitops/plan/api/CommonAPI.java index 465a5466a..ab5c52aef 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/api/CommonAPI.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/api/CommonAPI.java @@ -16,7 +16,11 @@ */ package com.djrapitops.plan.api; +import com.djrapitops.plan.api.data.PlayerContainer; +import com.djrapitops.plan.api.data.ServerContainer; import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.db.access.Query; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.utilities.uuid.UUIDUtility; import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.error.ErrorHandler; @@ -66,4 +70,15 @@ public abstract class CommonAPI implements PlanAPI { } } + protected abstract T queryDB(Query query); + + @Override + public PlayerContainer fetchPlayerContainer(UUID uuid) { + return new PlayerContainer(queryDB(ContainerFetchQueries.fetchPlayerContainer(uuid))); + } + + @Override + public ServerContainer fetchServerContainer(UUID serverUUID) { + return new ServerContainer(queryDB(ContainerFetchQueries.fetchServerContainer(serverUUID))); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/api/PlanAPI.java b/Plan/common/src/main/java/com/djrapitops/plan/api/PlanAPI.java index dac198a73..04a9b9534 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/api/PlanAPI.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/api/PlanAPI.java @@ -79,9 +79,7 @@ public interface PlanAPI { * @param uuid UUID of the player. * @return a {@link PlayerContainer}. */ - default PlayerContainer fetchPlayerContainer(UUID uuid) { - return new PlayerContainer(fetchFromPlanDB().getPlayerContainer(uuid)); - } + PlayerContainer fetchPlayerContainer(UUID uuid); /** * Fetch a ServerContainer from the database. @@ -91,9 +89,7 @@ public interface PlanAPI { * @param serverUUID UUID of the server. * @return a {@link ServerContainer}. */ - default ServerContainer fetchServerContainer(UUID serverUUID) { - return new ServerContainer(fetchFromPlanDB().getServerContainer(serverUUID)); - } + ServerContainer fetchServerContainer(UUID serverUUID); /** * Fetch server UUIDs. diff --git a/Plan/common/src/main/java/com/djrapitops/plan/api/ProxyAPI.java b/Plan/common/src/main/java/com/djrapitops/plan/api/ProxyAPI.java index 1f9fa9556..76470e21b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/api/ProxyAPI.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/api/ProxyAPI.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.db.access.Query; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.utilities.uuid.UUIDUtility; @@ -65,4 +66,9 @@ public class ProxyAPI extends CommonAPI { public FetchOperations fetchFromPlanDB() { return dbSystem.getDatabase().fetch(); } + + @Override + protected T queryDB(Query query) { + return dbSystem.getDatabase().query(query); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/api/ServerAPI.java b/Plan/common/src/main/java/com/djrapitops/plan/api/ServerAPI.java index 67f6f76d2..a1e7b81e3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/api/ServerAPI.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/api/ServerAPI.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.db.access.Query; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.utilities.uuid.UUIDUtility; @@ -64,4 +65,9 @@ public class ServerAPI extends CommonAPI { public FetchOperations fetchFromPlanDB() { return dbSystem.getDatabase().fetch(); } + + @Override + protected T queryDB(Query query) { + return dbSystem.getDatabase().query(query); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java index b94d54977..6cc07cf1a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java @@ -24,6 +24,7 @@ import com.djrapitops.plan.data.store.mutators.ActivityIndex; import com.djrapitops.plan.data.store.mutators.GeoInfoMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.objects.DateHolder; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -113,7 +114,7 @@ public class QInspectCommand extends CommandNode { return; } - PlayerContainer container = dbSystem.getDatabase().fetch().getPlayerContainer(uuid); + PlayerContainer container = dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid)); if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) { sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_KNOWN)); return; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java index f0e747810..e47ac47fd 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/webserver/response/ResponseFactory.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.system.webserver.response; import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.WebUserAuthException; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.locale.Locale; @@ -104,11 +105,11 @@ public class ResponseFactory { } public RawDataResponse rawPlayerPageResponse(UUID uuid) { - return new RawPlayerDataResponse(dbSystem.getDatabase().fetch().getPlayerContainer(uuid)); + return new RawPlayerDataResponse(dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid))); } public RawDataResponse rawServerPageResponse(UUID serverUUID) { - return new RawServerDataResponse(dbSystem.getDatabase().fetch().getServerContainer(serverUUID)); + return new RawServerDataResponse(dbSystem.getDatabase().query(ContainerFetchQueries.fetchServerContainer(serverUUID))); } public Response javaScriptResponse(String fileName) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java index d929e4c04..cd0da2a8c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PageFactory.java @@ -20,8 +20,9 @@ import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.store.containers.AnalysisContainer; import com.djrapitops.plan.data.store.containers.NetworkContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer; +import com.djrapitops.plan.db.Database; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.system.database.DBSystem; -import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -124,14 +125,14 @@ public class PageFactory { public AnalysisPage analysisPage(UUID serverUUID) { AnalysisContainer analysisContainer = analysisContainerFactory.get() - .forServerContainer(dbSystem.get().getDatabase().fetch().getServerContainer(serverUUID)); + .forServerContainer(dbSystem.get().getDatabase().query(ContainerFetchQueries.fetchServerContainer(serverUUID))); return new AnalysisPage(analysisContainer, versionCheckSystem.get(), fileSystem.get(), formatters.get().decimals(), timings.get()); } public InspectPage inspectPage(UUID uuid) { - FetchOperations fetch = dbSystem.get().getDatabase().fetch(); - PlayerContainer player = fetch.getPlayerContainer(uuid); - Map serverNames = fetch.getServerNames(); + Database db = dbSystem.get().getDatabase(); + PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(uuid)); + Map serverNames = db.fetch().getServerNames(); return new InspectPage( player, serverNames, versionCheckSystem.get(), @@ -146,7 +147,8 @@ public class PageFactory { } public NetworkPage networkPage() { - NetworkContainer networkContainer = dbSystem.get().getDatabase().fetch().getNetworkContainer(); // Not cached, big. + NetworkContainer networkContainer = dbSystem.get().getDatabase() + .query(ContainerFetchQueries.fetchNetworkContainer()); // Not cached, big. return new NetworkPage(networkContainer, analysisPluginsTabContentCreator.get(), versionCheckSystem.get(), fileSystem.get(), serverInfo.get().getServerProperties()); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PlayersPage.java b/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PlayersPage.java index 45d442b47..acf2c5088 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PlayersPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/utilities/html/pages/PlayersPage.java @@ -19,6 +19,7 @@ package com.djrapitops.plan.utilities.html.pages; import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.db.Database; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -81,7 +82,7 @@ public class PlayersPage implements Page { } timings.start("Players page players table parsing"); - List playerContainers = database.fetch().getAllPlayerContainers(); + List playerContainers = database.query(ContainerFetchQueries.fetchAllPlayerContainers()); placeholderReplacer.put("playersTable", tables.playerTableForPlayersPage(playerContainers).parseHtml()); timings.end("Pages", "Players page players table parsing"); 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 44e1dbe23..c5a6419b0 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 @@ -35,6 +35,7 @@ import com.djrapitops.plan.db.sql.queries.AggregateQueries; import com.djrapitops.plan.db.sql.queries.LargeFetchQueries; import com.djrapitops.plan.db.sql.queries.LargeStoreQueries; import com.djrapitops.plan.db.sql.queries.OptionalFetchQueries; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.db.sql.tables.*; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.database.DBSystem; @@ -826,7 +827,7 @@ public abstract class CommonDBTest { long start = System.nanoTime(); - PlayerContainer container = db.fetch().getPlayerContainer(playerUUID); + PlayerContainer container = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID)); assertTrue(container.supports(PlayerKeys.UUID)); assertTrue(container.supports(PlayerKeys.REGISTERED)); @@ -879,7 +880,7 @@ public abstract class CommonDBTest { public void playerContainerSupportsAllPlayerKeys() throws NoSuchAlgorithmException, IllegalAccessException { saveAllData(db); - PlayerContainer playerContainer = db.fetch().getPlayerContainer(playerUUID); + PlayerContainer playerContainer = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID)); // Active sessions are added after fetching playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomSession()); @@ -898,7 +899,7 @@ public abstract class CommonDBTest { public void serverContainerSupportsAllServerKeys() throws NoSuchAlgorithmException, IllegalAccessException { saveAllData(db); - ServerContainer serverContainer = db.fetch().getServerContainer(serverUUID); + ServerContainer serverContainer = db.query(ContainerFetchQueries.fetchServerContainer(serverUUID)); List unsupported = new ArrayList<>(); List keys = FieldFetcher.getPublicStaticFields(ServerKeys.class, Key.class); @@ -916,7 +917,7 @@ public abstract class CommonDBTest { serverContainerSupportsAllServerKeys(); AnalysisContainer.Factory factory = constructAnalysisContainerFactory(); AnalysisContainer analysisContainer = factory.forServerContainer( - db.fetch().getServerContainer(serverUUID) + db.query(ContainerFetchQueries.fetchServerContainer(serverUUID)) ); Collection unsupported = new ArrayList<>(); List keys = FieldFetcher.getPublicStaticFields(AnalysisKeys.class, Key.class); @@ -948,7 +949,7 @@ public abstract class CommonDBTest { @Test public void networkContainerSupportsAllNetworkKeys() throws IllegalAccessException, NoSuchAlgorithmException { serverContainerSupportsAllServerKeys(); - NetworkContainer networkContainer = db.fetch().getNetworkContainer(); + NetworkContainer networkContainer = db.query(ContainerFetchQueries.fetchNetworkContainer()); List unsupported = new ArrayList<>(); List keys = FieldFetcher.getPublicStaticFields(NetworkKeys.class, Key.class); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchH2RegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchH2RegressionTest.java index 1c74abe17..e9416b4ba 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchH2RegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchH2RegressionTest.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.Transaction; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -128,7 +129,7 @@ public class DBPatchH2RegressionTest extends DBPatchRegressionTest { assertPatchesHaveBeenApplied(underTest); // Make sure that a fetch works. - ServerContainer server = underTest.fetch().getServerContainer(TestConstants.SERVER_UUID); + ServerContainer server = underTest.query(ContainerFetchQueries.fetchServerContainer(TestConstants.SERVER_UUID)); OptionalAssert.equals(1, server.getValue(ServerKeys.PLAYER_KILL_COUNT)); // Make sure no foreign key checks fail on removal diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchMySQLRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchMySQLRegressionTest.java index 64c99889f..6626fd41b 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchMySQLRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchMySQLRegressionTest.java @@ -23,6 +23,7 @@ import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.Transaction; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.locale.Locale; @@ -156,7 +157,7 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest { assertPatchesHaveBeenApplied(underTest); // Make sure that a fetch works. - ServerContainer server = underTest.fetch().getServerContainer(TestConstants.SERVER_UUID); + ServerContainer server = underTest.query(ContainerFetchQueries.fetchServerContainer(TestConstants.SERVER_UUID)); OptionalAssert.equals(1, server.getValue(ServerKeys.PLAYER_KILL_COUNT)); // Make sure no foreign key checks fail on removal diff --git a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchSQLiteRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchSQLiteRegressionTest.java index 750196c73..4761e9007 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchSQLiteRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/db/DBPatchSQLiteRegressionTest.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.Transaction; +import com.djrapitops.plan.db.sql.queries.containers.ContainerFetchQueries; import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plugin.logging.L; @@ -121,7 +122,7 @@ public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest { assertPatchesHaveBeenApplied(underTest); // Make sure that a fetch works. - ServerContainer server = underTest.fetch().getServerContainer(TestConstants.SERVER_UUID); + ServerContainer server = underTest.query(ContainerFetchQueries.fetchServerContainer(TestConstants.SERVER_UUID)); OptionalAssert.equals(1, server.getValue(ServerKeys.PLAYER_KILL_COUNT)); // Make sure no foreign key checks fail on removal