Search in sources :

Example 1 with RemovePlayerTransaction

use of com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction in project Plan by plan-player-analytics.

the class DatabaseTest method testRemovalSingleUser.

@Test
default void testRemovalSingleUser() {
    saveUserTwo();
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    saveTwoWorlds();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", RandomData.randomTime(), serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    db().executeTransaction(new RemovePlayerTransaction(playerUUID));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    assertFalse(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
    assertTrue(db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID)).isEmpty());
    assertTrue(db().query(GeoInfoQueries.fetchPlayerGeoInformation(playerUUID)).isEmpty());
    assertQueryIsEmpty(db(), SessionQueries.fetchSessionsOfPlayer(playerUUID));
}
Also used : SELECT(com.djrapitops.plan.storage.database.sql.building.Sql.SELECT) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Disabled(org.junit.jupiter.api.Disabled) utilities(utilities) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) com.djrapitops.plan.storage.database.queries(com.djrapitops.plan.storage.database.queries) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WHERE(com.djrapitops.plan.storage.database.sql.building.Sql.WHERE) ServerPlayerContainersQuery(com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Example 2 with RemovePlayerTransaction

use of com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction in project Plan by plan-player-analytics.

the class DBCleanTask method cleanOldPlayers.

// VisibleForTesting
public int cleanOldPlayers(Database database) {
    long now = System.currentTimeMillis();
    long keepActiveAfter = now - config.get(TimeSettings.DELETE_INACTIVE_PLAYERS_AFTER);
    List<UUID> inactivePlayers = database.query(fetchInactivePlayerUUIDs(keepActiveAfter));
    for (UUID playerUUID : inactivePlayers) {
        queryService.playerRemoved(playerUUID);
        database.executeTransaction(new RemovePlayerTransaction(playerUUID));
    }
    return inactivePlayers.size();
}
Also used : UUID(java.util.UUID) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction)

Aggregations

RemovePlayerTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction)2 Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)1 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)1 Key (com.djrapitops.plan.delivery.domain.keys.Key)1 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)1 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)1 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 QuerySvc (com.djrapitops.plan.query.QuerySvc)1 Config (com.djrapitops.plan.settings.config.Config)1 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)1 Locale (com.djrapitops.plan.settings.locale.Locale)1 com.djrapitops.plan.storage.database.queries (com.djrapitops.plan.storage.database.queries)1 ContainerFetchQueries (com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries)1 ServerPlayerContainersQuery (com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery)1 com.djrapitops.plan.storage.database.queries.objects (com.djrapitops.plan.storage.database.queries.objects)1 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)1