From 1f31f472bd0493c007b605f30099297ed16f5588 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 2 Sep 2017 17:33:49 +0300 Subject: [PATCH] removeUserData methods now have no return value. No Exception -> success. --- .../commands/manage/ManageRemoveCommand.java | 7 ++----- .../djrapitops/plan/database/Database.java | 3 +-- .../plan/database/databases/SQLDB.java | 13 +++--------- .../plan/database/tables/KillsTable.java | 7 +------ .../plan/database/tables/UserIDTable.java | 7 +------ .../plan/database/tables/UsersTable.java | 5 +---- .../plan/database/tables/WorldTimesTable.java | 1 - .../plan/database/tables/ActionsTest.java | 20 +++++++++++++++++++ 8 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 Plan/test/main/java/com/djrapitops/plan/database/tables/ActionsTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java index 2d645f47d..1f3968d84 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRemoveCommand.java @@ -85,11 +85,8 @@ public class ManageRemoveCommand extends SubCommand { sender.sendMessage(Locale.get(Msg.MANAGE_INFO_START).parse()); try { // TODO Clear active session of user & start new one - if (plugin.getDB().removeAccount(uuid)) { - sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, plugin.getDB().getConfigName())); - } else { - sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); - } + plugin.getDB().removeAccount(uuid); + sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, plugin.getDB().getConfigName())); } catch (SQLException e) { Log.toLog(this.getClass().getName(), e); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/Database.java b/Plan/src/main/java/com/djrapitops/plan/database/Database.java index adc673207..3b0f3a59e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/Database.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/Database.java @@ -185,10 +185,9 @@ public abstract class Database { * Removes all data related to an account from the database. * * @param uuid UUID of the account. - * @return Success of the removal. * @throws SQLException If a database error occurs. */ - public abstract boolean removeAccount(UUID uuid) throws SQLException; + public abstract void removeAccount(UUID uuid) throws SQLException; /** * Used to clear all data from the database. diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index eea9b1c02..13757ff28 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -200,9 +200,9 @@ public abstract class SQLDB extends Database { } } - public boolean removeAccount(UUID uuid) throws SQLException { + public void removeAccount(UUID uuid) throws SQLException { if (uuid == null) { - return false; + return; } try { @@ -215,15 +215,8 @@ public abstract class SQLDB extends Database { } UserIDTable table = (UserIDTable) t; - if (!table.removeUser(uuid)) { - throw new IllegalStateException("Removal Failed"); - } + table.removeUser(uuid); } - - return true; - } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); - return false; } finally { Benchmark.stop("Database", "Remove Account"); setAvailable(); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java index 23e30811e..476890945 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/KillsTable.java @@ -1,7 +1,6 @@ package main.java.com.djrapitops.plan.database.tables; import com.djrapitops.plugin.utilities.Verify; -import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; import main.java.com.djrapitops.plan.data.PlayerKill; @@ -56,7 +55,7 @@ public class KillsTable extends UserIDTable { } @Override - public boolean removeUser(UUID uuid) { + public void removeUser(UUID uuid) throws SQLException{ PreparedStatement statement = null; try { statement = prepareStatement("DELETE FROM " + tableName + @@ -67,10 +66,6 @@ public class KillsTable extends UserIDTable { statement.execute(); commit(statement.getConnection()); - return true; - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); - return false; } finally { close(statement); } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java index a496ccb6a..2a650a86c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UserIDTable.java @@ -1,6 +1,5 @@ package main.java.com.djrapitops.plan.database.tables; -import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.database.databases.SQLDB; import java.sql.PreparedStatement; @@ -23,7 +22,7 @@ public abstract class UserIDTable extends Table { usersTable = db.getUsersTable(); } - public boolean removeUser(UUID uuid) { + public void removeUser(UUID uuid) throws SQLException { PreparedStatement statement = null; try { statement = prepareStatement("DELETE FROM " + tableName + @@ -32,10 +31,6 @@ public abstract class UserIDTable extends Table { statement.execute(); commit(statement.getConnection()); - return true; - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); - return false; } finally { close(statement); } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java index 4520916a1..37c52223b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java @@ -77,7 +77,7 @@ public class UsersTable extends UserIDTable { * @return if the removal was successful. */ @Override - public boolean removeUser(UUID uuid) { + public void removeUser(UUID uuid) throws SQLException { PreparedStatement statement = null; try { statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUUID + "=?)"); @@ -85,9 +85,6 @@ public class UsersTable extends UserIDTable { statement.execute(); commit(statement.getConnection()); - return true; - } catch (SQLException ex) { - return false; } finally { close(statement); } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java index b60e31eff..acffd4a95 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/WorldTimesTable.java @@ -210,7 +210,6 @@ public class WorldTimesTable extends UserIDTable { try { String worldIDColumn = worldTable + "." + worldTable.getColumnID(); String worldNameColumn = worldTable + "." + worldTable.getColumnWorldName() + " as world_name"; - String sessionIDColumn = sessionsTable + "." + sessionsTable.getColumnID(); statement = prepareStatement("SELECT " + "SUM(" + columnSurvival + ") as survival, " + "SUM(" + columnCreative + ") as creative, " + diff --git a/Plan/test/main/java/com/djrapitops/plan/database/tables/ActionsTest.java b/Plan/test/main/java/com/djrapitops/plan/database/tables/ActionsTest.java new file mode 100644 index 000000000..ab4de9473 --- /dev/null +++ b/Plan/test/main/java/com/djrapitops/plan/database/tables/ActionsTest.java @@ -0,0 +1,20 @@ +package main.java.com.djrapitops.plan.database.tables; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class ActionsTest { + + @Test + public void getUnknownActionsEnum() { + Actions action = Actions.getById(Integer.MIN_VALUE); + assertEquals(Actions.UNKNOWN, action); + } + +} \ No newline at end of file