Removed error spam when MySQL connection lost

This commit is contained in:
Robin Kupper
2011-10-17 16:23:40 +02:00
parent 9e4f058d92
commit 2c571575d6
2 changed files with 41 additions and 4 deletions
@@ -396,6 +396,10 @@ public class CommandsHandler implements CommandExecutor
params.needChestAccess = true;
}
conn = logblock.getConnection();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
state = conn.createStatement();
rs = state.executeQuery(params.getQuery());
sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":");
@@ -449,6 +453,10 @@ public class CommandsHandler implements CommandExecutor
params.needChestAccess = true;
}
conn = logblock.getConnection();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
state = conn.createStatement();
file = new File("plugins/LogBlock/log/" + params.getTitle().replace(":", ".") + ".log");
sender.sendMessage(ChatColor.GREEN + "Creating " + file.getName());
@@ -516,6 +524,10 @@ public class CommandsHandler implements CommandExecutor
params.limit = 1;
params.sum = SummarizationMode.NONE;
conn = logblock.getConnection();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
state = conn.createStatement();
rs = state.executeQuery(params.getQuery());
if (rs.next()) {
@@ -554,6 +566,10 @@ public class CommandsHandler implements CommandExecutor
params.order = Order.DESC;
params.sum = SummarizationMode.NONE;
conn = logblock.getConnection();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
state = conn.createStatement();
if (!checkRestrictions(sender, params))
return;
@@ -614,6 +630,10 @@ public class CommandsHandler implements CommandExecutor
params.order = Order.ASC;
params.sum = SummarizationMode.NONE;
conn = logblock.getConnection();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
state = conn.createStatement();
if (!checkRestrictions(sender, params))
return;
@@ -657,6 +677,10 @@ public class CommandsHandler implements CommandExecutor
try {
conn = logblock.getConnection();
state = conn.createStatement();
if (conn == null) {
sender.sendMessage(ChatColor.RED + "MySQL connection lost");
return;
}
if (!checkRestrictions(sender, params))
return;
final File dumpFolder = new File(logblock.getDataFolder(), "dump");
+17 -4
View File
@@ -45,6 +45,7 @@ public class LogBlock extends JavaPlugin
private PermissionHandler permissions = null;
private boolean errorAtLoading = false;
private final Map<String, Session> sessions = new HashMap<String, Session>();
private boolean connected = true;
public Config getLBConfig() {
return config;
@@ -76,13 +77,16 @@ public class LogBlock extends JavaPlugin
throw new FileNotFoundException(file.getAbsolutePath() + file.getName());
getLogger().info("[LogBlock] Connecting to " + config.user + "@" + config.url + "...");
pool = new MySQLConnectionPool(config.url, config.user, config.password);
getConnection().close();
final Connection conn = getConnection();
if (conn == null)
throw new SQLException("No MySQL connection");
conn.close();
if (updater.update())
config = new Config(this);
updater.checkTables();
doImports();
} catch (final Exception ex) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
getLogger().severe("[LogBlock] Error while loading: " + ex.getMessage());
errorAtLoading = true;
return;
}
@@ -299,9 +303,18 @@ public class LogBlock extends JavaPlugin
public Connection getConnection() {
try {
return pool.getConnection();
final Connection conn = pool.getConnection();
if (!connected) {
getLogger().info("[LogBlock] MySQL connection rebuild");
connected = true;
}
return conn;
} catch (final Exception ex) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection", ex);
if (connected) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection: ", ex);
connected = false;
} else
getLogger().severe("[LogBlock] MySQL connection lost");
return null;
}
}