diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index 75e24ce0f..03710d801 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.database; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.Closeable; import java.io.File; import java.io.FileReader; import java.io.FileWriter; @@ -10,6 +9,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -367,7 +367,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager { public Map readRank(String playerName) { updateLeaderboards(); - Map skills = new HashMap(); + Map skills = new EnumMap(SkillType.class); for (SkillType skill : SkillType.NON_CHILD_SKILLS) { skills.put(skill, getPlayerRank(playerName, playerStatHash.get(skill))); @@ -1081,8 +1081,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager { private PlayerProfile loadFromLine(String[] character) { Map skills = getSkillMapFromLine(character); // Skill levels - Map skillsXp = new HashMap(); // Skill & XP - Map skillsDATS = new HashMap(); // Ability & Cooldown + Map skillsXp = new EnumMap(SkillType.class); // Skill & XP + Map skillsDATS = new EnumMap(AbilityType.class); // Ability & Cooldown MobHealthbarType mobHealthbarType; // TODO on updates, put new values in a try{} ? @@ -1133,7 +1133,7 @@ public final class FlatfileDatabaseManager implements DatabaseManager { } private Map getSkillMapFromLine(String[] character) { - Map skills = new HashMap(); // Skill & Level + Map skills = new EnumMap(SkillType.class); // Skill & Level skills.put(SkillType.TAMING, Integer.valueOf(character[24])); skills.put(SkillType.MINING, Integer.valueOf(character[1])); diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index ae3f0928e..a8f03f6ee 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -8,6 +8,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,6 +56,10 @@ public final class SQLDatabaseManager implements DatabaseManager { connectionProperties.put("user", Config.getInstance().getMySQLUserName()); connectionProperties.put("password", Config.getInstance().getMySQLUserPassword()); connectionProperties.put("autoReconnect", "false"); + connectionProperties.put("cachePrepStmts", "true"); + connectionProperties.put("prepStmtCacheSize", "64"); + connectionProperties.put("prepStmtCacheSqlLimit", "2048"); + connectionProperties.put("useServerPrepStmts", "true"); connectionPool = new ConnectionPool("mcMMO-Pool", 1 /*Minimum of one*/, Config.getInstance().getMySQLMaxPoolSize() /*max pool size */, @@ -415,7 +420,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } public Map readRank(String playerName) { - Map skills = new HashMap(); + Map skills = new EnumMap(SkillType.class); ResultSet resultSet = null; PreparedStatement statement = null; @@ -1238,9 +1243,9 @@ public final class SQLDatabaseManager implements DatabaseManager { } private PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException { - Map skills = new HashMap(); // Skill & Level - Map skillsXp = new HashMap(); // Skill & XP - Map skillsDATS = new HashMap(); // Ability & Cooldown + Map skills = new EnumMap(SkillType.class); // Skill & Level + Map skillsXp = new EnumMap(SkillType.class); // Skill & XP + Map skillsDATS = new EnumMap(AbilityType.class); // Ability & Cooldown MobHealthbarType mobHealthbarType; UUID uuid; @@ -1309,6 +1314,8 @@ public final class SQLDatabaseManager implements DatabaseManager { } private void printErrors(SQLException ex) { + StackTraceElement element = ex.getStackTrace()[0]; + mcMMO.p.getLogger().severe("Location: " + element.getMethodName() + " " + element.getLineNumber()); mcMMO.p.getLogger().severe("SQLException: " + ex.getMessage()); mcMMO.p.getLogger().severe("SQLState: " + ex.getSQLState()); mcMMO.p.getLogger().severe("VendorError: " + ex.getErrorCode());