Search in sources :

Example 1 with SQLDB

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

the class DBPreparer method prepareDBByName.

private SQLDB prepareDBByName(String dbName) {
    PlanConfig config = dependencies.config();
    config.set(WebserverSettings.PORT, testPortNumber);
    config.set(DatabaseSettings.TYPE, dbName);
    dependencies.enable();
    DBSystem dbSystem = dependencies.dbSystem();
    SQLDB db = (SQLDB) dbSystem.getActiveDatabaseByName(dbName);
    db.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
    db.init();
    return db;
}
Also used : DBSystem(com.djrapitops.plan.storage.database.DBSystem) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SQLDB(com.djrapitops.plan.storage.database.SQLDB) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig)

Example 2 with SQLDB

use of com.djrapitops.plan.storage.database.SQLDB 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)

Aggregations

PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)2 SQLDB (com.djrapitops.plan.storage.database.SQLDB)2 DBSystem (com.djrapitops.plan.storage.database.DBSystem)1 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1