Search in sources :

Example 1 with Transaction

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

the class BukkitImporter method processServerData.

private void processServerData() {
    ServerImportData serverImportData = getServerImportData();
    if (serverImportData == null) {
        return;
    }
    dbSystem.getDatabase().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllTPSData(Collections.singletonMap(serverUUID.get(), serverImportData.getTpsData())));
        }
    });
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ServerImportData(com.djrapitops.plan.gathering.importing.data.ServerImportData)

Example 2 with Transaction

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

the class SessionQueriesTest method worldTimesAreSavedWithSessionWithoutWorlds.

@Test
default void worldTimesAreSavedWithSessionWithoutWorlds() {
    prepareForSessionSave();
    // Remove the worlds from the database so that they need to also be saved.
    execute(new ExecStatement("DELETE FROM " + WorldTable.TABLE_NAME) {

        @Override
        public void prepare(PreparedStatement statement) {
        // Nothing needed
        }
    });
    WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
    session.getExtraData().put(WorldTimes.class, worldTimes);
    List<FinishedSession> sessions = new ArrayList<>();
    sessions.add(session);
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
    assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
}
Also used : 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) PreparedStatement(java.sql.PreparedStatement) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 3 with Transaction

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

the class SessionQueriesTest method worldTimesAreSavedWithSession.

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

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
    assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
}
Also used : 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)

Example 4 with Transaction

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

the class UserInfoQueriesTest method cleanRemovesOnlyDuplicatedUserInfo.

@Test
default void cleanRemovesOnlyDuplicatedUserInfo() throws ExecutionException, InterruptedException {
    // Store one duplicate
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
            execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
            execute(DataStoreQueries.registerUserInfo(player2UUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
        }
    }).get();
    db().executeTransaction(new RemoveDuplicateUserInfoTransaction());
    Set<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
    assertEquals(Collections.singleton(new UserInfo(playerUUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)), found);
    Set<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
    assertEquals(Collections.singleton(new UserInfo(player2UUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)), found2);
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) Test(org.junit.jupiter.api.Test)

Example 5 with Transaction

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

the class DBPatchSQLiteRegressionTest method setUpDBWithOldSchema.

@BeforeEach
void setUpDBWithOldSchema(@TempDir Path tempDir) throws Exception {
    component = new PluginMockComponent(tempDir);
    underTest = this.component.getPlanSystem().getDatabaseSystem().getSqLiteFactory().usingFileCalled("test");
    underTest.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
    underTest.init();
    // Initialize database with the old table schema
    dropAllTables(underTest);
    underTest.executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(serverTable);
            execute(usersTable);
            execute(userInfoTable);
            execute(geoInfoTable);
            execute(nicknameTable);
            execute(sessionsTable);
            execute(killsTable);
            execute(pingTable);
            execute(commandUseTable);
            execute(tpsTable);
            execute(worldsTable);
            execute(worldTimesTable);
            execute(securityTable);
            execute(transferTable);
        }
    });
    underTest.executeTransaction(new CreateTablesTransaction());
    insertData(underTest);
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) PluginMockComponent(utilities.mocks.PluginMockComponent) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

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