From 57f3a518a044940ae3e2ff0a5c15a4612315aed9 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 7 Feb 2018 18:55:04 +0200 Subject: [PATCH] Attempts at fixing tests where "Another connection wrote to database" --- .../main/java/com/djrapitops/plan/Plan.java | 2 +- .../java/com/djrapitops/plan/PlanBungee.java | 2 +- .../com/djrapitops/plan/ShutdownHook.java | 8 +-- .../plan/command/commands/AnalyzeCommand.java | 4 +- .../plan/command/commands/InspectCommand.java | 4 +- .../command/commands/ListServersCommand.java | 2 +- .../command/commands/QInspectCommand.java | 2 +- .../command/commands/RegisterCommand.java | 2 +- .../plan/command/commands/ReloadCommand.java | 2 +- .../commands/manage/ManageBackupCommand.java | 2 +- .../commands/manage/ManageHotswapCommand.java | 2 +- .../commands/manage/ManageMoveCommand.java | 2 +- .../commands/manage/ManageRemoveCommand.java | 2 +- .../commands/manage/ManageRestoreCommand.java | 2 +- .../commands/manage/ManageSetupCommand.java | 2 +- .../commands/webuser/WebCheckCommand.java | 2 +- .../commands/webuser/WebDeleteCommand.java | 2 +- .../commands/webuser/WebListUsersCommand.java | 2 +- .../plan/data/plugin/HookHandler.java | 6 +- .../data/plugin/PluginsConfigSection.java | 2 +- .../plan/system/cache/DataCache.java | 6 +- .../plan/system/cache/SessionCache.java | 2 +- .../plan/system/database/DBSystem.java | 2 +- .../system/database/databases/sql/SQLDB.java | 6 +- .../database/databases/sql/SQLiteDB.java | 15 ++-- .../database/databases/sql/tables/Table.java | 41 ++++++----- .../plan/system/info/InfoSystem.java | 2 +- .../connection/BukkitConnectionSystem.java | 2 +- .../connection/BungeeConnectionSystem.java | 2 +- .../system/info/connection/ConnectionOut.java | 2 +- .../info/connection/ConnectionSystem.java | 2 +- .../system/info/server/BukkitServerInfo.java | 2 +- .../importing/UserImportRefiner.java | 2 +- .../importing/importers/Importer.java | 8 +-- .../processors/CommandProcessor.java | 2 +- .../processors/TPSInsertProcessor.java | 2 +- .../info/InspectCacheRequestProcessor.java | 2 +- .../info/NetworkPageUpdateProcessor.java | 2 +- .../processors/player/BanAndOpProcessor.java | 2 +- .../player/BungeePlayerRegisterProcessor.java | 2 +- .../player/FirstLeaveProcessor.java | 2 +- .../processors/player/IPUpdateProcessor.java | 2 +- .../processors/player/KickProcessor.java | 2 +- .../processors/player/NameProcessor.java | 4 +- .../processors/player/RegisterProcessor.java | 2 +- .../settings/ServerSpecificSettings.java | 2 +- .../system/settings/WorldAliasSettings.java | 2 +- .../plan/system/settings/locale/Locale.java | 4 +- .../settings/network/NetworkSettings.java | 9 +-- .../system/webserver/ResponseHandler.java | 2 +- .../plan/system/webserver/WebServer.java | 8 +-- .../webserver/pages/PlayerPageHandler.java | 2 +- .../response/errors/ErrorResponse.java | 2 +- .../response/pages/DebugPageResponse.java | 6 +- .../response/pages/PlayersPageResponse.java | 2 +- .../plan/utilities/analysis/Analysis.java | 2 +- .../utilities/file/export/AnalysisExport.java | 2 +- .../utilities/file/export/HtmlExport.java | 6 +- .../utilities/file/export/PlayerExport.java | 2 +- .../system/database/databases/SQLiteTest.java | 14 +++- .../settings/network/NetworkSettingsTest.java | 70 +++++++++++++++++++ .../test/java/utilities/TestErrorManager.java | 2 +- .../java/utilities/mocks/SystemMockUtil.java | 2 + 63 files changed, 194 insertions(+), 117 deletions(-) create mode 100644 Plan/src/test/java/com/djrapitops/plan/system/settings/network/NetworkSettingsTest.java diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 71c0ab552..07282e994 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -80,7 +80,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin { Log.info(Locale.get(Msg.ENABLED).toString()); } catch (Exception e) { Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); onDisable(); } registerCommand("plan", new PlanCommand(this)); diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 4000607ec..98d90d31f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -42,7 +42,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin { Log.info(Locale.get(Msg.ENABLED).toString()); } catch (Exception e) { Log.error("Plugin Failed to Initialize Correctly:"); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } registerCommand("planbungee", new PlanBungeeCommand(this)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java index e7f11935d..6aeceddc0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java @@ -65,13 +65,13 @@ public class ShutdownHook extends Thread { } catch (IllegalStateException ignored) { /* Database is not initialized */ } catch (DBInitException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { if (db != null) { try { db.close(); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } StaticHolder.unRegister(Plan.class); @@ -86,7 +86,7 @@ public class ShutdownHook extends Thread { int messagesSent = entry.getValue(); db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent)); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } @@ -103,7 +103,7 @@ public class ShutdownHook extends Thread { Log.debug("Shutdown: Saving a session: " + session.getSessionStart()); db.save().session(uuid, session); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } activeSessions.clear(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index 288875ad3..187cabb38 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -61,7 +61,7 @@ public class AnalyzeCommand extends SubCommand { } catch (DBException | WebException e) { // TODO Exception handling sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString()); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } }); return true; @@ -93,7 +93,7 @@ public class AnalyzeCommand extends SubCommand { sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register "); } } catch (Exception e) { - Log.toLog(this.getClass().getName() + getName(), e); + Log.toLog(this.getClass() + getName(), e); } }); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index ff7401e18..b1039dc81 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -74,10 +74,10 @@ public class InspectCommand extends SubCommand { } new InspectCacheRequestProcessor(uuid, sender, playerName).queue(); } catch (FatalDBException ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage()); } catch (DBException ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java index 6641ae92a..2837d8b3f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListServersCommand.java @@ -48,7 +48,7 @@ public class ListServersCommand extends SubCommand { sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()); } catch (DBException e) { sender.sendMessage("§cDatabase Exception occurred."); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java index ffe3fb842..f209a1455 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/QInspectCommand.java @@ -82,7 +82,7 @@ public class QInspectCommand extends SubCommand { sendMsgs(sender, playerProfile); } catch (DBException ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); } finally { this.cancel(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java index d42036991..12280ec51 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java @@ -125,7 +125,7 @@ public class RegisterCommand extends SubCommand { sender.sendMessage(successMsg); Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel()); } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { this.cancel(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java index 0ce1f2769..839a3cd4c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ReloadCommand.java @@ -33,7 +33,7 @@ public class ReloadCommand extends SubCommand { try { plugin.reloadPlugin(true); } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); sender.sendMessage("§cSomething went wrong during reload of the plugin, a restart is recommended."); } sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString()); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index e2b72d11c..0718dc194 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -72,7 +72,7 @@ public class ManageBackupCommand extends SubCommand { ManageUtils.backup(args[0], database); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString()); } catch (Exception e) { - Log.toLog(this.getClass().getName() + " " + getTaskName(), e); + Log.toLog(this.getClass() + " " + getTaskName(), e); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java index 6308fb9d3..a77a9b8b9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageHotswapCommand.java @@ -70,7 +70,7 @@ public class ManageHotswapCommand extends SubCommand { return true; } } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString()); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java index 921d80a0e..c37b804ce 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java @@ -84,7 +84,7 @@ public class ManageMoveCommand extends SubCommand { boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName()); Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender); } catch (Exception e) { - Log.toLog(this.getClass().getName() + " " + getTaskName(), e); + Log.toLog(this.getClass() + " " + getTaskName(), e); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); } finally { this.cancel(); 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 53780cb36..2dc0d9ef0 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 @@ -90,7 +90,7 @@ public class ManageRemoveCommand extends SubCommand { } sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, Database.getActive().getConfigName())); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java index c2cea0c0c..c21ffb80c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java @@ -92,7 +92,7 @@ public class ManageRestoreCommand extends SubCommand { sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString()); } catch (Exception e) { - Log.toLog(this.getClass().getName() + " " + getTaskName(), e); + Log.toLog(this.getClass() + " " + getTaskName(), e); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java index b8878488c..4c8e58c9a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java @@ -68,7 +68,7 @@ public class ManageSetupCommand extends SubCommand { } catch (UnauthorizedServerException e) { sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support"); } catch (WebException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console"); } return true; diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java index 73c0c38bc..4723e8a4f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebCheckCommand.java @@ -48,7 +48,7 @@ public class WebCheckCommand extends SubCommand { WebUser info = database.fetch().getWebUser(user); sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel()); } catch (Exception ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java index bc5ff8dc1..cd383a4be 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebDeleteCommand.java @@ -47,7 +47,7 @@ public class WebDeleteCommand extends SubCommand { database.remove().webUser(user); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).parse()); } catch (Exception ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java index a64067828..ba3ecd59a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebListUsersCommand.java @@ -48,7 +48,7 @@ public class WebListUsersCommand extends SubCommand { } sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse()); } catch (Exception ex) { - Log.toLog(this.getClass().getName(), ex); + Log.toLog(this.getClass(), ex); sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse()); } finally { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java index 5873ee134..3dd2a5cb5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/plugin/HookHandler.java @@ -39,7 +39,7 @@ public class HookHandler implements SubSystem { try { Bridge.hook(this); } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); Log.error("Plan Plugin Bridge not included in the plugin jar."); } } @@ -73,7 +73,7 @@ public class HookHandler implements SubSystem { additionalDataSources.add(dataSource); } } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); Log.error("Attempting to register PluginDataSource caused an exception."); } } @@ -100,7 +100,7 @@ public class HookHandler implements SubSystem { } catch (Exception e) { String sourcePlugin = pluginData.getSourcePlugin(); Log.error("PluginData caused exception: " + sourcePlugin); - Log.toLog(this.getClass().getName() + " " + sourcePlugin, e); + Log.toLog(this.getClass() + " " + sourcePlugin, e); } } return containers; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java b/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java index b37cb143e..efcd64f4a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/plugin/PluginsConfigSection.java @@ -35,7 +35,7 @@ public class PluginsConfigSection { section.sort(); section.save(); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java index e3701ae74..ceeaf749e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/DataCache.java @@ -77,7 +77,7 @@ public class DataCache extends SessionCache implements SubSystem { uuids.put(entry.getValue(), entry.getKey()); } } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } @@ -94,7 +94,7 @@ public class DataCache extends SessionCache implements SubSystem { name = db.fetch().getPlayerName(uuid); playerNames.put(uuid, name); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); name = "Error occurred"; } } @@ -119,7 +119,7 @@ public class DataCache extends SessionCache implements SubSystem { return nicknames.get(nicknames.size() - 1); } } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } return cached; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java index d99983086..73cae746f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/cache/SessionCache.java @@ -68,7 +68,7 @@ public class SessionCache { session.endSession(time); Database.getActive().save().session(uuid, session); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { activeSessions.remove(uuid); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java index 12937267b..c727274df 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/DBSystem.java @@ -66,7 +66,7 @@ public abstract class DBSystem implements SubSystem { db.close(); } } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java index 8a53fcfd6..c77965275 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java @@ -120,7 +120,7 @@ public abstract class SQLDB extends Database { clean(); } } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { cancel(); } @@ -157,7 +157,7 @@ public abstract class SQLDB extends Database { try { new Version8TransferTable(db).alterTablesToV10(); } catch (DBInitException | SQLException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } }).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L); @@ -270,7 +270,7 @@ public abstract class SQLDB extends Database { } } catch (SQLException e) { if (!e.getMessage().contains("cannot commit")) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } finally { returnToPool(connection); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java index f87ae8f49..015a2e2a1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLiteDB.java @@ -10,10 +10,7 @@ import com.djrapitops.plugin.task.RunnableFactory; import org.apache.commons.dbcp2.BasicDataSource; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; /** * @author Rsl1122 @@ -52,13 +49,14 @@ public class SQLiteDB extends SQLDB { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); return null; // Should never happen. } String dbFilePath = new File(PlanPlugin.getInstance().getDataFolder(), dbName + ".db").getAbsolutePath(); Connection newConnection = getConnectionFor(dbFilePath); + Log.debug("SQLite: Opened a new Connection"); newConnection.setAutoCommit(false); return newConnection; } @@ -80,22 +78,23 @@ public class SQLiteDB extends SQLDB { @Override public void run() { Statement statement = null; + ResultSet resultSet = null; try { if (connection != null && !connection.isClosed()) { statement = connection.createStatement(); - statement.execute("/* ping */ SELECT 1"); + resultSet = statement.executeQuery("/* ping */ SELECT 1"); } } catch (SQLException e) { Log.debug("Something went wrong during Ping task."); try { connection = getNewConnection(dbName); } catch (SQLException e1) { - Log.toLog(this.getClass().getName(), e1); + Log.toLog(this.getClass(), e1); Log.error("SQLite connection maintaining task had to be closed due to exception."); this.cancel(); } } finally { - MiscUtils.close(statement); + MiscUtils.close(statement, resultSet); } } }).runTaskTimerAsynchronously(60L * 20L, 60L * 20L); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/Table.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/Table.java index 36d32da3f..b68e7b971 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/Table.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/Table.java @@ -9,8 +9,8 @@ import com.djrapitops.plugin.utilities.Verify; import com.google.common.base.Objects; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.SQLException; -import java.sql.Statement; /** * @author Rsl1122 @@ -24,8 +24,8 @@ public abstract class Table { /** * Constructor. * - * @param name Name of the table in the db. - * @param db Database to use. + * @param name Name of the table in the db. + * @param db Database to use. */ public Table(String name, SQLDB db) { this.tableName = name; @@ -71,19 +71,12 @@ public abstract class Table { * @throws SQLException DB error */ protected boolean execute(String statementString) throws SQLException { - Statement statement = null; - Connection connection = null; - try { - connection = getConnection(); - statement = connection.createStatement(); - boolean b = statement.execute(statementString); -// Log.debug("Execute: " + statementString); - commit(connection); - return b; - } finally { - close(statement); - db.returnToPool(connection); - } + return execute(new ExecStatement(statementString) { + @Override + public void prepare(PreparedStatement statement) { + /* No preparations necessary */ + } + }); } /** @@ -176,9 +169,11 @@ public abstract class Table { Connection connection = null; try { connection = getConnection(); - updatedSomething = statement.execute(connection.prepareStatement(statement.getSql())); - commit(connection); + try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) { + updatedSomething = statement.execute(preparedStatement); + } } finally { + commit(connection); db.returnToPool(connection); } return updatedSomething; @@ -188,9 +183,11 @@ public abstract class Table { Connection connection = null; try { connection = getConnection(); - statement.executeBatch(connection.prepareStatement(statement.getSql())); - commit(connection); + try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) { + statement.executeBatch(preparedStatement); + } } finally { + commit(connection); db.returnToPool(connection); } } @@ -199,7 +196,9 @@ public abstract class Table { Connection connection = null; try { connection = getConnection(); - return statement.executeQuery(connection.prepareStatement(statement.getSql())); + try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) { + return statement.executeQuery(preparedStatement); + } } finally { db.returnToPool(connection); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index 97e4ea597..7ff6cc598 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -96,7 +96,7 @@ public abstract class InfoSystem implements SubSystem { /* Ignored */ } catch (WebException e) { // TODO Exception handling - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java index bb99ee788..0bb684306 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java @@ -46,7 +46,7 @@ public class BukkitConnectionSystem extends ConnectionSystem { bukkitServers = database.fetch().getBukkitServers(); latestServerMapRefresh = MiscUtils.getTime(); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java index 30c40ee36..4513cd3b8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java @@ -37,7 +37,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { bukkitServers = Database.getActive().fetch().getBukkitServers(); latestServerMapRefresh = MiscUtils.getTime(); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java index 83d4a1317..552d06e62 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionOut.java @@ -143,7 +143,7 @@ public class ConnectionOut { } catch (NoSuchAlgorithmException | KeyManagementException | IOException e) { if (Settings.DEV_MODE.isTrue()) { Log.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:"); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } ConnectionLog.logConnectionTo(toServer, infoRequest, -1); throw new ConnectionFailException("Connection failed to address: " + address, e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java index a61c96180..4e868b844 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java @@ -98,7 +98,7 @@ public abstract class ConnectionSystem implements SubSystem { } catch (UnsupportedTransferDatabaseException e) { /* Do nothing */ } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } return Optional.empty(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java index a3a1fda6b..36111c66d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java @@ -111,7 +111,7 @@ public class BukkitServerInfo extends ServerInfo { return Optional.of(bungeeInfo.get().getWebAddress()); } } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } return Optional.empty(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/UserImportRefiner.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/UserImportRefiner.java index bc250aa1a..dcfde5fa9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/UserImportRefiner.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/UserImportRefiner.java @@ -153,7 +153,7 @@ public class UserImportRefiner { result = uuidFetcher.call().entrySet().parallelStream() .collect(Collectors.toMap(entry -> entry.getValue().toString(), Map.Entry::getKey)); } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); return; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/importers/Importer.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/importers/Importer.java index a63cc5588..b564c9f81 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/importers/Importer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/importing/importers/Importer.java @@ -67,7 +67,7 @@ public abstract class Importer { try { service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); Thread.currentThread().interrupt(); } @@ -108,7 +108,7 @@ public abstract class Importer { service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } Benchmark.stop(insertDataIntoDatabaseBenchmarkName); @@ -189,7 +189,7 @@ public abstract class Importer { service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } Benchmark.stop(insertDataIntoDatabaseBenchmarkName); @@ -242,7 +242,7 @@ public abstract class Importer { try { execute(); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } }); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java index 875393bb6..05ed0a7bb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/CommandProcessor.java @@ -24,7 +24,7 @@ public class CommandProcessor extends ObjectProcessor { try { Database.getActive().save().commandUsed(object); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/TPSInsertProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/TPSInsertProcessor.java index 706e36847..507edeed0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/TPSInsertProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/TPSInsertProcessor.java @@ -48,7 +48,7 @@ public class TPSInsertProcessor extends ObjectProcessor> { try { Database.getActive().save().insertTPSforThisServer(tps); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/InspectCacheRequestProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/InspectCacheRequestProcessor.java index b56ad17c8..d2782265a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/InspectCacheRequestProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/InspectCacheRequestProcessor.java @@ -44,7 +44,7 @@ public class InspectCacheRequestProcessor extends PlayerProcessor { // TODO Test if this is appropriate sender.sendMessage("§c" + e.getMessage()); } catch (WebException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/NetworkPageUpdateProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/NetworkPageUpdateProcessor.java index a1bb9fbeb..cbbf385d1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/NetworkPageUpdateProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/info/NetworkPageUpdateProcessor.java @@ -21,7 +21,7 @@ public class NetworkPageUpdateProcessor implements Processor { try { InfoSystem.getInstance().updateNetworkPage(); } catch (WebException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BanAndOpProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BanAndOpProcessor.java index 45e479f03..9d9cb350a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BanAndOpProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BanAndOpProcessor.java @@ -35,7 +35,7 @@ public class BanAndOpProcessor extends PlayerProcessor { save.banStatus(uuid, banned); save.opStatus(uuid, opped); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java index 995b6d8f0..9e2e3385d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/BungeePlayerRegisterProcessor.java @@ -36,7 +36,7 @@ public class BungeePlayerRegisterProcessor extends PlayerProcessor { } database.save().registerNewUser(uuid, registered, name); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/FirstLeaveProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/FirstLeaveProcessor.java index 9049bf774..088d7a0fb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/FirstLeaveProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/FirstLeaveProcessor.java @@ -34,7 +34,7 @@ public class FirstLeaveProcessor extends PlayerProcessor { try { Database.getActive().save().action(uuid, leaveAction); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { SessionCache.getInstance().endFirstSessionActionTracking(uuid); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java index e857facb8..b5832411e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/IPUpdateProcessor.java @@ -35,7 +35,7 @@ public class IPUpdateProcessor extends PlayerProcessor { try { Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time)); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/KickProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/KickProcessor.java index 45298f4d7..bccb6970f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/KickProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/KickProcessor.java @@ -26,7 +26,7 @@ public class KickProcessor extends PlayerProcessor { try { Database.getActive().save().playerWasKicked(uuid); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/NameProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/NameProcessor.java index 0ace17488..26d727c75 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/NameProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/NameProcessor.java @@ -54,7 +54,7 @@ public class NameProcessor extends PlayerProcessor { database.save().playerDisplayName(uuid, displayName); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } dataCache.updateNames(uuid, playerName, displayName); @@ -76,7 +76,7 @@ public class NameProcessor extends PlayerProcessor { try { Database.getActive().save().action(uuid, action); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } }); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java index 6cfdacef1..a7ced4c86 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java @@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor { SessionCache.getInstance().markFirstSession(uuid); db.save().action(uuid, new Action(time, Actions.FIRST_SESSION, "Online: " + playersOnline + " Players")); } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { Processor.queueMany(afterProcess); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java index 6b6ab76b4..006290806 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/ServerSpecificSettings.java @@ -88,7 +88,7 @@ public class ServerSpecificSettings { } config.save(); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java index b7b54ffcc..544d54a0c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/WorldAliasSettings.java @@ -59,7 +59,7 @@ public class WorldAliasSettings { try { aliasSect.save(); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } }); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/locale/Locale.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/locale/Locale.java index 0cf257cca..1080ab38d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/locale/Locale.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/locale/Locale.java @@ -74,7 +74,7 @@ public class Locale { loadFromResource("locale_" + locale + ".txt"); } } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { Benchmark.stop("Enable", "Initializing locale"); } @@ -316,7 +316,7 @@ public class Locale { Log.error("Could not find file inside the jar: " + fileName); Log.info("Using Locale: Default (EN)"); } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); Log.info("Using Locale: Default (EN)"); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java index 1c8543b0a..5153d7a92 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/settings/network/NetworkSettings.java @@ -31,10 +31,6 @@ public class NetworkSettings { private static final String SPLIT = ";;SETTING;;"; private static final String VAL_SPLIT = ";;VALUE;;"; - private NetworkSettings() { - /* Hides Constructor */ - } - public static void loadSettingsFromDB() { if (Check.isBungeeAvailable()) { return; @@ -69,7 +65,7 @@ public class NetworkSettings { }); } - private void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException { + public void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException { Optional encodedConfigSettings = Database.getActive().transfer().getEncodedConfigSettings(); if (!encodedConfigSettings.isPresent()) { @@ -78,7 +74,6 @@ public class NetworkSettings { } String configSettings = Base64Util.decode(encodedConfigSettings.get()); - Map pathValueMap = getPathsAndValues(configSettings); ServerSpecificSettings.updateSettings(pathValueMap); @@ -110,7 +105,7 @@ public class NetworkSettings { return pathValueMap; } - private void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException { + public void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException { Map configValues = getConfigValues(); StringBuilder transferBuilder = new StringBuilder(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java index ba25bf301..59ac55879 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/ResponseHandler.java @@ -80,7 +80,7 @@ public class ResponseHandler extends TreePageHandler { return new InternalErrorResponse(request.getTarget(), e); } } catch (Exception e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); return new InternalErrorResponse(request.getTarget(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java index 7782a819c..2cb3bb406 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/WebServer.java @@ -114,7 +114,7 @@ public class WebServer implements SubSystem { Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()) + " (" + getAccessAddress() + ")"); } catch (IllegalArgumentException | IllegalStateException | IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); enabled = false; } } @@ -164,16 +164,16 @@ public class WebServer implements SubSystem { startSuccessful = true; } catch (KeyManagementException | NoSuchAlgorithmException e) { Log.error("WebServer: SSL Context Initialization Failed."); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } catch (FileNotFoundException e) { Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath); Log.info("No Certificate -> Using Http server for Visualization."); } catch (IOException e) { Log.error("WebServer: " + e); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) { Log.error("WebServer: SSL Certificate loading Failed."); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } return startSuccessful; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java index 82ba87355..a081c118d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/PlayerPageHandler.java @@ -58,7 +58,7 @@ public class PlayerPageHandler extends PageHandler { return notFound("Player has not played on this server."); } } catch (DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); throw new InternalErrorException("Analysis", e); } catch (NoServersException e) { ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> new NotFoundResponse(e.getMessage())); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/errors/ErrorResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/errors/ErrorResponse.java index 47bfdb8fe..26a50d66f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/errors/ErrorResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/errors/ErrorResponse.java @@ -29,7 +29,7 @@ public class ErrorResponse extends Response { try { setContent(Theme.replaceColors(FileUtil.getStringFromResource("web/error.html"))); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java index 8f1149c91..23e7a81a1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java @@ -122,7 +122,7 @@ public class DebugPageResponse extends ErrorResponse { try { content.append(" schema v").append(((SQLDB) database).getVersion()); } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } @@ -165,7 +165,7 @@ public class DebugPageResponse extends ErrorResponse { content.append("```"); } } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } @@ -210,7 +210,7 @@ public class DebugPageResponse extends ErrorResponse { } content.append(""); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java index e89c77c19..ace6d0bfc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java @@ -49,7 +49,7 @@ public class PlayersPageResponse extends Response { replace.put("version", plugin.getVersion()); super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("web/players.html"), replace))); } catch (DBException | IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); setContent(new InternalErrorResponse("/players", e).getContent()); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 7db836fe1..0df7dc81f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -132,7 +132,7 @@ public class Analysis { } catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) { Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin()); - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/AnalysisExport.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/AnalysisExport.java index 92a8d4d69..d61cae6e1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/AnalysisExport.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/AnalysisExport.java @@ -37,7 +37,7 @@ public class AnalysisExport extends SpecificExport { exportAvailableServerPage(serverUUID, serverName); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { try { this.cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java index 6a6b5febe..d9563ec0b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/HtmlExport.java @@ -71,7 +71,7 @@ public class HtmlExport extends SpecificExport { exportAvailablePlayers(); exportPlayersPage(); } catch (IOException | DBException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { try { this.cancel(); @@ -149,7 +149,7 @@ public class HtmlExport extends SpecificExport { outputFolder.mkdirs(); export(new File(outputFolder, "demo.js"), lines); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } @@ -174,7 +174,7 @@ public class HtmlExport extends SpecificExport { try { copyFromJar(resource); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/PlayerExport.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/PlayerExport.java index c70a2a2da..7224c3552 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/PlayerExport.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/export/PlayerExport.java @@ -37,7 +37,7 @@ public class PlayerExport extends SpecificExport { exportAvailablePlayerPage(uuid, name); } catch (IOException e) { - Log.toLog(this.getClass().getName(), e); + Log.toLog(this.getClass(), e); } finally { try { this.cancel(); diff --git a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java index 8723e6a51..60548a570 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java @@ -20,6 +20,7 @@ import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor; import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.utilities.Base64Util; import com.djrapitops.plan.utilities.ManageUtils; import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.analysis.MathUtils; @@ -846,7 +847,6 @@ public class SQLiteTest { } @Test - @Ignore public void testRegisterProcessorRegisterException() throws SQLException { assertFalse(db.getUsersTable().isRegistered(playerUUID)); assertFalse(db.getUserInfoTable().isRegistered(playerUUID)); @@ -871,4 +871,16 @@ public class SQLiteTest { public void testWorldTableGetWorldNamesNoException() throws SQLException { Set worldNames = db.getWorldTable().getWorldNames(); } + + @Test + public void testSettingTransfer() throws SQLException { + String testString = RandomData.randomString(100); + + TransferTable transferTable = db.getTransferTable(); + transferTable.storeConfigSettings(Base64Util.encode(testString)); + Optional configSettings = transferTable.getConfigSettings(); + + assertTrue(configSettings.isPresent()); + assertEquals(testString, Base64Util.decode(configSettings.get())); + } } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/settings/network/NetworkSettingsTest.java b/Plan/src/test/java/com/djrapitops/plan/system/settings/network/NetworkSettingsTest.java new file mode 100644 index 000000000..9b0973bb5 --- /dev/null +++ b/Plan/src/test/java/com/djrapitops/plan/system/settings/network/NetworkSettingsTest.java @@ -0,0 +1,70 @@ +package com.djrapitops.plan.system.settings.network; + +import com.djrapitops.plan.Plan; +import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException; +import com.djrapitops.plan.api.exceptions.database.DBException; +import com.djrapitops.plan.system.database.databases.sql.SQLDB; +import com.djrapitops.plan.system.database.databases.sql.SQLiteDB; +import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable; +import com.djrapitops.plan.system.info.server.Server; +import com.djrapitops.plan.system.info.server.ServerInfo; +import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plugin.StaticHolder; +import com.djrapitops.plugin.api.utility.log.Log; +import org.junit.*; +import org.junit.rules.TemporaryFolder; +import utilities.Teardown; +import utilities.TestConstants; +import utilities.TestErrorManager; +import utilities.mocks.SystemMockUtil; + +import java.sql.SQLException; + +import static org.junit.Assert.assertEquals; + +public class NetworkSettingsTest { + + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + private static SQLDB db; + + @BeforeClass + public static void setUpClass() throws Exception { + Teardown.resetSettingsTempValues(); + StaticHolder.saveInstance(NetworkSettingsTest.class, Plan.class); + + db = new SQLiteDB(); + SystemMockUtil.setUp(temporaryFolder.getRoot()) + .enableConfigSystem() + .enableDatabaseSystem(db) + .enableServerInfoSystem(); + + Log.setErrorManager(new TestErrorManager()); + Log.setDebugMode("console"); + Settings.DEV_MODE.setTemporaryValue(true); + } + + @AfterClass + public static void tearDownClass() { + if (db != null) { + db.close(); + } + Teardown.resetSettingsTempValues(); + } + + @Before + public void setUp() throws DBException, SQLException { + db.remove().everything(); + ServerTable serverTable = db.getServerTable(); + serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20)); + assertEquals(ServerInfo.getServerUUID(), TestConstants.SERVER_UUID); + } + + @Test + public void testTransfer() throws DBException, UnsupportedTransferDatabaseException { + NetworkSettings networkSettings = new NetworkSettings(); + networkSettings.placeToDatabase(); + networkSettings.loadFromDatabase(); + } + +} \ No newline at end of file diff --git a/Plan/src/test/java/utilities/TestErrorManager.java b/Plan/src/test/java/utilities/TestErrorManager.java index e27914b14..292a40224 100644 --- a/Plan/src/test/java/utilities/TestErrorManager.java +++ b/Plan/src/test/java/utilities/TestErrorManager.java @@ -15,6 +15,6 @@ public class TestErrorManager extends ErrorManager { @Override public void toLog(String s, Throwable throwable, Class aClass) { - throw new IllegalStateException(throwable); + throw new RuntimeException("Error During Test.", throwable); } } \ No newline at end of file diff --git a/Plan/src/test/java/utilities/mocks/SystemMockUtil.java b/Plan/src/test/java/utilities/mocks/SystemMockUtil.java index af9ef4bce..4c3515763 100644 --- a/Plan/src/test/java/utilities/mocks/SystemMockUtil.java +++ b/Plan/src/test/java/utilities/mocks/SystemMockUtil.java @@ -9,6 +9,7 @@ import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.system.BukkitSystem; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.databases.sql.SQLDB; +import com.djrapitops.plugin.StaticHolder; import java.io.File; @@ -22,6 +23,7 @@ public class SystemMockUtil { private BukkitSystem bukkitSystem; public static SystemMockUtil setUp(File dataFolder) throws Exception { + StaticHolder.saveInstance(SystemMockUtil.class, Plan.class); return new SystemMockUtil().initializeBukkitSystem(dataFolder); }