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);
}
}
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;
}
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()));
}
}
Aggregations