mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +01:00
Attempts at fixing tests where "Another connection wrote to database"
This commit is contained in:
parent
1945984fc4
commit
57f3a518a0
@ -80,7 +80,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
|
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();
|
onDisable();
|
||||||
}
|
}
|
||||||
registerCommand("plan", new PlanCommand(this));
|
registerCommand("plan", new PlanCommand(this));
|
||||||
|
@ -42,7 +42,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
|||||||
Log.info(Locale.get(Msg.ENABLED).toString());
|
Log.info(Locale.get(Msg.ENABLED).toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.error("Plugin Failed to Initialize Correctly:");
|
Log.error("Plugin Failed to Initialize Correctly:");
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
registerCommand("planbungee", new PlanBungeeCommand(this));
|
registerCommand("planbungee", new PlanBungeeCommand(this));
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,13 @@ public class ShutdownHook extends Thread {
|
|||||||
} catch (IllegalStateException ignored) {
|
} catch (IllegalStateException ignored) {
|
||||||
/* Database is not initialized */
|
/* Database is not initialized */
|
||||||
} catch (DBInitException e) {
|
} catch (DBInitException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
db.close();
|
db.close();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StaticHolder.unRegister(Plan.class);
|
StaticHolder.unRegister(Plan.class);
|
||||||
@ -86,7 +86,7 @@ public class ShutdownHook extends Thread {
|
|||||||
int messagesSent = entry.getValue();
|
int messagesSent = entry.getValue();
|
||||||
db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
|
db.save().action(uuid, new Action(now, Actions.FIRST_LOGOUT, "Messages sent: " + messagesSent));
|
||||||
} catch (DBException e) {
|
} 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());
|
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
|
||||||
db.save().session(uuid, session);
|
db.save().session(uuid, session);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activeSessions.clear();
|
activeSessions.clear();
|
||||||
|
@ -61,7 +61,7 @@ public class AnalyzeCommand extends SubCommand {
|
|||||||
} catch (DBException | WebException e) {
|
} catch (DBException | WebException e) {
|
||||||
// TODO Exception handling
|
// TODO Exception handling
|
||||||
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
|
sender.sendMessage(ChatColor.RED + " Error occurred: " + e.toString());
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
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 <password>");
|
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName() + getName(), e);
|
Log.toLog(this.getClass() + getName(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,10 @@ public class InspectCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
new InspectCacheRequestProcessor(uuid, sender, playerName).queue();
|
new InspectCacheRequestProcessor(uuid, sender, playerName).queue();
|
||||||
} catch (FatalDBException ex) {
|
} catch (FatalDBException ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass(), ex);
|
||||||
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + "Fatal database exception occurred: " + ex.getMessage());
|
||||||
} catch (DBException ex) {
|
} 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());
|
sender.sendMessage(ChatColor.YELLOW + "Non-Fatal database exception occurred: " + ex.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -48,7 +48,7 @@ public class ListServersCommand extends SubCommand {
|
|||||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
sender.sendMessage("§cDatabase Exception occurred.");
|
sender.sendMessage("§cDatabase Exception occurred.");
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class QInspectCommand extends SubCommand {
|
|||||||
sendMsgs(sender, playerProfile);
|
sendMsgs(sender, playerProfile);
|
||||||
|
|
||||||
} catch (DBException ex) {
|
} catch (DBException ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ public class RegisterCommand extends SubCommand {
|
|||||||
sender.sendMessage(successMsg);
|
sender.sendMessage(successMsg);
|
||||||
Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel());
|
Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class ReloadCommand extends SubCommand {
|
|||||||
try {
|
try {
|
||||||
plugin.reloadPlugin(true);
|
plugin.reloadPlugin(true);
|
||||||
} catch (Exception e) {
|
} 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("§cSomething went wrong during reload of the plugin, a restart is recommended.");
|
||||||
}
|
}
|
||||||
sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString());
|
sender.sendMessage(Locale.get(Msg.CMD_INFO_RELOAD_COMPLETE).toString());
|
||||||
|
@ -72,7 +72,7 @@ public class ManageBackupCommand extends SubCommand {
|
|||||||
ManageUtils.backup(args[0], database);
|
ManageUtils.backup(args[0], database);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||||
} catch (Exception e) {
|
} 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());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -70,7 +70,7 @@ public class ManageHotswapCommand extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
sender.sendMessage(Locale.get(Msg.MANAGE_FAIL_FAULTY_DB).toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class ManageMoveCommand extends SubCommand {
|
|||||||
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName());
|
boolean movedToCurrentDatabase = Verify.equalsIgnoreCase(toDatabase.getConfigName(), Database.getActive().getConfigName());
|
||||||
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
|
Condition.isTrue(!movedToCurrentDatabase, Locale.get(Msg.MANAGE_INFO_CONFIG_REMINDER).toString(), sender);
|
||||||
} catch (Exception e) {
|
} 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());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -90,7 +90,7 @@ public class ManageRemoveCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, Database.getActive().getConfigName()));
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_REMOVE_SUCCESS).parse(playerName, Database.getActive().getConfigName()));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -92,7 +92,7 @@ public class ManageRestoreCommand extends SubCommand {
|
|||||||
|
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_COPY_SUCCESS).toString());
|
||||||
} catch (Exception e) {
|
} 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());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).toString());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -68,7 +68,7 @@ public class ManageSetupCommand extends SubCommand {
|
|||||||
} catch (UnauthorizedServerException e) {
|
} catch (UnauthorizedServerException e) {
|
||||||
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
||||||
} catch (WebException e) {
|
} 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");
|
sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -48,7 +48,7 @@ public class WebCheckCommand extends SubCommand {
|
|||||||
WebUser info = database.fetch().getWebUser(user);
|
WebUser info = database.fetch().getWebUser(user);
|
||||||
sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel());
|
sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass(), ex);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -47,7 +47,7 @@ public class WebDeleteCommand extends SubCommand {
|
|||||||
database.remove().webUser(user);
|
database.remove().webUser(user);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).parse());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).parse());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass(), ex);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -48,7 +48,7 @@ public class WebListUsersCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse());
|
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
Log.toLog(this.getClass(), ex);
|
||||||
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_FAIL).parse());
|
||||||
} finally {
|
} finally {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -39,7 +39,7 @@ public class HookHandler implements SubSystem {
|
|||||||
try {
|
try {
|
||||||
Bridge.hook(this);
|
Bridge.hook(this);
|
||||||
} catch (Exception e) {
|
} 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.");
|
Log.error("Plan Plugin Bridge not included in the plugin jar.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public class HookHandler implements SubSystem {
|
|||||||
additionalDataSources.add(dataSource);
|
additionalDataSources.add(dataSource);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
Log.error("Attempting to register PluginDataSource caused an exception.");
|
Log.error("Attempting to register PluginDataSource caused an exception.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ public class HookHandler implements SubSystem {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String sourcePlugin = pluginData.getSourcePlugin();
|
String sourcePlugin = pluginData.getSourcePlugin();
|
||||||
Log.error("PluginData caused exception: " + sourcePlugin);
|
Log.error("PluginData caused exception: " + sourcePlugin);
|
||||||
Log.toLog(this.getClass().getName() + " " + sourcePlugin, e);
|
Log.toLog(this.getClass() + " " + sourcePlugin, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return containers;
|
return containers;
|
||||||
|
@ -35,7 +35,7 @@ public class PluginsConfigSection {
|
|||||||
section.sort();
|
section.sort();
|
||||||
section.save();
|
section.save();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||||||
uuids.put(entry.getValue(), entry.getKey());
|
uuids.put(entry.getValue(), entry.getKey());
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} 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);
|
name = db.fetch().getPlayerName(uuid);
|
||||||
playerNames.put(uuid, name);
|
playerNames.put(uuid, name);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
name = "Error occurred";
|
name = "Error occurred";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ public class DataCache extends SessionCache implements SubSystem {
|
|||||||
return nicknames.get(nicknames.size() - 1);
|
return nicknames.get(nicknames.size() - 1);
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cached;
|
return cached;
|
||||||
|
@ -68,7 +68,7 @@ public class SessionCache {
|
|||||||
session.endSession(time);
|
session.endSession(time);
|
||||||
Database.getActive().save().session(uuid, session);
|
Database.getActive().save().session(uuid, session);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
activeSessions.remove(uuid);
|
activeSessions.remove(uuid);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public abstract class DBSystem implements SubSystem {
|
|||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public abstract class SQLDB extends Database {
|
|||||||
clean();
|
clean();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ public abstract class SQLDB extends Database {
|
|||||||
try {
|
try {
|
||||||
new Version8TransferTable(db).alterTablesToV10();
|
new Version8TransferTable(db).alterTablesToV10();
|
||||||
} catch (DBInitException | SQLException e) {
|
} catch (DBInitException | SQLException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
|
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 5L);
|
||||||
@ -270,7 +270,7 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (!e.getMessage().contains("cannot commit")) {
|
if (!e.getMessage().contains("cannot commit")) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
returnToPool(connection);
|
returnToPool(connection);
|
||||||
|
@ -10,10 +10,7 @@ import com.djrapitops.plugin.task.RunnableFactory;
|
|||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -52,13 +49,14 @@ public class SQLiteDB extends SQLDB {
|
|||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
return null; // Should never happen.
|
return null; // Should never happen.
|
||||||
}
|
}
|
||||||
|
|
||||||
String dbFilePath = new File(PlanPlugin.getInstance().getDataFolder(), dbName + ".db").getAbsolutePath();
|
String dbFilePath = new File(PlanPlugin.getInstance().getDataFolder(), dbName + ".db").getAbsolutePath();
|
||||||
|
|
||||||
Connection newConnection = getConnectionFor(dbFilePath);
|
Connection newConnection = getConnectionFor(dbFilePath);
|
||||||
|
Log.debug("SQLite: Opened a new Connection");
|
||||||
newConnection.setAutoCommit(false);
|
newConnection.setAutoCommit(false);
|
||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
@ -80,22 +78,23 @@ public class SQLiteDB extends SQLDB {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
try {
|
try {
|
||||||
if (connection != null && !connection.isClosed()) {
|
if (connection != null && !connection.isClosed()) {
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
statement.execute("/* ping */ SELECT 1");
|
resultSet = statement.executeQuery("/* ping */ SELECT 1");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.debug("Something went wrong during Ping task.");
|
Log.debug("Something went wrong during Ping task.");
|
||||||
try {
|
try {
|
||||||
connection = getNewConnection(dbName);
|
connection = getNewConnection(dbName);
|
||||||
} catch (SQLException e1) {
|
} 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.");
|
Log.error("SQLite connection maintaining task had to be closed due to exception.");
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
MiscUtils.close(statement);
|
MiscUtils.close(statement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
|
}).runTaskTimerAsynchronously(60L * 20L, 60L * 20L);
|
||||||
|
@ -9,8 +9,8 @@ import com.djrapitops.plugin.utilities.Verify;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
@ -71,19 +71,12 @@ public abstract class Table {
|
|||||||
* @throws SQLException DB error
|
* @throws SQLException DB error
|
||||||
*/
|
*/
|
||||||
protected boolean execute(String statementString) throws SQLException {
|
protected boolean execute(String statementString) throws SQLException {
|
||||||
Statement statement = null;
|
return execute(new ExecStatement(statementString) {
|
||||||
Connection connection = null;
|
@Override
|
||||||
try {
|
public void prepare(PreparedStatement statement) {
|
||||||
connection = getConnection();
|
/* No preparations necessary */
|
||||||
statement = connection.createStatement();
|
|
||||||
boolean b = statement.execute(statementString);
|
|
||||||
// Log.debug("Execute: " + statementString);
|
|
||||||
commit(connection);
|
|
||||||
return b;
|
|
||||||
} finally {
|
|
||||||
close(statement);
|
|
||||||
db.returnToPool(connection);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,9 +169,11 @@ public abstract class Table {
|
|||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
updatedSomething = statement.execute(connection.prepareStatement(statement.getSql()));
|
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
|
||||||
commit(connection);
|
updatedSomething = statement.execute(preparedStatement);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
commit(connection);
|
||||||
db.returnToPool(connection);
|
db.returnToPool(connection);
|
||||||
}
|
}
|
||||||
return updatedSomething;
|
return updatedSomething;
|
||||||
@ -188,9 +183,11 @@ public abstract class Table {
|
|||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
statement.executeBatch(connection.prepareStatement(statement.getSql()));
|
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
|
||||||
commit(connection);
|
statement.executeBatch(preparedStatement);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
commit(connection);
|
||||||
db.returnToPool(connection);
|
db.returnToPool(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +196,9 @@ public abstract class Table {
|
|||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
try {
|
try {
|
||||||
connection = getConnection();
|
connection = getConnection();
|
||||||
return statement.executeQuery(connection.prepareStatement(statement.getSql()));
|
try (PreparedStatement preparedStatement = connection.prepareStatement(statement.getSql())) {
|
||||||
|
return statement.executeQuery(preparedStatement);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
db.returnToPool(connection);
|
db.returnToPool(connection);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public abstract class InfoSystem implements SubSystem {
|
|||||||
/* Ignored */
|
/* Ignored */
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
// TODO Exception handling
|
// TODO Exception handling
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
|||||||
bukkitServers = database.fetch().getBukkitServers();
|
bukkitServers = database.fetch().getBukkitServers();
|
||||||
latestServerMapRefresh = MiscUtils.getTime();
|
latestServerMapRefresh = MiscUtils.getTime();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
|||||||
bukkitServers = Database.getActive().fetch().getBukkitServers();
|
bukkitServers = Database.getActive().fetch().getBukkitServers();
|
||||||
latestServerMapRefresh = MiscUtils.getTime();
|
latestServerMapRefresh = MiscUtils.getTime();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ public class ConnectionOut {
|
|||||||
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
|
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
|
||||||
if (Settings.DEV_MODE.isTrue()) {
|
if (Settings.DEV_MODE.isTrue()) {
|
||||||
Log.warn("THIS ERROR IS ONLY LOGGED IN DEV MODE:");
|
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);
|
ConnectionLog.logConnectionTo(toServer, infoRequest, -1);
|
||||||
throw new ConnectionFailException("Connection failed to address: " + address, e);
|
throw new ConnectionFailException("Connection failed to address: " + address, e);
|
||||||
|
@ -98,7 +98,7 @@ public abstract class ConnectionSystem implements SubSystem {
|
|||||||
} catch (UnsupportedTransferDatabaseException e) {
|
} catch (UnsupportedTransferDatabaseException e) {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class BukkitServerInfo extends ServerInfo {
|
|||||||
return Optional.of(bungeeInfo.get().getWebAddress());
|
return Optional.of(bungeeInfo.get().getWebAddress());
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ public class UserImportRefiner {
|
|||||||
result = uuidFetcher.call().entrySet().parallelStream()
|
result = uuidFetcher.call().entrySet().parallelStream()
|
||||||
.collect(Collectors.toMap(entry -> entry.getValue().toString(), Map.Entry::getKey));
|
.collect(Collectors.toMap(entry -> entry.getValue().toString(), Map.Entry::getKey));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public abstract class Importer {
|
|||||||
try {
|
try {
|
||||||
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public abstract class Importer {
|
|||||||
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
|
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
|
||||||
@ -189,7 +189,7 @@ public abstract class Importer {
|
|||||||
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
|
Benchmark.stop(insertDataIntoDatabaseBenchmarkName);
|
||||||
@ -242,7 +242,7 @@ public abstract class Importer {
|
|||||||
try {
|
try {
|
||||||
execute();
|
execute();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ public class CommandProcessor extends ObjectProcessor<String> {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().commandUsed(object);
|
Database.getActive().save().commandUsed(object);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,7 +48,7 @@ public class TPSInsertProcessor extends ObjectProcessor<List<TPS>> {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().insertTPSforThisServer(tps);
|
Database.getActive().save().insertTPSforThisServer(tps);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ public class InspectCacheRequestProcessor extends PlayerProcessor {
|
|||||||
// TODO Test if this is appropriate
|
// TODO Test if this is appropriate
|
||||||
sender.sendMessage("§c" + e.getMessage());
|
sender.sendMessage("§c" + e.getMessage());
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class NetworkPageUpdateProcessor implements Processor {
|
|||||||
try {
|
try {
|
||||||
InfoSystem.getInstance().updateNetworkPage();
|
InfoSystem.getInstance().updateNetworkPage();
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ public class BanAndOpProcessor extends PlayerProcessor {
|
|||||||
save.banStatus(uuid, banned);
|
save.banStatus(uuid, banned);
|
||||||
save.opStatus(uuid, opped);
|
save.opStatus(uuid, opped);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ public class BungeePlayerRegisterProcessor extends PlayerProcessor {
|
|||||||
}
|
}
|
||||||
database.save().registerNewUser(uuid, registered, name);
|
database.save().registerNewUser(uuid, registered, name);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,7 +34,7 @@ public class FirstLeaveProcessor extends PlayerProcessor {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().action(uuid, leaveAction);
|
Database.getActive().save().action(uuid, leaveAction);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
SessionCache.getInstance().endFirstSessionActionTracking(uuid);
|
SessionCache.getInstance().endFirstSessionActionTracking(uuid);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class IPUpdateProcessor extends PlayerProcessor {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time));
|
Database.getActive().save().geoInfo(uuid, new GeoInfo(ip, country, time));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ public class KickProcessor extends PlayerProcessor {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().playerWasKicked(uuid);
|
Database.getActive().save().playerWasKicked(uuid);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,7 +54,7 @@ public class NameProcessor extends PlayerProcessor {
|
|||||||
|
|
||||||
database.save().playerDisplayName(uuid, displayName);
|
database.save().playerDisplayName(uuid, displayName);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataCache.updateNames(uuid, playerName, displayName);
|
dataCache.updateNames(uuid, playerName, displayName);
|
||||||
@ -76,7 +76,7 @@ public class NameProcessor extends PlayerProcessor {
|
|||||||
try {
|
try {
|
||||||
Database.getActive().save().action(uuid, action);
|
Database.getActive().save().action(uuid, action);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class RegisterProcessor extends PlayerProcessor {
|
|||||||
SessionCache.getInstance().markFirstSession(uuid);
|
SessionCache.getInstance().markFirstSession(uuid);
|
||||||
db.save().action(uuid, new Action(time, Actions.FIRST_SESSION, "Online: " + playersOnline + " Players"));
|
db.save().action(uuid, new Action(time, Actions.FIRST_SESSION, "Online: " + playersOnline + " Players"));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
Processor.queueMany(afterProcess);
|
Processor.queueMany(afterProcess);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class ServerSpecificSettings {
|
|||||||
}
|
}
|
||||||
config.save();
|
config.save();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class WorldAliasSettings {
|
|||||||
try {
|
try {
|
||||||
aliasSect.save();
|
aliasSect.save();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class Locale {
|
|||||||
loadFromResource("locale_" + locale + ".txt");
|
loadFromResource("locale_" + locale + ".txt");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
Benchmark.stop("Enable", "Initializing locale");
|
Benchmark.stop("Enable", "Initializing locale");
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ public class Locale {
|
|||||||
Log.error("Could not find file inside the jar: " + fileName);
|
Log.error("Could not find file inside the jar: " + fileName);
|
||||||
Log.info("Using Locale: Default (EN)");
|
Log.info("Using Locale: Default (EN)");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
Log.info("Using Locale: Default (EN)");
|
Log.info("Using Locale: Default (EN)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,6 @@ public class NetworkSettings {
|
|||||||
private static final String SPLIT = ";;SETTING;;";
|
private static final String SPLIT = ";;SETTING;;";
|
||||||
private static final String VAL_SPLIT = ";;VALUE;;";
|
private static final String VAL_SPLIT = ";;VALUE;;";
|
||||||
|
|
||||||
private NetworkSettings() {
|
|
||||||
/* Hides Constructor */
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadSettingsFromDB() {
|
public static void loadSettingsFromDB() {
|
||||||
if (Check.isBungeeAvailable()) {
|
if (Check.isBungeeAvailable()) {
|
||||||
return;
|
return;
|
||||||
@ -69,7 +65,7 @@ public class NetworkSettings {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException {
|
public void loadFromDatabase() throws DBException, UnsupportedTransferDatabaseException {
|
||||||
Optional<String> encodedConfigSettings = Database.getActive().transfer().getEncodedConfigSettings();
|
Optional<String> encodedConfigSettings = Database.getActive().transfer().getEncodedConfigSettings();
|
||||||
|
|
||||||
if (!encodedConfigSettings.isPresent()) {
|
if (!encodedConfigSettings.isPresent()) {
|
||||||
@ -78,7 +74,6 @@ public class NetworkSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String configSettings = Base64Util.decode(encodedConfigSettings.get());
|
String configSettings = Base64Util.decode(encodedConfigSettings.get());
|
||||||
|
|
||||||
Map<String, String> pathValueMap = getPathsAndValues(configSettings);
|
Map<String, String> pathValueMap = getPathsAndValues(configSettings);
|
||||||
|
|
||||||
ServerSpecificSettings.updateSettings(pathValueMap);
|
ServerSpecificSettings.updateSettings(pathValueMap);
|
||||||
@ -110,7 +105,7 @@ public class NetworkSettings {
|
|||||||
return pathValueMap;
|
return pathValueMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException {
|
public void placeToDatabase() throws DBException, UnsupportedTransferDatabaseException {
|
||||||
Map<String, Object> configValues = getConfigValues();
|
Map<String, Object> configValues = getConfigValues();
|
||||||
|
|
||||||
StringBuilder transferBuilder = new StringBuilder();
|
StringBuilder transferBuilder = new StringBuilder();
|
||||||
|
@ -80,7 +80,7 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
return new InternalErrorResponse(request.getTarget(), e);
|
return new InternalErrorResponse(request.getTarget(), e);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
return new InternalErrorResponse(request.getTarget(), e);
|
return new InternalErrorResponse(request.getTarget(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ public class WebServer implements SubSystem {
|
|||||||
|
|
||||||
Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()) + " (" + getAccessAddress() + ")");
|
Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()) + " (" + getAccessAddress() + ")");
|
||||||
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
|
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,16 +164,16 @@ public class WebServer implements SubSystem {
|
|||||||
startSuccessful = true;
|
startSuccessful = true;
|
||||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
||||||
Log.error("WebServer: SSL Context Initialization Failed.");
|
Log.error("WebServer: SSL Context Initialization Failed.");
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
|
Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
|
||||||
Log.info("No Certificate -> Using Http server for Visualization.");
|
Log.info("No Certificate -> Using Http server for Visualization.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.error("WebServer: " + e);
|
Log.error("WebServer: " + e);
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {
|
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {
|
||||||
Log.error("WebServer: SSL Certificate loading Failed.");
|
Log.error("WebServer: SSL Certificate loading Failed.");
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
return startSuccessful;
|
return startSuccessful;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class PlayerPageHandler extends PageHandler {
|
|||||||
return notFound("Player has not played on this server.");
|
return notFound("Player has not played on this server.");
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
throw new InternalErrorException("Analysis", e);
|
throw new InternalErrorException("Analysis", e);
|
||||||
} catch (NoServersException e) {
|
} catch (NoServersException e) {
|
||||||
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> new NotFoundResponse(e.getMessage()));
|
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> new NotFoundResponse(e.getMessage()));
|
||||||
|
@ -29,7 +29,7 @@ public class ErrorResponse extends Response {
|
|||||||
try {
|
try {
|
||||||
setContent(Theme.replaceColors(FileUtil.getStringFromResource("web/error.html")));
|
setContent(Theme.replaceColors(FileUtil.getStringFromResource("web/error.html")));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class DebugPageResponse extends ErrorResponse {
|
|||||||
try {
|
try {
|
||||||
content.append(" schema v").append(((SQLDB) database).getVersion());
|
content.append(" schema v").append(((SQLDB) database).getVersion());
|
||||||
} catch (SQLException e) {
|
} 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("```</pre>");
|
content.append("```</pre>");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} 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("</pre>");
|
content.append("</pre>");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class PlayersPageResponse extends Response {
|
|||||||
replace.put("version", plugin.getVersion());
|
replace.put("version", plugin.getVersion());
|
||||||
super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("web/players.html"), replace)));
|
super.setContent(Theme.replaceColors(StrSubstitutor.replace(FileUtil.getStringFromResource("web/players.html"), replace)));
|
||||||
} catch (DBException | IOException e) {
|
} catch (DBException | IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
setContent(new InternalErrorResponse("/players", e).getContent());
|
setContent(new InternalErrorResponse("/players", e).getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class Analysis {
|
|||||||
|
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||||
Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin());
|
Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin());
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin());
|
Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin());
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class AnalysisExport extends SpecificExport {
|
|||||||
|
|
||||||
exportAvailableServerPage(serverUUID, serverName);
|
exportAvailableServerPage(serverUUID, serverName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -71,7 +71,7 @@ public class HtmlExport extends SpecificExport {
|
|||||||
exportAvailablePlayers();
|
exportAvailablePlayers();
|
||||||
exportPlayersPage();
|
exportPlayersPage();
|
||||||
} catch (IOException | DBException e) {
|
} catch (IOException | DBException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
@ -149,7 +149,7 @@ public class HtmlExport extends SpecificExport {
|
|||||||
outputFolder.mkdirs();
|
outputFolder.mkdirs();
|
||||||
export(new File(outputFolder, "demo.js"), lines);
|
export(new File(outputFolder, "demo.js"), lines);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ public class HtmlExport extends SpecificExport {
|
|||||||
try {
|
try {
|
||||||
copyFromJar(resource);
|
copyFromJar(resource);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class PlayerExport extends SpecificExport {
|
|||||||
|
|
||||||
exportAvailablePlayerPage(uuid, name);
|
exportAvailablePlayerPage(uuid, name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
@ -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.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
|
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
|
import com.djrapitops.plan.utilities.Base64Util;
|
||||||
import com.djrapitops.plan.utilities.ManageUtils;
|
import com.djrapitops.plan.utilities.ManageUtils;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import com.djrapitops.plan.utilities.analysis.MathUtils;
|
import com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||||
@ -846,7 +847,6 @@ public class SQLiteTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testRegisterProcessorRegisterException() throws SQLException {
|
public void testRegisterProcessorRegisterException() throws SQLException {
|
||||||
assertFalse(db.getUsersTable().isRegistered(playerUUID));
|
assertFalse(db.getUsersTable().isRegistered(playerUUID));
|
||||||
assertFalse(db.getUserInfoTable().isRegistered(playerUUID));
|
assertFalse(db.getUserInfoTable().isRegistered(playerUUID));
|
||||||
@ -871,4 +871,16 @@ public class SQLiteTest {
|
|||||||
public void testWorldTableGetWorldNamesNoException() throws SQLException {
|
public void testWorldTableGetWorldNamesNoException() throws SQLException {
|
||||||
Set<String> worldNames = db.getWorldTable().getWorldNames();
|
Set<String> 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<String> configSettings = transferTable.getConfigSettings();
|
||||||
|
|
||||||
|
assertTrue(configSettings.isPresent());
|
||||||
|
assertEquals(testString, Base64Util.decode(configSettings.get()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,6 +15,6 @@ public class TestErrorManager extends ErrorManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toLog(String s, Throwable throwable, Class aClass) {
|
public void toLog(String s, Throwable throwable, Class aClass) {
|
||||||
throw new IllegalStateException(throwable);
|
throw new RuntimeException("Error During Test.", throwable);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ import com.djrapitops.plan.api.exceptions.EnableException;
|
|||||||
import com.djrapitops.plan.system.BukkitSystem;
|
import com.djrapitops.plan.system.BukkitSystem;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||||
|
import com.djrapitops.plugin.StaticHolder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ public class SystemMockUtil {
|
|||||||
private BukkitSystem bukkitSystem;
|
private BukkitSystem bukkitSystem;
|
||||||
|
|
||||||
public static SystemMockUtil setUp(File dataFolder) throws Exception {
|
public static SystemMockUtil setUp(File dataFolder) throws Exception {
|
||||||
|
StaticHolder.saveInstance(SystemMockUtil.class, Plan.class);
|
||||||
return new SystemMockUtil().initializeBukkitSystem(dataFolder);
|
return new SystemMockUtil().initializeBukkitSystem(dataFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user