Search in sources :

Example 16 with DBOpException

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

the class WorldTimesOptimizationPatch method applyPatch.

@Override
protected void applyPatch() {
    try {
        tempOldTable();
        execute(WorldTimesTable.createTableSQL(dbType));
        if (hasColumn(tempTableName, WorldTimesTable.ID)) {
            execute("INSERT INTO " + tableName + " (" + WorldTimesTable.USER_ID + ',' + WorldTimesTable.SERVER_ID + ',' + WorldTimesTable.ADVENTURE + ',' + WorldTimesTable.CREATIVE + ',' + WorldTimesTable.SURVIVAL + ',' + WorldTimesTable.SPECTATOR + ',' + WorldTimesTable.SESSION_ID + ',' + WorldTimesTable.WORLD_ID + ") 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), " + WorldTimesTable.ADVENTURE + ',' + WorldTimesTable.CREATIVE + ',' + WorldTimesTable.SURVIVAL + ',' + WorldTimesTable.SPECTATOR + ',' + WorldTimesTable.SESSION_ID + ',' + WorldTimesTable.WORLD_ID + FROM + tempTableName);
        } else {
            execute("INSERT INTO " + tableName + " (" + WorldTimesTable.USER_ID + ',' + WorldTimesTable.SERVER_ID + ',' + WorldTimesTable.ADVENTURE + ',' + WorldTimesTable.CREATIVE + ',' + WorldTimesTable.SURVIVAL + ',' + WorldTimesTable.SPECTATOR + ',' + WorldTimesTable.SESSION_ID + ',' + WorldTimesTable.WORLD_ID + ") SELECT " + WorldTimesTable.USER_ID + ',' + WorldTimesTable.SERVER_ID + ',' + WorldTimesTable.ADVENTURE + ',' + WorldTimesTable.CREATIVE + ',' + WorldTimesTable.SURVIVAL + ',' + WorldTimesTable.SPECTATOR + ',' + WorldTimesTable.SESSION_ID + ',' + WorldTimesTable.WORLD_ID + FROM + tempTableName);
        }
        dropTable(tempTableName);
    } catch (Exception e) {
        throw new DBOpException(WorldTimesOptimizationPatch.class.getSimpleName() + " failed.", e);
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException)

Example 17 with DBOpException

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

the class MySQLDB method getConnection.

@Override
public synchronized Connection getConnection() throws SQLException {
    Connection connection = dataSource.getConnection();
    if (!connection.isValid(5)) {
        connection.close();
        try {
            return getConnection();
        } catch (StackOverflowError databaseHasGoneDown) {
            throw new DBOpException("Valid connection could not be fetched (Is MySQL down?) - attempted until StackOverflowError occurred.", databaseHasGoneDown);
        }
    }
    if (connection.getAutoCommit())
        connection.setAutoCommit(false);
    setTimezoneToUTC(connection);
    return connection;
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException)

Example 18 with DBOpException

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

the class DatabaseCommands method performRestore.

public void performRestore(CMDSender sender, File backupDBFile, Database toDB) {
    try {
        SQLiteDB fromDB = sqliteFactory.usingFile(backupDBFile);
        fromDB.init();
        sender.send(locale.getString(CommandLang.DB_WRITE, toDB.getType().getName()));
        toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
        sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (DBOpException | ExecutionException e) {
        errorLogger.error(e, ErrorContext.builder().related(backupDBFile, toDB.getType(), toDB.getState()).build());
        sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) 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