Search in sources :

Example 6 with Transaction

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

the class DBPatchMySQLRegressionTest method dropAllTables.

private void dropAllTables() {
    String dbName = System.getenv(CIProperties.MYSQL_DATABASE);
    underTest.executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute("DROP DATABASE " + dbName);
            execute("CREATE DATABASE " + dbName);
            execute("USE " + dbName);
        }
    });
}
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)

Example 7 with Transaction

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

the class DBPatchMySQLRegressionTest method setUpDBWithOldSchema.

@BeforeEach
void setUpDBWithOldSchema() {
    Optional<Database> db = dbPreparer.prepareMySQL();
    assumeTrue(db.isPresent());
    underTest = (MySQLDB) db.get();
    dropAllTables();
    // Initialize database with the old table schema
    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) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction)

Example 8 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)

Example 9 with Transaction

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

the class DatabaseTest method indexCreationWorksWithoutErrors.

@Test
default void indexCreationWorksWithoutErrors() throws Exception {
    Transaction transaction = new CreateIndexTransaction();
    // get to ensure transaction is finished
    db().executeTransaction(transaction).get();
    assertTrue(transaction.wasSuccessful());
}
Also used : CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) 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) Test(org.junit.jupiter.api.Test)

Example 10 with Transaction

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

the class BukkitImporter method processUserData.

private void processUserData() {
    List<UserImportData> userImportData = getUserImportData();
    if (userImportData == null || userImportData.isEmpty()) {
        return;
    }
    BukkitUserImportRefiner userImportRefiner = new BukkitUserImportRefiner(userImportData);
    userImportData = userImportRefiner.refineData();
    Database db = dbSystem.getDatabase();
    Set<UUID> existingUUIDs = db.query(UserIdentifierQueries.fetchAllPlayerUUIDs());
    Set<UUID> existingUserInfoTableUUIDs = db.query(UserIdentifierQueries.fetchPlayerUUIDsOfServer(serverUUID.get()));
    Map<UUID, BaseUser> users = new HashMap<>();
    List<UserInfo> userInfo = new ArrayList<>();
    Map<UUID, List<Nickname>> nickNames = new HashMap<>();
    List<FinishedSession> sessions = new ArrayList<>();
    Map<UUID, List<GeoInfo>> geoInfo = new HashMap<>();
    userImportData.parallelStream().forEach(data -> {
        UUID uuid = data.getUuid();
        if (!existingUUIDs.contains(uuid)) {
            users.put(uuid, toBaseUser(data));
        }
        if (!existingUserInfoTableUUIDs.contains(uuid)) {
            userInfo.add(toUserInfo(data));
        }
        nickNames.put(uuid, data.getNicknames());
        geoInfo.put(uuid, convertGeoInfo(data));
        sessions.add(toSession(data));
    });
    db.executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllCommonUserInformation(users.values()));
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
            Map<ServerUUID, List<UserInfo>> userInformation = Collections.singletonMap(serverUUID.get(), userInfo);
            execute(LargeStoreQueries.storePerServerUserInformation(userInformation));
            execute(LargeStoreQueries.storeAllNicknameData(Collections.singletonMap(serverUUID.get(), nickNames)));
            execute(LargeStoreQueries.storeAllGeoInformation(geoInfo));
        }
    });
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) BukkitUserImportRefiner(com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner) UserImportData(com.djrapitops.plan.gathering.importing.data.UserImportData)

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)4 ServerUUID (com.djrapitops.plan.identification.ServerUUID)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 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 Server (com.djrapitops.plan.identification.Server)1 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)1 Database (com.djrapitops.plan.storage.database.Database)1 SQLDB (com.djrapitops.plan.storage.database.SQLDB)1 ExecStatement (com.djrapitops.plan.storage.database.transactions.ExecStatement)1