Pārlūkot izejas kodu

some of zreeds work, because too lazy to fix merge compatability

t00thpick1 11 gadi atpakaļ
vecāks
revīzija
2248316ed3

+ 5 - 5
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<SkillType, Integer> readRank(String playerName) {
         updateLeaderboards();
 
-        Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
+        Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(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<SkillType, Integer>   skills     = getSkillMapFromLine(character);      // Skill levels
-        Map<SkillType, Float>     skillsXp   = new HashMap<SkillType, Float>();     // Skill & XP
-        Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
+        Map<SkillType, Float>     skillsXp   = new EnumMap<SkillType, Float>(SkillType.class);     // Skill & XP
+        Map<AbilityType, Integer> skillsDATS = new EnumMap<AbilityType, Integer>(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<SkillType, Integer> getSkillMapFromLine(String[] character) {
-        Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();   // Skill & Level
+        Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class);   // Skill & Level
 
         skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
         skills.put(SkillType.MINING, Integer.valueOf(character[1]));

+ 11 - 4
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<SkillType, Integer> readRank(String playerName) {
-        Map<SkillType, Integer> skills = new HashMap<SkillType, Integer>();
+        Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(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<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); // Skill & Level
-        Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
-        Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
+        Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class); // Skill & Level
+        Map<SkillType, Float> skillsXp = new EnumMap<SkillType, Float>(SkillType.class); // Skill & XP
+        Map<AbilityType, Integer> skillsDATS = new EnumMap<AbilityType, Integer>(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());