Fixed SQLException related to Register concurrency. Fixed compile issues.

This commit is contained in:
Rsl1122 2017-09-02 12:59:38 +03:00
parent 6ddaf8dec8
commit 555840c238
8 changed files with 26 additions and 28 deletions

View File

@ -5,6 +5,7 @@ import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand; import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.Database;
@ -12,6 +13,8 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg; import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.Check;
import java.sql.SQLException;
/** /**
* This manage subcommand is used to clear a database of all data. * This manage subcommand is used to clear a database of all data.
* *
@ -80,12 +83,12 @@ public class ManageClearCommand extends SubCommand {
try { try {
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse()); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse());
if (database.removeAllData()) { database.removeAllData();
// TODO Clear active session of all users & start new ones // TODO Clear active session of all users & start new ones
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CLEAR_SUCCESS).toString()); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_CLEAR_SUCCESS).toString());
} else { } catch (SQLException e) {
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
} Log.toLog(this.getClass().getSimpleName() + "/" + this.getTaskName(), e);
} finally { } finally {
this.cancel(); this.cancel();
} }

View File

@ -195,9 +195,9 @@ public abstract class Database {
* <p> * <p>
* Uses DELETE * FROM table. * Uses DELETE * FROM table.
* *
* @return Success of removal. * @throws SQLException if remove fails.
*/ */
public abstract boolean removeAllData(); public abstract void removeAllData() throws SQLException;
/** /**
* Used to fetch the saved UUIDs in the users table. * Used to fetch the saved UUIDs in the users table.

View File

@ -244,16 +244,12 @@ public abstract class SQLDB extends Database {
* @return * @return
*/ */
@Override @Override
public boolean removeAllData() { public void removeAllData() throws SQLException {
setStatus("Clearing all data"); setStatus("Clearing all data");
try { try {
for (Table table : getAllTablesInRemoveOrder()) { for (Table table : getAllTablesInRemoveOrder()) {
if (!table.removeAllData()) { table.removeAllData();
return false;
}
} }
return true;
} finally { } finally {
setAvailable(); setAvailable();
} }

View File

@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseException;
import main.java.com.djrapitops.plan.database.Container; import main.java.com.djrapitops.plan.database.Container;
import main.java.com.djrapitops.plan.database.DBUtils; import main.java.com.djrapitops.plan.database.DBUtils;
import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.databases.SQLDB;
@ -134,12 +133,8 @@ public abstract class Table {
/** /**
* @return * @return
*/ */
public void removeAllData() throws DatabaseException { public void removeAllData() throws SQLException {
try { execute("DELETE FROM " + tableName);
execute("DELETE FROM " + tableName);
} catch (SQLException e) {
throw new DatabaseException("Failed to delete", e);
}
} }
/** /**

View File

@ -5,7 +5,6 @@
package main.java.com.djrapitops.plan.database.tables.move; package main.java.com.djrapitops.plan.database.tables.move;
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.api.exceptions.DatabaseException;
import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.database.tables.ServerTable; import main.java.com.djrapitops.plan.database.tables.ServerTable;
import main.java.com.djrapitops.plan.database.tables.Table; import main.java.com.djrapitops.plan.database.tables.Table;
@ -44,7 +43,7 @@ public class BatchOperationTable extends Table {
throw new IllegalStateException("Method not supposed to be used on this table."); throw new IllegalStateException("Method not supposed to be used on this table.");
} }
public void clearTable(Table table) throws DatabaseException { public void clearTable(Table table) throws SQLException {
table.removeAllData(); table.removeAllData();
} }

View File

@ -95,9 +95,10 @@ public class PlanPlayerListener implements Listener {
cache.cacheSession(uuid, Session.start(time, world, gm)); cache.cacheSession(uuid, Session.start(time, world, gm));
plugin.addToProcessQueue( plugin.addToProcessQueue(
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline), new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
new IPUpdateProcessor(uuid, ip), new IPUpdateProcessor(uuid, ip),
new NameProcessor(uuid, playerName, displayName) new NameProcessor(uuid, playerName, displayName)
)
); );
} }

View File

@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.Actions; import main.java.com.djrapitops.plan.database.tables.Actions;
import main.java.com.djrapitops.plan.database.tables.UserInfoTable; import main.java.com.djrapitops.plan.database.tables.UserInfoTable;
import main.java.com.djrapitops.plan.database.tables.UsersTable; import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
@ -26,13 +27,15 @@ public class RegisterProcessor extends PlayerProcessor {
private final long time; private final long time;
private final int playersOnline; private final int playersOnline;
private final String name; private final String name;
private final Processor[] afterProcess;
public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline) { public RegisterProcessor(UUID uuid, long registered, long time, String name, int playersOnline, Processor... afterProcess) {
super(uuid); super(uuid);
this.registered = registered; this.registered = registered;
this.time = time; this.time = time;
this.playersOnline = playersOnline; this.playersOnline = playersOnline;
this.name = name; this.name = name;
this.afterProcess = afterProcess;
} }
@Override @Override
@ -55,5 +58,6 @@ public class RegisterProcessor extends PlayerProcessor {
} catch (SQLException e) { } catch (SQLException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
plugin.addToProcessQueue(afterProcess);
} }
} }

View File

@ -68,7 +68,7 @@ public class ManageUtils {
*/ */
public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) { public static boolean clearAndCopy(Database clearAndCopyToDB, Database copyFromDB) {
// try { // try {
clearAndCopyToDB.removeAllData(); //clearAndCopyToDB.removeAllData();
//TODO List<UserInfo> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs()); //TODO List<UserInfo> allUserData = copyFromDB.getUserDataForUUIDS(copyFromDB.getSavedUUIDs());
// clearAndCopyToDB.saveMultipleUserData(allUserData); // clearAndCopyToDB.saveMultipleUserData(allUserData);
// TODO clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse()); // TODO clearAndCopyToDB.getCommandUseTable().saveCommandUse(copyFromDB.getCommandUseTable().getCommandUse());