Replace usages of FetchOperations that fetch containers with the queries

This commit is contained in:
Rsl1122 2019-01-26 12:35:47 +02:00
parent 8fe712ccfe
commit 9b7e12ccfb
12 changed files with 56 additions and 24 deletions

View File

@ -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> T queryDB(Query<T> 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)));
}
}

View File

@ -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.

View File

@ -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> T queryDB(Query<T> query) {
return dbSystem.getDatabase().query(query);
}
}

View File

@ -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> T queryDB(Query<T> query) {
return dbSystem.getDatabase().query(query);
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -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<UUID, String> serverNames = fetch.getServerNames();
Database db = dbSystem.get().getDatabase();
PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(uuid));
Map<UUID, String> 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());

View File

@ -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<PlayerContainer> playerContainers = database.fetch().getAllPlayerContainers();
List<PlayerContainer> playerContainers = database.query(ContainerFetchQueries.fetchAllPlayerContainers());
placeholderReplacer.put("playersTable", tables.playerTableForPlayersPage(playerContainers).parseHtml());
timings.end("Pages", "Players page players table parsing");

View File

@ -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<String> unsupported = new ArrayList<>();
List<Key> 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<String> unsupported = new ArrayList<>();
List<Key> 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<String> unsupported = new ArrayList<>();
List<Key> keys = FieldFetcher.getPublicStaticFields(NetworkKeys.class, Key.class);

View File

@ -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

View File

@ -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

View File

@ -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