From 2e9f6148d67938169c3f09ba5b27b168b590a485 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 14 Feb 2019 22:47:19 +0200 Subject: [PATCH] Fixed Smells, Level Minor (SonarCloud): - Function in GeoInfoStoreTransaction - Unused throws clause in Version10Patch - Bad variable name in UsersTable - Fixed WorldTimesQueries again --- .../queries/objects/WorldTimesQueries.java | 2 +- .../events/GeoInfoStoreTransaction.java | 6 ++--- .../plan/db/patches/Version10Patch.java | 24 +++++++------------ .../plan/db/sql/tables/UsersTable.java | 10 ++++---- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java index 0bc1f9312..7f80fc076 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/objects/WorldTimesQueries.java @@ -45,7 +45,7 @@ public class WorldTimesQueries { "SUM(" + WorldTimesTable.CREATIVE + ") as creative, " + "SUM(" + WorldTimesTable.ADVENTURE + ") as adventure, " + "SUM(" + WorldTimesTable.SPECTATOR + ") as spectator, " + - WorldTimesTable.SERVER_UUID + ", " + + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + ", " + WorldTable.TABLE_NAME + "." + WorldTable.NAME + " as " + worldColumn + FROM + WorldTimesTable.TABLE_NAME + " INNER JOIN " + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + "." + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java index a5a8148d2..ac5392f91 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/events/GeoInfoStoreTransaction.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.db.access.transactions.Transaction; import java.net.InetAddress; import java.security.NoSuchAlgorithmException; import java.util.UUID; -import java.util.function.Function; +import java.util.function.UnaryOperator; /** * Transaction to update Geo information of a player in the database. @@ -37,7 +37,7 @@ public class GeoInfoStoreTransaction extends Transaction { private final UUID playerUUID; private InetAddress ip; private long time; - private Function geolocationFunction; + private UnaryOperator geolocationFunction; private GeoInfo geoInfo; @@ -45,7 +45,7 @@ public class GeoInfoStoreTransaction extends Transaction { UUID playerUUID, InetAddress ip, long time, - Function geolocationFunction + UnaryOperator geolocationFunction ) { this.playerUUID = playerUUID; this.ip = ip; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Version10Patch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Version10Patch.java index 9f64c1ea6..d2447e847 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Version10Patch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Version10Patch.java @@ -16,8 +16,6 @@ */ package com.djrapitops.plan.db.patches; -import com.djrapitops.plan.api.exceptions.database.DBInitException; -import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.sql.tables.*; @@ -40,19 +38,15 @@ public class Version10Patch extends Patch { @Override protected void applyPatch() { - try { - Optional fetchedServerID = db.getServerTable().getServerID(getServerUUID()); - if (!fetchedServerID.isPresent()) { - throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin."); - } - serverID = fetchedServerID.get(); - alterTablesToV10(); - } catch (DBInitException e) { - throw new DBOpException(e.getMessage(), e); + Optional fetchedServerID = db.getServerTable().getServerID(getServerUUID()); + if (!fetchedServerID.isPresent()) { + throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin."); } + serverID = fetchedServerID.get(); + alterTablesToV10(); } - public void alterTablesToV10() throws DBInitException { + public void alterTablesToV10() { copyCommandUsage(); copyTPS(); @@ -73,7 +67,7 @@ public class Version10Patch extends Patch { dropTable("temp_users"); } - private void copyUsers() throws DBInitException { + private void copyUsers() { String tempTableName = "temp_users"; renameTable(UsersTable.TABLE_NAME, tempTableName); @@ -113,7 +107,7 @@ public class Version10Patch extends Patch { execute(statement); } - private void copyCommandUsage() throws DBInitException { + private void copyCommandUsage() { String tempTableName = "temp_cmdusg"; renameTable("plan_commandusages", tempTableName); @@ -129,7 +123,7 @@ public class Version10Patch extends Patch { dropTable(tempTableName); } - private void copyTPS() throws DBInitException { + private void copyTPS() { String tempTableName = "temp_tps"; TPSTable tpsTable = db.getTpsTable(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/UsersTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/UsersTable.java index c08bfaa2c..37b4072de 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/UsersTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/UsersTable.java @@ -289,14 +289,14 @@ public class UsersTable extends Table { } public DataContainer getUserInformation(UUID uuid) { - Key user_data = new Key<>(DataContainer.class, "plan_users_data"); + Key key = new Key<>(DataContainer.class, "plan_users_data"); DataContainer returnValue = new SupplierDataContainer(); - returnValue.putSupplier(user_data, () -> getUserInformationDataContainer(uuid)); + returnValue.putSupplier(key, () -> getUserInformationDataContainer(uuid)); returnValue.putRawData(PlayerKeys.UUID, uuid); - returnValue.putSupplier(PlayerKeys.REGISTERED, () -> returnValue.getUnsafe(user_data).getValue(PlayerKeys.REGISTERED).orElse(null)); - returnValue.putSupplier(PlayerKeys.NAME, () -> returnValue.getUnsafe(user_data).getValue(PlayerKeys.NAME).orElse(null)); - returnValue.putSupplier(PlayerKeys.KICK_COUNT, () -> returnValue.getUnsafe(user_data).getValue(PlayerKeys.KICK_COUNT).orElse(null)); + returnValue.putSupplier(PlayerKeys.REGISTERED, () -> returnValue.getUnsafe(key).getValue(PlayerKeys.REGISTERED).orElse(null)); + returnValue.putSupplier(PlayerKeys.NAME, () -> returnValue.getUnsafe(key).getValue(PlayerKeys.NAME).orElse(null)); + returnValue.putSupplier(PlayerKeys.KICK_COUNT, () -> returnValue.getUnsafe(key).getValue(PlayerKeys.KICK_COUNT).orElse(null)); return returnValue; }