Search in sources :

Example 1 with CreateTablesTransaction

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

the class SQLDB method setupDatabase.

/**
 * Ensures connection functions correctly and all tables exist.
 * <p>
 * Updates to latest schema.
 */
private void setupDatabase() {
    executeTransaction(new CreateTablesTransaction());
    logger.info("Database: Making sure schema is up to date..");
    for (Patch patch : patches()) {
        executeTransaction(patch);
    }
    executeTransaction(new OperationCriticalTransaction() {

        @Override
        protected void performOperations() {
            if (getState() == State.PATCHING)
                setState(State.OPEN);
        }
    });
    registerIndexCreationTask();
    logger.info("Database: Ready for operation.");
}
Also used : CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) RemoveIncorrectTebexPackageDataPatch(com.djrapitops.plan.storage.database.transactions.init.RemoveIncorrectTebexPackageDataPatch) OperationCriticalTransaction(com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction)

Example 2 with CreateTablesTransaction

use of com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction 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 3 with CreateTablesTransaction

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

the class MySQLTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new Patch() {

        @Override
        public boolean hasBeenApplied() {
            return false;
        }

        @Override
        public void applyPatch() {
            dropTable("plan_world_times");
            dropTable("plan_kills");
            dropTable("plan_sessions");
            dropTable("plan_worlds");
            dropTable("plan_users");
        }
    });
    db().executeTransaction(new CreateTablesTransaction());
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "")));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CreateTablesTransaction

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

the class DBPatchMySQLRegressionTest method setUpDBWithOldSchema.

@BeforeEach
void setUpDBWithOldSchema() throws Exception {
    PlanSystem system = component.getPlanSystem();
    Optional<Database> db = new DBPreparer(system, TEST_PORT_NUMBER).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) PlanSystem(com.djrapitops.plan.PlanSystem) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction)

Example 5 with CreateTablesTransaction

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

the class SQLiteTest method setUp.

@BeforeEach
void setUp() {
    TestErrorLogger.throwErrors(true);
    db().executeTransaction(new Patch() {

        @Override
        public boolean hasBeenApplied() {
            return false;
        }

        @Override
        public void applyPatch() {
            dropTable("plan_world_times");
            dropTable("plan_kills");
            dropTable("plan_sessions");
            dropTable("plan_worlds");
            dropTable("plan_users");
        }
    });
    db().executeTransaction(new CreateTablesTransaction());
    db().executeTransaction(new RemoveEverythingTransaction());
    db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "")));
    assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}
Also used : Server(com.djrapitops.plan.identification.Server) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) Patch(com.djrapitops.plan.storage.database.transactions.patches.Patch) CreateTablesTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CreateTablesTransaction (com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransaction)5 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Server (com.djrapitops.plan.identification.Server)2 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)2 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)2 Patch (com.djrapitops.plan.storage.database.transactions.patches.Patch)2 PlanSystem (com.djrapitops.plan.PlanSystem)1 OperationCriticalTransaction (com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction)1 RemoveIncorrectTebexPackageDataPatch (com.djrapitops.plan.storage.database.transactions.init.RemoveIncorrectTebexPackageDataPatch)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 PluginMockComponent (utilities.mocks.PluginMockComponent)1