Search in sources :

Example 11 with Transaction

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

the class DatabaseTest method registerDateIsMinimized.

@Test
default void registerDateIsMinimized() {
    executeTransactions(new PlayerServerRegisterTransaction(playerUUID, () -> 1000, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME), new Transaction() {

        @Override
        protected void performOperations() {
            execute("UPDATE " + UserInfoTable.TABLE_NAME + " SET " + UserInfoTable.REGISTERED + "=0" + WHERE + UserInfoTable.USER_UUID + "='" + playerUUID + "'");
        }
    });
    // Check test assumptions
    Map<UUID, Long> registerDates = db().query(UserInfoQueries.fetchRegisterDates(0L, System.currentTimeMillis(), serverUUID()));
    assertEquals(0L, registerDates.get(playerUUID));
    Optional<BaseUser> baseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
    assertEquals(1000L, baseUser.isPresent() ? baseUser.get().getRegistered() : null);
    RegisterDateMinimizationPatch testedPatch = new RegisterDateMinimizationPatch();
    executeTransactions(testedPatch);
    // Test expected result
    Optional<BaseUser> updatedBaseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
    assertEquals(0L, updatedBaseUser.isPresent() ? updatedBaseUser.get().getRegistered() : null);
    assertTrue(testedPatch.isApplied());
}
Also used : BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Test(org.junit.jupiter.api.Test)

Example 12 with Transaction

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

the class DBPreparer method prepareMySQL.

public Optional<Database> prepareMySQL() {
    PlanConfig config = dependencies.config();
    Optional<String> formattedDB = setUpMySQLSettings(config);
    if (formattedDB.isPresent()) {
        String formattedDatabase = formattedDB.get();
        SQLDB mysql = prepareDBByName(DBType.MYSQL.getName());
        mysql.executeTransaction(new Transaction() {

            @Override
            protected void performOperations() {
                execute("DROP DATABASE " + formattedDatabase);
                execute("CREATE DATABASE " + formattedDatabase);
                execute("USE " + formattedDatabase);
            }
        });
        return Optional.of(mysql);
    }
    return Optional.empty();
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) SQLDB(com.djrapitops.plan.storage.database.SQLDB) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig)

Example 13 with Transaction

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

the class SessionQueriesTest method worldTimesAreSavedWithAllSessionSave.

@Test
default void worldTimesAreSavedWithAllSessionSave() {
    prepareForSessionSave();
    WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
    session.getExtraData().put(WorldTimes.class, worldTimes);
    List<FinishedSession> sessions = Collections.singletonList(session);
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    Map<ServerUUID, WorldTimes> saved = db().query(WorldTimesQueries.fetchPlayerWorldTimesOnServers(playerUUID));
    WorldTimes savedWorldTimes = saved.get(serverUUID());
    assertEquals(worldTimes, savedWorldTimes);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)13 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)7 Test (org.junit.jupiter.api.Test)6 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)5 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)3 CreateTablesTransaction (com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 StoreConfigTransaction (com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction)2 RemovePlayerTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction)2 CreateIndexTransaction (com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction)2 PlanSystem (com.djrapitops.plan.PlanSystem)1 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)1 UserInfo (com.djrapitops.plan.gathering.domain.UserInfo)1 BukkitUserImportRefiner (com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner)1 ServerImportData (com.djrapitops.plan.gathering.importing.data.ServerImportData)1 UserImportData (com.djrapitops.plan.gathering.importing.data.UserImportData)1