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