Search in sources :

Example 6 with DBOpException

use of com.djrapitops.plan.exceptions.database.DBOpException in project Plan by plan-player-analytics.

the class UserInfoOptimizationPatch method applyPatch.

@Override
protected void applyPatch() {
    try {
        tempOldTable();
        execute(UserInfoTable.createTableSQL(dbType));
        execute("INSERT INTO " + tableName + " (" + UserInfoTable.USER_ID + ',' + UserInfoTable.SERVER_ID + ',' + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + UserInfoTable.JOIN_ADDRESS + ") SELECT " + "(SELECT plan_users.id FROM plan_users WHERE plan_users.uuid = " + tempTableName + ".uuid LIMIT 1), " + "(SELECT plan_servers.id FROM plan_servers WHERE plan_servers.uuid = " + tempTableName + ".server_uuid LIMIT 1), " + UserInfoTable.REGISTERED + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.OP + ',' + UserInfoTable.JOIN_ADDRESS + FROM + tempTableName);
        dropTable(tempTableName);
    } catch (Exception e) {
        throw new DBOpException(UserInfoOptimizationPatch.class.getSimpleName() + " failed.", e);
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException)

Example 7 with DBOpException

use of com.djrapitops.plan.exceptions.database.DBOpException in project Plan by plan-player-analytics.

the class WorldsOptimizationPatch method applyPatch.

@Override
protected void applyPatch() {
    try {
        dropForeignKeys(tableName);
        ensureNoForeignKeyConstraints(tableName);
        tempOldTable();
        execute(WorldTable.createTableSQL(dbType));
        execute("INSERT INTO " + tableName + " (" + WorldTable.ID + ',' + WorldTable.SERVER_UUID + ',' + WorldTable.NAME + ") SELECT " + WorldTable.ID + ',' + "(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " + WorldTable.NAME + FROM + tempTableName);
        dropTable(tempTableName);
    } catch (Exception e) {
        throw new DBOpException(WorldsOptimizationPatch.class.getSimpleName() + " failed.", e);
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException)

Example 8 with DBOpException

use of com.djrapitops.plan.exceptions.database.DBOpException in project Plan by plan-player-analytics.

the class StoreSessionTransaction method registerPlayer.

private void registerPlayer() {
    try {
        UUID playerUUID = session.getPlayerUUID();
        String playerName = session.getExtraData(PlayerName.class).map(PlayerName::get).orElseGet(playerUUID::toString);
        execute(DataStoreQueries.registerBaseUser(playerUUID, session.getStart(), playerName));
    } catch (DBOpException ignored) {
    // Ignored. Likely that another transaction managed to insert first.
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) UUID(java.util.UUID)

Example 9 with DBOpException

use of com.djrapitops.plan.exceptions.database.DBOpException in project Plan by plan-player-analytics.

the class DatabaseCommands method performClear.

private void performClear(CMDSender sender, DBType fromDB) {
    try {
        Database fromDatabase = dbSystem.getActiveDatabaseByType(fromDB);
        fromDatabase.init();
        sender.send(locale.getString(CommandLang.DB_REMOVAL, fromDB.getName()));
        fromDatabase.executeTransaction(new RemoveEverythingTransaction()).get();
        queryService.dataCleared();
        sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
        // Reload plugin to register the server into the database
        // Otherwise errors will start.
        statusCommands.onReload(sender);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (DBOpException | ExecutionException e) {
        sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
        errorLogger.error(e, ErrorContext.builder().related(sender, fromDB.getName()).build());
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Database(com.djrapitops.plan.storage.database.Database) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with DBOpException

use of com.djrapitops.plan.exceptions.database.DBOpException in project Plan by plan-player-analytics.

the class DatabaseCommands method performBackup.

public void performBackup(CMDSender sender, Arguments arguments, String dbName, Database fromDB) {
    Database toDB = null;
    try {
        String timeStamp = timestamp.apply(System.currentTimeMillis());
        String fileName = dbName + "-backup-" + timeStamp;
        sender.send(locale.getString(CommandLang.DB_BACKUP_CREATE, fileName, dbName));
        toDB = sqliteFactory.usingFileCalled(fileName);
        toDB.init();
        toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
    } catch (DBOpException | ExecutionException e) {
        errorLogger.error(e, ErrorContext.builder().related(sender, arguments).build());
    } catch (InterruptedException e) {
        toDB.close();
        Thread.currentThread().interrupt();
    } finally {
        if (toDB != null) {
            toDB.close();
        }
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) Database(com.djrapitops.plan.storage.database.Database) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)18 Database (com.djrapitops.plan.storage.database.Database)6 ExecutionException (java.util.concurrent.ExecutionException)4 BackupCopyTransaction (com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction)2 User (com.djrapitops.plan.delivery.domain.auth.User)1 PassEncryptException (com.djrapitops.plan.exceptions.PassEncryptException)1 WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)1 RemoveUnsatisfiedConditionalPlayerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction)1 RemoveUnsatisfiedConditionalServerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction)1 Ping (com.djrapitops.plan.gathering.domain.Ping)1 DBType (com.djrapitops.plan.storage.database.DBType)1 SQLiteDB (com.djrapitops.plan.storage.database.SQLiteDB)1 RegisterWebUserTransaction (com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction)1 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)1 RemoveDuplicateUserInfoTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction)1 RemoveOldExtensionsTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveOldExtensionsTransaction)1 RemoveOldSampledDataTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveOldSampledDataTransaction)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1