diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/PlayerOnlineListener.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/PlayerOnlineListener.java index 9bf42705f..e45cc4720 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/gathering/listeners/bukkit/PlayerOnlineListener.java @@ -186,7 +186,7 @@ public class PlayerOnlineListener implements Listener { boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( - new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) + new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry) ); } @@ -197,7 +197,7 @@ public class PlayerOnlineListener implements Listener { session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName())); session.getExtraData().put(JoinAddress.class, new JoinAddress(getHostName)); sessionCache.cacheSession(playerUUID, session) - .map(SessionEndTransaction::new) + .map(StoreSessionTransaction::new) .ifPresent(database::executeTransaction); database.executeTransaction(new NicknameStoreTransaction( @@ -248,7 +248,7 @@ public class PlayerOnlineListener implements Listener { dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, player::isBanned)); sessionCache.endSession(playerUUID, time) - .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession))); + .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new StoreSessionTransaction(endedSession))); if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) { processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName)); diff --git a/Plan/bungeecord/src/main/java/com/djrapitops/plan/gathering/listeners/bungee/PlayerOnlineListener.java b/Plan/bungeecord/src/main/java/com/djrapitops/plan/gathering/listeners/bungee/PlayerOnlineListener.java index 59f25e3ef..d84f6e8e9 100644 --- a/Plan/bungeecord/src/main/java/com/djrapitops/plan/gathering/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/bungeecord/src/main/java/com/djrapitops/plan/gathering/listeners/bungee/PlayerOnlineListener.java @@ -31,8 +31,8 @@ import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.ExportSettings; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; -import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreGeoInfoTransaction; import com.djrapitops.plan.utilities.logging.ErrorContext; import com.djrapitops.plan.utilities.logging.ErrorLogger; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -113,7 +113,7 @@ public class PlayerOnlineListener implements Listener { boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( - new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) + new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry) ); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/modules/DataPipelineModule.java b/Plan/common/src/main/java/com/djrapitops/plan/modules/DataPipelineModule.java index 4655b60b4..1161e2520 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/modules/DataPipelineModule.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/modules/DataPipelineModule.java @@ -24,7 +24,7 @@ import com.djrapitops.plan.gathering.domain.event.JoinAddress; import com.djrapitops.plan.gathering.domain.event.MobKill; import com.djrapitops.plan.gathering.domain.event.PlayerJoin; import com.djrapitops.plan.gathering.domain.event.PlayerLeave; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import dagger.Module; import dagger.Provides; import dagger.multibindings.IntoSet; @@ -89,7 +89,7 @@ public class DataPipelineModule { DataService.Pipeline playerLeaveToSession(SessionCache sessionCache) { return service -> service .registerOptionalMapper(UUID.class, PlayerLeave.class, FinishedSession.class, sessionCache::endSession) - .registerDatabaseSink(UUID.class, FinishedSession.class, (playerUUID, session) -> new SessionEndTransaction(session)); + .registerDatabaseSink(UUID.class, FinishedSession.class, (playerUUID, session) -> new StoreSessionTransaction(session)); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/MySQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/MySQLDB.java index c58cf84db..dd452b265 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/MySQLDB.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/MySQLDB.java @@ -36,10 +36,7 @@ import net.playeranalytics.plugin.server.PluginLogger; import javax.inject.Inject; import javax.inject.Singleton; import java.io.IOException; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.SQLException; +import java.sql.*; import java.util.Enumeration; import java.util.List; import java.util.Objects; @@ -82,7 +79,7 @@ public class MySQLDB extends SQLDB { try { return files.getResourceFromJar("dependencies/mysqlDriver.txt").asLines(); } catch (IOException e) { - throw new RuntimeException("Failed to get MySQL dependency information", e); + throw new DBInitException("Failed to get MySQL dependency information", e); } } @@ -177,9 +174,16 @@ public class MySQLDB extends SQLDB { } } if (connection.getAutoCommit()) connection.setAutoCommit(false); + setTimezoneToUTC(connection); return connection; } + private void setTimezoneToUTC(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute("set time_zone = '+00:00'"); + } + } + @Override public void close() { super.close(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/PlayerFetchQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/PlayerFetchQueries.java index 6f6451e39..4add5e3cf 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/PlayerFetchQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/PlayerFetchQueries.java @@ -73,14 +73,19 @@ public class PlayerFetchQueries { * @return True if the player's BaseUser is found */ public static Query isPlayerRegistered(UUID playerUUID) { - String sql = SELECT + "COUNT(1) as c" + + String sql = SELECT + UsersTable.ID + FROM + UsersTable.TABLE_NAME + WHERE + UsersTable.USER_UUID + "=?"; - return new HasMoreThanZeroQueryStatement(sql) { + return new QueryStatement(sql) { @Override public void prepare(PreparedStatement statement) throws SQLException { statement.setString(1, playerUUID.toString()); } + + @Override + public Boolean processResults(ResultSet set) throws SQLException { + return set.next(); + } }; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PingStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PingStoreTransaction.java index f96dcbe94..79aefaa78 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PingStoreTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PingStoreTransaction.java @@ -21,6 +21,7 @@ import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.gathering.domain.Ping; import com.djrapitops.plan.identification.ServerUUID; import com.djrapitops.plan.storage.database.queries.DataStoreQueries; +import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries; import com.djrapitops.plan.storage.database.transactions.Transaction; import com.djrapitops.plan.utilities.Predicates; import com.djrapitops.plan.utilities.analysis.Median; @@ -49,20 +50,43 @@ public class PingStoreTransaction extends Transaction { @Override protected void performOperations() { Ping ping = calculateAggregatePing(); + + DBOpException userInsertError = null; + if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegistered(playerUUID)))) { + userInsertError = tryToRegisterUser(ping.getDate()); + } + try { execute(DataStoreQueries.storePing(playerUUID, serverUUID, ping)); } catch (DBOpException failed) { + if (userInsertError != null) failed.addSuppressed(userInsertError); if (failed.isUserIdConstraintViolation()) { - retry(ping); + retry(ping, failed); } else { throw failed; } } } - private void retry(Ping ping) { - executeOther(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, playerUUID.toString())); - execute(DataStoreQueries.storePing(playerUUID, serverUUID, ping)); + private void retry(Ping ping, DBOpException failed) { + DBOpException userInsertError = null; + try { + userInsertError = tryToRegisterUser(ping.getDate()); + execute(DataStoreQueries.storePing(playerUUID, serverUUID, ping)); + } catch (DBOpException failedAgain) { + if (userInsertError != null) failedAgain.addSuppressed(userInsertError); + failedAgain.addSuppressed(failed); + throw failedAgain; + } + } + + private DBOpException tryToRegisterUser(long date) { + try { + execute(DataStoreQueries.registerBaseUser(playerUUID, date, playerUUID.toString())); + return null; + } catch (DBOpException failedInsert) { + return failedInsert; + } } private Ping calculateAggregatePing() { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/GeoInfoStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreGeoInfoTransaction.java similarity index 69% rename from Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/GeoInfoStoreTransaction.java rename to Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreGeoInfoTransaction.java index e78aabe63..8aeeafdeb 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/GeoInfoStoreTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreGeoInfoTransaction.java @@ -19,6 +19,7 @@ package com.djrapitops.plan.storage.database.transactions.events; import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.gathering.domain.GeoInfo; import com.djrapitops.plan.storage.database.queries.DataStoreQueries; +import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries; import com.djrapitops.plan.storage.database.transactions.Transaction; import java.net.InetAddress; @@ -30,7 +31,7 @@ import java.util.function.UnaryOperator; * * @author AuroraLS3 */ -public class GeoInfoStoreTransaction extends Transaction { +public class StoreGeoInfoTransaction extends Transaction { private final UUID playerUUID; private String ip; @@ -39,14 +40,14 @@ public class GeoInfoStoreTransaction extends Transaction { private GeoInfo geoInfo; - public GeoInfoStoreTransaction(UUID playerUUID, String ip, long time, UnaryOperator geolocationFunction) { + public StoreGeoInfoTransaction(UUID playerUUID, String ip, long time, UnaryOperator geolocationFunction) { this.playerUUID = playerUUID; this.ip = ip; this.time = time; this.geolocationFunction = geolocationFunction; } - public GeoInfoStoreTransaction( + public StoreGeoInfoTransaction( UUID playerUUID, InetAddress ip, long time, @@ -58,7 +59,7 @@ public class GeoInfoStoreTransaction extends Transaction { this.geolocationFunction = geolocationFunction; } - public GeoInfoStoreTransaction(UUID playerUUID, GeoInfo geoInfo) { + public StoreGeoInfoTransaction(UUID playerUUID, GeoInfo geoInfo) { this.playerUUID = playerUUID; this.geoInfo = geoInfo; } @@ -73,19 +74,37 @@ public class GeoInfoStoreTransaction extends Transaction { protected void performOperations() { if (geoInfo == null) geoInfo = createGeoInfo(); if (geoInfo.getGeolocation() == null) return; // Don't save null geolocation. + + if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegistered(playerUUID)))) { + registerPlayer(); + } + try { execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo)); } catch (DBOpException failed) { if (failed.isUserIdConstraintViolation()) { - retry(); + retry(failed); } else { throw failed; } } } - private void retry() { - executeOther(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, playerUUID.toString())); - execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo)); + private void retry(DBOpException failed) { + try { + executeOther(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, playerUUID.toString())); + execute(DataStoreQueries.storeGeoInfo(playerUUID, geoInfo)); + } catch (DBOpException failedAgain) { + failedAgain.addSuppressed(failed); + throw failedAgain; + } + } + + private void registerPlayer() { + try { + execute(DataStoreQueries.registerBaseUser(playerUUID, geoInfo.getDate(), playerUUID.toString())); + } catch (DBOpException ignored) { + // Ignored. Likely that another transaction managed to insert first. + } } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/SessionEndTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreSessionTransaction.java similarity index 79% rename from Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/SessionEndTransaction.java rename to Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreSessionTransaction.java index 34c594c74..536ff61c1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/SessionEndTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreSessionTransaction.java @@ -21,6 +21,7 @@ import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.gathering.domain.FinishedSession; import com.djrapitops.plan.gathering.domain.event.JoinAddress; import com.djrapitops.plan.storage.database.queries.DataStoreQueries; +import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries; import com.djrapitops.plan.storage.database.transactions.Transaction; import java.util.UUID; @@ -30,16 +31,19 @@ import java.util.UUID; * * @author AuroraLS3 */ -public class SessionEndTransaction extends Transaction { +public class StoreSessionTransaction extends Transaction { private final FinishedSession session; - public SessionEndTransaction(FinishedSession session) { + public StoreSessionTransaction(FinishedSession session) { this.session = session; } @Override protected void performOperations() { + if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegistered(session.getPlayerUUID())))) { + registerPlayer(); + } try { storeSession(); } catch (DBOpException failed) { @@ -65,15 +69,23 @@ public class SessionEndTransaction extends Transaction { private void retry(DBOpException failed) { try { - UUID playerUUID = session.getPlayerUUID(); - String playerName = session.getExtraData(PlayerName.class) - .map(PlayerName::get) - .orElseGet(playerUUID::toString); - executeOther(new PlayerRegisterTransaction(playerUUID, session::getStart, playerName)); + registerPlayer(); storeSession(); } catch (DBOpException anotherFail) { anotherFail.addSuppressed(failed); throw anotherFail; } } + + private void registerPlayer() { + try { + UUID playerUUID = session.getPlayerUUID(); + String playerName = session.getExtraData(PlayerName.class) + .map(PlayerName::get) + .orElseGet(playerUUID::toString); + execute(DataStoreQueries.registerBaseUser(playerUUID, session.getStart(), playerName)); + } catch (DBOpException ignored) { + // Ignored. Likely that another transaction managed to insert first. + } + } } \ No newline at end of file diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java index 588851a20..d2b7ce8d1 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java @@ -28,7 +28,7 @@ import com.djrapitops.plan.settings.config.paths.WebserverSettings; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import extension.SeleniumExtension; import org.junit.jupiter.api.*; @@ -131,7 +131,7 @@ class ExportJSErrorRegressionTest { database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME)); FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap()); database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world")); - database.executeTransaction(new SessionEndTransaction(session)); + database.executeTransaction(new StoreSessionTransaction(session)); } @AfterAll diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java index d56e5d332..d1808f6e9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JSErrorRegressionTest.java @@ -30,7 +30,7 @@ import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import extension.SeleniumExtension; import org.junit.jupiter.api.*; @@ -101,7 +101,7 @@ class JSErrorRegressionTest { database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME)); FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap()); database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world")); - database.executeTransaction(new SessionEndTransaction(session)); + database.executeTransaction(new StoreSessionTransaction(session)); } @AfterAll diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java index b51dca612..ff7e18865 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java @@ -29,6 +29,7 @@ import com.djrapitops.plan.identification.ServerUUID; import com.djrapitops.plan.query.QuerySvc; import com.djrapitops.plan.settings.config.Config; import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.FormatSettings; import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries; import com.djrapitops.plan.storage.database.queries.Query; @@ -48,7 +49,6 @@ import com.djrapitops.plan.storage.database.transactions.events.*; import com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction; import com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch; import com.djrapitops.plan.storage.upkeep.DBCleanTask; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import utilities.FieldFetcher; import utilities.RandomData; @@ -57,6 +57,8 @@ import utilities.TestPluginLogger; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.*; import java.util.concurrent.TimeUnit; @@ -104,9 +106,9 @@ public interface DatabaseTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); db().executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", RandomData.randomTime(), serverUUID()), (uuid, name) -> false /* Not cached */)); - db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()))); + db().executeTransaction(new StoreGeoInfoTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()))); assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))); @@ -124,7 +126,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { } default void saveGeoInfo(UUID uuid, GeoInfo geoInfo) { - db().executeTransaction(new GeoInfoStoreTransaction(uuid, geoInfo)); + db().executeTransaction(new StoreGeoInfoTransaction(uuid, geoInfo)); } @Test @@ -134,7 +136,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { long sessionStart = System.currentTimeMillis(); ActiveSession session = new ActiveSession(playerUUID, serverUUID(), sessionStart, worlds[0], "SURVIVAL"); - db().executeTransaction(new SessionEndTransaction(session.toFinishedSession(sessionStart + 22345L))); + db().executeTransaction(new StoreSessionTransaction(session.toFinishedSession(sessionStart + 22345L))); TestPluginLogger logger = new TestPluginLogger(); new DBCleanTask( @@ -157,7 +159,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { saveUserTwo(); saveTwoWorlds(); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false /* Not cached */)); saveGeoInfo(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())); assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))); @@ -258,22 +260,24 @@ public interface DatabaseTest extends DatabaseTestPreparer { } @Test - @Disabled("Flaky test, fails every evening.") default void sqlDateParsingSanitySQLDoesNotApplyTimezone() { Database db = db(); + config().set(FormatSettings.TIMEZONE, "UTC"); List assertions = new ArrayList<>(); - long now = System.currentTimeMillis(); + long now = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); + long dayStartEpochSecond = now - (now % TimeUnit.DAYS.toSeconds(1)); + for (int i = 0; i < 24; i++) { - long hourChange = TimeUnit.HOURS.toMillis(i); + long hourChange = TimeUnit.HOURS.toSeconds(i); assertions.add(() -> { - long time = now + hourChange; + long time = dayStartEpochSecond + hourChange; int offset = 0; Sql sql = db.getType().getSql(); - String testSQL = SELECT + sql.dateToDayStamp(sql.epochSecondToDate(Long.toString((time + offset) / 1000))) + " as date"; + String testSQL = SELECT + sql.dateToDayStamp(sql.epochSecondToDate(Long.toString((time + offset)))) + " as date"; - String expected = deliveryUtilities().getFormatters().iso8601NoClockLong().apply(time); + String expected = deliveryUtilities().getFormatters().iso8601NoClockLong().apply(TimeUnit.SECONDS.toMillis(time)); //noinspection Convert2Diamond Causes compiler issues without Generic type definition String result = db.query(new QueryAllStatement(testSQL) { @Override @@ -324,7 +328,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); - db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID))); + db().executeTransaction(new StoreSessionTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID))); List result = db().query(new ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), 10L, 1)); assertEquals(1, result.size(), () -> "Incorrect query result: " + result); @@ -339,7 +343,7 @@ public interface DatabaseTest extends DatabaseTestPreparer { TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); - db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID))); + db().executeTransaction(new StoreSessionTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID))); List result = db().query(new NetworkTablePlayersQuery(System.currentTimeMillis(), 10L, 1)); assertEquals(1, result.size(), () -> "Incorrect query result: " + result); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java index dd4a79f77..c91d5f767 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ActivityIndexQueriesTest.java @@ -28,7 +28,7 @@ import com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTa import com.djrapitops.plan.storage.database.sql.tables.SessionsTable; import com.djrapitops.plan.storage.database.sql.tables.UsersTable; import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; @@ -60,7 +60,7 @@ public interface ActivityIndexQueriesTest extends DatabaseTestPreparer { } for (FinishedSession session : RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID)) { - if (save.test(session)) db().executeTransaction(new SessionEndTransaction(session)); + if (save.test(session)) db().executeTransaction(new StoreSessionTransaction(session)); } } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/DatabaseBackupTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/DatabaseBackupTest.java index ce5484126..48d1c68a9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/DatabaseBackupTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/DatabaseBackupTest.java @@ -52,12 +52,12 @@ public interface DatabaseBackupTest extends DatabaseTestPreparer { TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); db().executeTransaction( new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false /* Not cached */) ); - db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()))); + db().executeTransaction(new StoreGeoInfoTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()))); List expected = RandomData.randomTPS(); for (TPS tps : expected) { diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ExtensionsDatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ExtensionsDatabaseTest.java index ecaefebd7..b836d7392 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ExtensionsDatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/ExtensionsDatabaseTest.java @@ -38,7 +38,7 @@ import com.djrapitops.plan.identification.ServerUUID; import com.djrapitops.plan.storage.database.DatabaseTestPreparer; import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -122,7 +122,7 @@ public interface ExtensionsDatabaseTest extends DatabaseTestPreparer { // Store a session to check against issue https://github.com/plan-player-analytics/Plan/issues/1039 ActiveSession session = new ActiveSession(playerUUID, serverUUID(), 32345L, worlds[0], "SURVIVAL"); session.getExtraData().put(WorldTimes.class, RandomData.randomWorldTimes(worlds)); - db().executeTransaction(new SessionEndTransaction(session.toFinishedSession(42345L))); + db().executeTransaction(new StoreSessionTransaction(session.toFinishedSession(42345L))); Map result = db().query(new ExtensionServerTableDataQuery(serverUUID(), 50)); assertEquals(1, result.size()); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java index 76c213eb8..e8a4a57e9 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/GeolocationQueriesTest.java @@ -26,10 +26,10 @@ import com.djrapitops.plan.storage.database.queries.objects.BaseUserQueries; import com.djrapitops.plan.storage.database.queries.objects.GeoInfoQueries; import com.djrapitops.plan.storage.database.queries.objects.PingQueries; import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction; -import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreGeoInfoTransaction; import org.junit.jupiter.api.Test; import utilities.RandomData; import utilities.TestConstants; @@ -85,7 +85,7 @@ public interface GeolocationQueriesTest extends DatabaseTestPreparer { } default void save(UUID uuid, GeoInfo info) { - db().executeTransaction(new GeoInfoStoreTransaction(uuid, info)); + db().executeTransaction(new StoreGeoInfoTransaction(uuid, info)); } @Test diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/JoinAddressQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/JoinAddressQueriesTest.java index 639110519..246c975c3 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/JoinAddressQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/JoinAddressQueriesTest.java @@ -24,8 +24,8 @@ import com.djrapitops.plan.storage.database.queries.objects.JoinAddressQueries; import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable; import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; import com.djrapitops.plan.storage.database.transactions.events.StoreJoinAddressTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import org.junit.jupiter.api.Test; import utilities.RandomData; @@ -69,7 +69,7 @@ public interface JoinAddressQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); session.getExtraData().remove(JoinAddress.class); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Set expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID))); Set result = db().query(JoinAddressQueries.userIdsOfPlayersWithJoinAddresses(List.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP))); @@ -89,7 +89,7 @@ public interface JoinAddressQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get(); session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress)); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Map expected = Map.of(expectedAddress, 1); Map result = db().query(JoinAddressQueries.latestJoinAddresses()); @@ -108,7 +108,7 @@ public interface JoinAddressQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(TestConstants.SERVER_TWO_UUID, worlds, playerUUID, player2UUID); String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get(); session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress)); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Map expected1 = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1); Map result1 = db().query(JoinAddressQueries.latestJoinAddresses(serverUUID())); @@ -148,7 +148,7 @@ public interface JoinAddressQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, player2UUID, playerUUID); String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get(); session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress)); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Map expected = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1, expectedAddress, 1); Map result = db().query(JoinAddressQueries.latestJoinAddresses()); diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java index e4099256d..db2a99b0f 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java @@ -57,7 +57,6 @@ public interface PingQueriesTest extends DatabaseTestPreparer { assertEquals(expected, fetched); } - @Test default void pingStoreTransactionOutOfOrderUpdatesUserInformation() { db().executeTransaction(new PingStoreTransaction(player2UUID, serverUUID(), diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java index c8be04b2c..dfdfcdaa4 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/SessionQueriesTest.java @@ -59,7 +59,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); List savedSessions = sessions.get(serverUUID()); @@ -78,7 +78,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); List savedSessions = sessions.get(serverUUID()); @@ -140,7 +140,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); // killed user is registered after session already ended. db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); @@ -159,7 +159,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0])); db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1])); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); long registerDate = RandomData.randomTime(); db().executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> registerDate, TestConstants.PLAYER_ONE_NAME)); @@ -177,7 +177,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { long expectedLength = session.getLength(); long sessionEnd = session.getEnd(); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); forcePersistenceCheck(); @@ -206,7 +206,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { default void sessionsAreStoredWithAllData() { prepareForSessionSave(); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); forcePersistenceCheck(); @@ -223,7 +223,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { default void mostRecentSessionsCanBeQueried() { prepareForSessionSave(); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); List expected = Collections.singletonList(session); List result = db().query(SessionQueries.fetchLatestSessionsOfServer(serverUUID(), 1)); @@ -330,7 +330,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { prepareForSessionSave(); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); forcePersistenceCheck(); @@ -346,7 +346,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); List expected = session.getExtraData(PlayerKills.class).map(PlayerKills::asList) .orElseThrow(AssertionError::new); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); forcePersistenceCheck(); @@ -366,7 +366,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); WorldTimes expected = session.getExtraData(WorldTimes.class).orElseThrow(AssertionError::new); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); // Fetch the session Map> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)); @@ -413,8 +413,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { prepareForSessionSave(); List player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID); List player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID); - player1Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); - player2Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); + player1Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); + player2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L)); @@ -433,8 +433,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { prepareForSessionSave(); List player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID); List player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID); - player1Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); - player2Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); + player1Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); + player2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); long time = System.currentTimeMillis(); long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L)); @@ -469,14 +469,14 @@ public interface SessionQueriesTest extends DatabaseTestPreparer { default void serverPreferencePieValuesAreCorrect() { prepareForSessionSave(); List server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID); - server1Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); + server1Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); ServerUUID serverTwoUuid = TestConstants.SERVER_TWO_UUID; executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "", TestConstants.VERSION))); db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0])); db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1])); List server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID); - server2Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session))); + server2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session))); Map expected = Maps.builder(String.class, Long.class) .put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime()) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java index 34437b8f2..5e972a2c8 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/analysis/TopListQueriesTest.java @@ -19,7 +19,7 @@ package com.djrapitops.plan.storage.database.queries.analysis; import com.djrapitops.plan.gathering.domain.FinishedSession; import com.djrapitops.plan.storage.database.DatabaseTestPreparer; import com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction; -import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction; import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; import org.junit.jupiter.api.Test; import utilities.RandomData; @@ -37,7 +37,7 @@ public interface TopListQueriesTest extends DatabaseTestPreparer { db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME)); FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID); - db().executeTransaction(new SessionEndTransaction(session)); + db().executeTransaction(new StoreSessionTransaction(session)); } @Test diff --git a/Plan/common/src/test/java/utilities/TestData.java b/Plan/common/src/test/java/utilities/TestData.java index 8c7d21d9f..4ce3f35b1 100644 --- a/Plan/common/src/test/java/utilities/TestData.java +++ b/Plan/common/src/test/java/utilities/TestData.java @@ -123,11 +123,11 @@ public class TestData { playerName, server2UUID, TestConstants.GET_PLAYER_HOSTNAME)); for (GeoInfo geoInfo : playerGeoInfo) { - executeOther(new GeoInfoStoreTransaction(playerUUID, geoInfo)); + executeOther(new StoreGeoInfoTransaction(playerUUID, geoInfo)); } for (FinishedSession session : playerSessions) { - executeOther(new SessionEndTransaction(session)); + executeOther(new StoreSessionTransaction(session)); } } } @@ -146,11 +146,11 @@ public class TestData { player2Name, server2UUID, TestConstants.GET_PLAYER_HOSTNAME)); for (GeoInfo geoInfo : playerGeoInfo) { - executeOther(new GeoInfoStoreTransaction(player2UUID, geoInfo)); + executeOther(new StoreGeoInfoTransaction(player2UUID, geoInfo)); } for (FinishedSession session : player2Sessions) { - executeOther(new SessionEndTransaction(session)); + executeOther(new StoreSessionTransaction(session)); } } } diff --git a/Plan/nukkit/src/main/java/com/djrapitops/plan/gathering/listeners/nukkit/PlayerOnlineListener.java b/Plan/nukkit/src/main/java/com/djrapitops/plan/gathering/listeners/nukkit/PlayerOnlineListener.java index 9f0778707..ab54b4aa7 100644 --- a/Plan/nukkit/src/main/java/com/djrapitops/plan/gathering/listeners/nukkit/PlayerOnlineListener.java +++ b/Plan/nukkit/src/main/java/com/djrapitops/plan/gathering/listeners/nukkit/PlayerOnlineListener.java @@ -174,7 +174,7 @@ public class PlayerOnlineListener implements Listener { boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( - new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) + new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry) ); } @@ -184,7 +184,7 @@ public class PlayerOnlineListener implements Listener { session.getExtraData().put(PlayerName.class, new PlayerName(playerName)); session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName())); sessionCache.cacheSession(playerUUID, session) - .map(SessionEndTransaction::new) + .map(StoreSessionTransaction::new) .ifPresent(database::executeTransaction); database.executeTransaction(new NicknameStoreTransaction( @@ -231,7 +231,7 @@ public class PlayerOnlineListener implements Listener { dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, player::isBanned)); sessionCache.endSession(playerUUID, time) - .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession))); + .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new StoreSessionTransaction(endedSession))); if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) { processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName)); diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/PlayerOnlineListener.java b/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/PlayerOnlineListener.java index f95f5bc17..e6e3c3270 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/PlayerOnlineListener.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/gathering/listeners/sponge/PlayerOnlineListener.java @@ -177,7 +177,7 @@ public class PlayerOnlineListener { boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( - new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) + new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry) ); } database.executeTransaction(new StoreJoinAddressTransaction(getHostName)); @@ -187,7 +187,7 @@ public class PlayerOnlineListener { session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName())); session.getExtraData().put(JoinAddress.class, new JoinAddress(getHostName)); sessionCache.cacheSession(playerUUID, session) - .map(SessionEndTransaction::new) + .map(StoreSessionTransaction::new) .ifPresent(database::executeTransaction); database.executeTransaction(new NicknameStoreTransaction( @@ -233,7 +233,7 @@ public class PlayerOnlineListener { dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, () -> isBanned(player.getProfile()))); sessionCache.endSession(playerUUID, time) - .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession))); + .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new StoreSessionTransaction(endedSession))); if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) { processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName)); diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/gathering/listeners/velocity/PlayerOnlineListener.java b/Plan/velocity/src/main/java/com/djrapitops/plan/gathering/listeners/velocity/PlayerOnlineListener.java index 75070bc47..829bcadd7 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/gathering/listeners/velocity/PlayerOnlineListener.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/gathering/listeners/velocity/PlayerOnlineListener.java @@ -31,8 +31,8 @@ import com.djrapitops.plan.settings.config.paths.DataGatheringSettings; import com.djrapitops.plan.settings.config.paths.ExportSettings; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; -import com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction; import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; +import com.djrapitops.plan.storage.database.transactions.events.StoreGeoInfoTransaction; import com.djrapitops.plan.utilities.logging.ErrorContext; import com.djrapitops.plan.utilities.logging.ErrorLogger; import com.velocitypowered.api.event.PostOrder; @@ -119,7 +119,7 @@ public class PlayerOnlineListener { boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); if (gatheringGeolocations) { database.executeTransaction( - new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry) + new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry) ); }