mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-05 07:58:08 +01:00
Various fixes to transactions
- Hopefully fix user_id relation error once and for all. - Set timezone to 00:00 properly when MySQL initializes connection Affects issues: - Close #1239
This commit is contained in:
parent
7aa84c27e4
commit
368f1e5002
@ -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));
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -73,14 +73,19 @@ public class PlayerFetchQueries {
|
||||
* @return True if the player's BaseUser is found
|
||||
*/
|
||||
public static Query<Boolean> 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<Boolean>(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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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<String> geolocationFunction) {
|
||||
public StoreGeoInfoTransaction(UUID playerUUID, String ip, long time, UnaryOperator<String> 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.
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<org.junit.jupiter.api.function.Executable> 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<String>(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<TablePlayer> 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<TablePlayer> result = db().query(new NetworkTablePlayersQuery(System.currentTimeMillis(), 10L, 1));
|
||||
assertEquals(1, result.size(), () -> "Incorrect query result: " + result);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<TPS> expected = RandomData.randomTPS();
|
||||
for (TPS tps : expected) {
|
||||
|
@ -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<UUID, ExtensionTabData> result = db().query(new ExtensionServerTableDataQuery(serverUUID(), 50));
|
||||
assertEquals(1, result.size());
|
||||
|
@ -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
|
||||
|
@ -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<Integer> expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID)));
|
||||
Set<Integer> 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<String, Integer> expected = Map.of(expectedAddress, 1);
|
||||
Map<String, Integer> 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<String, Integer> expected1 = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
|
||||
Map<String, Integer> 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<String, Integer> expected = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1, expectedAddress, 1);
|
||||
Map<String, Integer> result = db().query(JoinAddressQueries.latestJoinAddresses());
|
||||
|
@ -57,7 +57,6 @@ public interface PingQueriesTest extends DatabaseTestPreparer {
|
||||
assertEquals(expected, fetched);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
default void pingStoreTransactionOutOfOrderUpdatesUserInformation() {
|
||||
db().executeTransaction(new PingStoreTransaction(player2UUID, serverUUID(),
|
||||
|
@ -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<ServerUUID, List<FinishedSession>> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
|
||||
List<FinishedSession> 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<ServerUUID, List<FinishedSession>> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
|
||||
List<FinishedSession> 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<FinishedSession> expected = Collections.singletonList(session);
|
||||
List<FinishedSession> 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<PlayerKill> 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<ServerUUID, List<FinishedSession>> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
|
||||
@ -413,8 +413,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
|
||||
prepareForSessionSave();
|
||||
List<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
|
||||
List<FinishedSession> 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<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
|
||||
List<FinishedSession> 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<FinishedSession> 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<FinishedSession> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
|
||||
server2Sessions.forEach(session -> db().executeTransaction(new SessionEndTransaction(session)));
|
||||
server2Sessions.forEach(session -> db().executeTransaction(new StoreSessionTransaction(session)));
|
||||
|
||||
Map<String, Long> expected = Maps.builder(String.class, Long.class)
|
||||
.put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime())
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user