From f2d28fd7af69930432e3c76e55b3d96097c89ea9 Mon Sep 17 00:00:00 2001
From: MagicBot <MagicBot@magicbane.com>
Date: Thu, 14 Mar 2024 15:22:38 -0400
Subject: [PATCH] Refactored out duplicate db interface.

---
 src/engine/db/handlers/dbPowerHandler.java    |   31 +-
 src/engine/objects/AbstractGameObject.java    |   16 -
 src/engine/objects/LevelDefault.java          |   71 -
 src/engine/objects/PowerGrant.java            |   28 +-
 src/engine/objects/PowerReq.java              |   19 +-
 .../objects/PreparedStatementShared.java      | 1261 -----------------
 src/engine/powers/ActionsBase.java            |   21 +-
 src/engine/powers/EffectsBase.java            |   23 +-
 src/engine/powers/FailCondition.java          |  118 --
 src/engine/powers/PowerPrereq.java            |   17 +-
 .../poweractions/AbstractPowerAction.java     |   45 +-
 src/engine/server/login/LoginServer.java      |    6 -
 src/engine/server/world/WorldServer.java      |    6 -
 13 files changed, 86 insertions(+), 1576 deletions(-)
 delete mode 100644 src/engine/objects/LevelDefault.java
 delete mode 100644 src/engine/objects/PreparedStatementShared.java
 delete mode 100644 src/engine/powers/FailCondition.java

diff --git a/src/engine/db/handlers/dbPowerHandler.java b/src/engine/db/handlers/dbPowerHandler.java
index ae3da531..e9714afe 100644
--- a/src/engine/db/handlers/dbPowerHandler.java
+++ b/src/engine/db/handlers/dbPowerHandler.java
@@ -13,10 +13,11 @@ import engine.Enum;
 import engine.gameManager.DbManager;
 import engine.gameManager.PowersManager;
 import engine.objects.Mob;
-import engine.objects.PreparedStatementShared;
 import engine.powers.EffectsBase;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.HashSet;
 
@@ -28,16 +29,17 @@ public class dbPowerHandler extends dbHandlerBase {
     }
 
     public static void addAllSourceTypes() {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_sourcetype")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
             String IDString, source;
+
             while (rs.next()) {
                 IDString = rs.getString("IDString");
                 int token = DbManager.hasher.SBStringHash(IDString);
 
-
                 source = rs.getString("source").replace("-", "").trim();
                 Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source);
 
@@ -46,19 +48,18 @@ public class dbPowerHandler extends dbHandlerBase {
 
                 EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType);
             }
-            rs.close();
         } catch (Exception e) {
             Logger.error(e);
-        } finally {
-            ps.release();
         }
     }
 
     public static void addAllAnimationOverrides() {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_animation_override")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
+
             String IDString;
             int animation;
             while (rs.next()) {
@@ -72,12 +73,10 @@ public class dbPowerHandler extends dbHandlerBase {
                 PowersManager.AnimationOverrides.put(IDString, animation);
 
             }
-            rs.close();
         } catch (Exception e) {
             Logger.error(e);
-        } finally {
-            ps.release();
         }
+
     }
 
 }
diff --git a/src/engine/objects/AbstractGameObject.java b/src/engine/objects/AbstractGameObject.java
index e0b5f206..ad321d57 100644
--- a/src/engine/objects/AbstractGameObject.java
+++ b/src/engine/objects/AbstractGameObject.java
@@ -84,22 +84,6 @@ public abstract class AbstractGameObject {
         return GameObjectType.values()[ordinal];
     }
 
-    /**
-     * Generates a {@link PreparedStatementShared} based on the specified query.
-     * <p>
-     * If {@link AbstractGameObject} Database functions  will properly release
-     * the PreparedStatementShared upon completion. If these functions are not
-     * used, then {@link PreparedStatementShared#release release()} must be
-     * called when finished with this object.
-     *
-     * @param sql The SQL string used to generate the PreparedStatementShared
-     * @return {@link PreparedStatementShared}
-     * @throws {@link SQLException}
-     **/
-    protected static PreparedStatementShared prepareStatement(String sql) throws SQLException {
-        return new PreparedStatementShared(sql);
-    }
-
     public static AbstractGameObject getFromTypeAndID(long compositeID) {
         int objectTypeID = extractTypeOrdinal(compositeID);
         int tableID = extractTableID(objectTypeID, compositeID);
diff --git a/src/engine/objects/LevelDefault.java b/src/engine/objects/LevelDefault.java
deleted file mode 100644
index 60492d7e..00000000
--- a/src/engine/objects/LevelDefault.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
-// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
-// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
-// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
-// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
-//      Magicbane Emulator Project © 2013 - 2022
-//                www.magicbane.com
-
-
-package engine.objects;
-
-import engine.server.MBServerStatics;
-import org.pmw.tinylog.Logger;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class LevelDefault {
-
-    public static ConcurrentHashMap<Byte, LevelDefault> defaults = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
-    public final int level;
-    public final float health;
-    public final float mana;
-    public final float stamina;
-    public final float atr;
-    public final float def;
-    public final float minDamage;
-    public final float maxDamage;
-    public final int goldMin;
-    public final int goldMax;
-
-    /**
-     * ResultSet Constructor
-     */
-    public LevelDefault(ResultSet rs) throws SQLException {
-        super();
-        this.level = rs.getInt("level");
-        this.health = rs.getFloat("health");
-        this.mana = (float) rs.getInt("mana");
-        this.stamina = (float) rs.getInt("stamina");
-        this.atr = (float) rs.getInt("atr");
-        this.def = (float) rs.getInt("def");
-        this.minDamage = (float) rs.getInt("minDamage");
-        this.maxDamage = (float) rs.getInt("maxDamage");
-        this.goldMin = rs.getInt("goldMin");
-        this.goldMax = rs.getInt("goldMax");
-    }
-
-    public static LevelDefault getLevelDefault(byte level) {
-        LevelDefault ret = null;
-        if (LevelDefault.defaults.containsKey(level))
-            return LevelDefault.defaults.get(level);
-
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM `static_npc_level_defaults` WHERE level = ?;");
-            ps.setInt(1, (int) level);
-            ResultSet rs = ps.executeQuery();
-            if (rs.next()) {
-                ret = new LevelDefault(rs);
-                LevelDefault.defaults.put(level, ret);
-            }
-        } catch (SQLException e) {
-            Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage());
-        } finally {
-            ps.release();
-        }
-        return ret;
-    }
-}
\ No newline at end of file
diff --git a/src/engine/objects/PowerGrant.java b/src/engine/objects/PowerGrant.java
index cffa21b9..04c08552 100644
--- a/src/engine/objects/PowerGrant.java
+++ b/src/engine/objects/PowerGrant.java
@@ -9,9 +9,12 @@
 
 package engine.objects;
 
+import engine.gameManager.DbManager;
 import engine.server.MBServerStatics;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -86,18 +89,26 @@ public class PowerGrant extends AbstractGameObject {
     }
 
     public static void fillGrantedPowers() {
+
         PowerGrant.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
-        PreparedStatementShared ps = null;
-        try {
-            ps = prepareStatement("SELECT * FROM static_power_powergrant");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powergrant")) {
+
+
+            ResultSet rs = preparedStatement.executeQuery();
+
             if (PowerGrant.grantedPowers.size() > 0) {
                 rs.close();
                 return;
             }
+
             while (rs.next()) {
+
                 int token = rs.getInt("powerToken");
-                PowerGrant pg = null;
+
+                PowerGrant pg;
+
                 if (PowerGrant.grantedPowers.containsKey(token)) {
                     pg = PowerGrant.grantedPowers.get(token);
                     pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount"));
@@ -109,16 +120,9 @@ public class PowerGrant extends AbstractGameObject {
             rs.close();
         } catch (SQLException e) {
             Logger.error("SQL Error number: " + e.getErrorCode(), e);
-        } finally {
-            ps.release();
         }
     }
 
-    public ConcurrentHashMap<Integer, Short> getRuneGrants() {
-        return this.runeGrants;
-    }
-
-
     /*
      * Database
      */
diff --git a/src/engine/objects/PowerReq.java b/src/engine/objects/PowerReq.java
index bc1e7c2b..6c0a4481 100644
--- a/src/engine/objects/PowerReq.java
+++ b/src/engine/objects/PowerReq.java
@@ -9,11 +9,14 @@
 
 package engine.objects;
 
+import engine.gameManager.DbManager;
 import engine.gameManager.PowersManager;
 import engine.powers.PowersBase;
 import engine.server.MBServerStatics;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -87,15 +90,18 @@ public class PowerReq extends AbstractGameObject implements Comparable<PowerReq>
     }
 
     public static ConcurrentHashMap<Integer, ArrayList<PowerReq>> fillRunePowers() {
+
         PowerReq.runePowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
-        PreparedStatementShared ps = null;
-        try {
-            ps = prepareStatement("SELECT * FROM static_power_powerrequirement");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powerrequirement")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
+
             if (PowerReq.runePowers.size() > 0) {
-                rs.close();
                 return PowerReq.runePowers;
             }
+
             while (rs.next()) {
                 ArrayList<PowerReq> runePR = null;
                 int runeID = rs.getInt("runeID");
@@ -130,9 +136,8 @@ public class PowerReq extends AbstractGameObject implements Comparable<PowerReq>
             }
         } catch (SQLException e) {
             Logger.error("SQL Error number: " + e.getErrorCode(), e);
-        } finally {
-            ps.release();
         }
+
         return PowerReq.runePowers;
     }
 
diff --git a/src/engine/objects/PreparedStatementShared.java b/src/engine/objects/PreparedStatementShared.java
deleted file mode 100644
index de3aae0c..00000000
--- a/src/engine/objects/PreparedStatementShared.java
+++ /dev/null
@@ -1,1261 +0,0 @@
-// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
-// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
-// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
-// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
-// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
-//      Magicbane Emulator Project © 2013 - 2022
-//                www.magicbane.com
-
-
-package engine.objects;
-
-import engine.gameManager.DbManager;
-import engine.job.JobScheduler;
-import engine.jobs.BasicScheduledJob;
-import engine.server.MBServerStatics;
-import org.pmw.tinylog.Logger;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * A thread-safe sharing implementation of {@link PreparedStatement}.
- * <p>
- * All of the methods from the PreparedStatement interface simply check to see
- * that the PreparedStatement is active, and call the corresponding method on
- * that PreparedStatement.
- *
- * @author Burfo
- * @see PreparedStatement
- **/
-public class PreparedStatementShared implements PreparedStatement {
-    private static final ConcurrentHashMap<Integer, LinkedList<PreparedStatement>> statementList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
-    private static final ArrayList<PreparedStatementShared> statementListDelegated = new ArrayList<>();
-    private static final String ExceptionMessage = "PreparedStatementShared object " + "was accessed after being released.";
-    private static boolean debuggingIsOn;
-
-    private PreparedStatement ps = null;
-    private int sqlHash;
-    private String sql;
-    private long delegatedTime;
-
-    //debugging variables
-    private StackTraceElement[] stackTrace;
-    private DebugParam[] variables;
-    private String filteredSql;
-
-    /**
-     * Generates a new PreparedStatementShared based on the specified sql.
-     *
-     * @param sql Query string to generate the PreparedStatement
-     * @throws SQLException
-     **/
-    public PreparedStatementShared(String sql) throws SQLException {
-        this.sqlHash = sql.hashCode();
-        this.sql = sql;
-        this.delegatedTime = System.currentTimeMillis();
-        this.ps = getFromPool(sql, sqlHash);
-        if (this.ps == null) {
-            this.ps = createNew(sql, sqlHash);
-        }
-
-
-        if (debuggingIsOn) {
-            //see if there are any '?' in the statement that are not bind variables
-            //and filter them out.
-            boolean isString = false;
-            char[] sqlString = this.sql.toCharArray();
-            for (int i = 0; i < sqlString.length; i++) {
-                if (sqlString[i] == '\'')
-                    isString = !isString;
-                //substitute the ? with an unprintable character if is in a string
-                if (sqlString[i] == '?' && isString)
-                    sqlString[i] = '\u0007';
-            }
-            this.filteredSql = new String(sqlString);
-
-            //find out how many variables are present in statement.
-            int count = 0;
-            int index = -1;
-            while ((index = filteredSql.indexOf('?', index + 1)) != -1) {
-                count++;
-            }
-
-            //create variables array with size equal to count of variables
-            this.variables = new DebugParam[count];
-
-            this.stackTrace = Thread.currentThread().getStackTrace();
-
-        } else {
-            this.stackTrace = null;
-            this.variables = null;
-            this.filteredSql = null;
-        }
-
-        synchronized (statementListDelegated) {
-            statementListDelegated.add(this);
-        }
-
-    }
-
-    private static PreparedStatement getFromPool(String sql, int sqlHash) throws SQLException {
-        PreparedStatement ps = null;
-
-        if (statementList.containsKey(sqlHash)) {
-            LinkedList<PreparedStatement> list = statementList.get(sqlHash);
-            if (list == null) { // Shouldn't happen b/c no keys are ever removed
-                throw new AssertionError("list cannot be null.");
-            }
-            boolean success = false;
-            synchronized (list) {
-                do {
-                    ps = list.pollFirst();
-                    if (ps == null) {
-                        break;
-                    }
-                    if (ps.isClosed()) { // should rarely happen
-                        Logger.warn("A closed PreparedStatement was removed "
-                                + "from AbstractGameObject statementList. " + "SQL: " + sql);
-                    } else {
-                        success = true;
-                    }
-                } while (!success);
-            }
-
-            if (ps != null) {
-                if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) {
-                    Logger.info("Found cached PreparedStatement for SQL hash: " + sqlHash
-                            + " SQL String: " + sql);
-                }
-            }
-        }
-        return ps;
-    }
-
-    private static PreparedStatement createNew(String sql, int sqlHash) throws SQLException {
-        statementList.putIfAbsent(sqlHash, new LinkedList<>());
-        return DbManager.prepareStatement(sql);
-    }
-
-    public static void submitPreparedStatementsCleaningJob() {
-        JobScheduler.getInstance().scheduleJob(new BasicScheduledJob("cleanUnreleasedStatements", PreparedStatementShared.class), 1000 * 60 * 2); // 2
-        // minutes
-    }
-
-    public static void cleanUnreleasedStatements() {
-        long now = System.currentTimeMillis();
-        long timeLimit = 120000; // 2 minutes
-
-        synchronized (statementListDelegated) {
-            Iterator<PreparedStatementShared> iterator = statementListDelegated.iterator();
-            while (iterator.hasNext()) {
-                PreparedStatementShared pss = iterator.next();
-                if ((pss.delegatedTime + timeLimit) >= now) {
-                    continue;
-                }
-                iterator.remove();
-
-                Logger.warn("Forcefully released after being held for > 2 minutes." + " SQL STRING: \""
-                        + pss.sql + "\" METHOD: " + pss.getTraceInfo());
-            }
-        }
-
-        submitPreparedStatementsCleaningJob(); // resubmit
-    }
-
-    public static void enableDebugging() {
-        debuggingIsOn = true;
-        Logger.info("Database debugging has been enabled.");
-    }
-
-    public static void disableDebugging() {
-        debuggingIsOn = false;
-        Logger.info("Database debugging has been disabled.");
-    }
-
-    @Override
-    public boolean isCloseOnCompletion() {
-        return true;
-    }
-
-    @Override
-    public void closeOnCompletion() {
-        Logger.warn("Prepared Statement Closed");
-    }
-
-    /**
-     * Releases the use of a PreparedStatementShared that was generated by
-     * {@link AbstractGameObject#prepareStatement}, making it available for use
-     * by another query.
-     * <p>
-     * Do not utilize or modify the object after calling this method.
-     * <p>
-     * Example:
-     *
-     * <pre>
-     * &#064;code
-     * PreparedStatementShared ps = prepareStatement(...);
-     * ps.executeUpdate();
-     * ps.release();
-     * ps = null;}
-     * </pre>
-     **/
-    public void release() {
-        if (this.ps == null) {
-            return;
-        } // nothing to release
-        if (statementListDelegated.contains(this)) {
-            synchronized (statementListDelegated) {
-                statementListDelegated.remove(this);
-            }
-            try {
-                if (this.ps.isClosed()) {
-                    return;
-                }
-                this.ps.clearParameters();
-                this.variables = null;
-            } catch (SQLException ignore) {
-            }
-
-            // add back to pool
-            LinkedList<PreparedStatement> list = statementList.get(this.sqlHash);
-            if (list == null) {
-                return;
-            }
-            synchronized (list) {
-                list.add(this.ps);
-            }
-        }
-        // clear values from this object so caller cannot use it after it has
-        // been released
-        this.ps = null;
-        this.sqlHash = 0;
-        this.sql = "";
-        this.delegatedTime = 0;
-        this.stackTrace = null;
-    }
-
-    /**
-     * Determines if the object is in a usable state.
-     *
-     * @return True if the object is in a useable state.
-     **/
-    public boolean isUsable() {
-        if (ps == null) {
-            return false;
-        }
-        try {
-            if (ps.isClosed()) {
-                return false;
-            }
-        } catch (SQLException e) {
-            return false;
-        }
-        return true;
-    }
-
-    private String getTraceInfo() {
-        if (stackTrace == null) {
-            return "<no debug data>";
-        }
-
-        if (stackTrace.length > 3) {
-            return stackTrace[3].getClassName() + '.' + stackTrace[3].getMethodName();
-        } else if (stackTrace.length == 0) {
-            return "<unavailable>";
-        } else {
-            return stackTrace[stackTrace.length - 1].getClassName() + '.' + stackTrace[stackTrace.length - 1].getMethodName();
-        }
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (ps == null || obj == null) {
-            return false;
-        }
-
-        if (obj instanceof PreparedStatementShared) {
-            return this.ps.equals(((PreparedStatementShared) obj).ps);
-        }
-
-        if (obj instanceof PreparedStatement) {
-            return this.ps.equals(obj);
-        }
-
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        if (!debuggingIsOn || variables == null) {
-            return "SQL: " + this.sql + " (enable DB debugging for more data)";
-        }
-
-        String out;
-
-        out = "SQL: [" + this.sql + "] ";
-        out += "VARIABLES[count=" + variables.length + "]: ";
-
-        for (int i = 0; i < variables.length; i++) {
-            out += "[" + (i + 1) + "]: ";
-            DebugParam dp = variables[i];
-            if (dp == null || !dp.isValueAssigned()) {
-                out += "{MISSING} ";
-                continue;
-            }
-            Object dpObj = dp.getDebugObject();
-            out += dpObj.toString() + ' ';
-        }
-        return out;
-    }
-
-    @Override
-    public void addBatch() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException();
-        }
-        this.ps.addBatch();
-
-    }
-
-    private void saveObject(int parameterIndex, Object obj) throws SQLException {
-        if (!debuggingIsOn || this.variables == null) {
-            return;
-        }
-
-        if (parameterIndex > variables.length) {
-            throw new SQLException("Parameter index of " + parameterIndex +
-                    " exceeds actual parameter count of " + this.variables.length);
-        }
-
-        this.variables[parameterIndex - 1] = new DebugParam(obj);
-    }
-
-    private void logExceptionAndRethrow(SQLException e) throws SQLException {
-        Logger.error("SQL operation failed: (" +
-                e.getMessage() + ") " + this.toString(), e);
-        throw e;
-    }
-
-    @Override
-    public void clearParameters() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-
-        this.ps.clearParameters();
-        for (int i = 0; i < this.variables.length; i++) {
-            this.variables[i] = null;
-        }
-
-    }
-
-    @Override
-    public boolean execute() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-
-        if (debuggingIsOn || MBServerStatics.ENABLE_EXECUTION_TIME_WARNING) {
-            long startTime = System.currentTimeMillis();
-            boolean rs = false;
-            try {
-                rs = this.ps.execute();
-            } catch (SQLException e) {
-                logExceptionAndRethrow(e);
-            }
-            if ((startTime + MBServerStatics.DB_EXECUTION_WARNING_TIME_MS) < System.currentTimeMillis())
-                Logger.warn("The following statement took " + (System.currentTimeMillis() - startTime)
-                        + " millis to execute: " + this.sql);
-            return rs;
-        }
-
-        return this.ps.execute();
-    }
-
-    @Override
-    public ResultSet executeQuery() throws SQLException, SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-
-        if (debuggingIsOn || MBServerStatics.ENABLE_QUERY_TIME_WARNING) {
-            long startTime = System.currentTimeMillis();
-            ResultSet rs = null;
-            try {
-                rs = this.ps.executeQuery();
-            } catch (SQLException e) {
-                logExceptionAndRethrow(e);
-            }
-            if ((startTime + MBServerStatics.DB_QUERY_WARNING_TIME_MS) < System.currentTimeMillis())
-                Logger.warn("The following query took " + (System.currentTimeMillis() - startTime)
-                        + " millis to execute: " + this.sql);
-            return rs;
-        }
-
-        return this.ps.executeQuery();
-    }
-
-    @Override
-    public int executeUpdate() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-
-        if (debuggingIsOn || MBServerStatics.ENABLE_UPDATE_TIME_WARNING) {
-            long startTime = System.currentTimeMillis();
-            int rs = 0;
-            try {
-                rs = this.ps.executeUpdate();
-            } catch (SQLException e) {
-                logExceptionAndRethrow(e);
-            }
-            if ((startTime + MBServerStatics.DB_UPDATE_WARNING_TIME_MS) < System.currentTimeMillis())
-                Logger.warn("The following update took " + (System.currentTimeMillis() - startTime)
-                        + " millis to execute: " + this.sql);
-            return rs;
-        }
-
-        return this.ps.executeUpdate();
-    }
-
-    @Override
-    public ResultSetMetaData getMetaData() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getMetaData();
-    }
-
-    @Override
-    public ParameterMetaData getParameterMetaData() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getParameterMetaData();
-    }
-
-    @Override
-    public void setArray(int parameterIndex, Array x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.saveObject(parameterIndex, x);
-        this.ps.setArray(parameterIndex, x);
-    }
-
-    @Override
-    public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream>"));
-        this.ps.setAsciiStream(parameterIndex, x);
-    }
-
-    @Override
-    public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setAsciiStream(parameterIndex, x, length);
-    }
-
-    @Override
-    public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setAsciiStream(parameterIndex, x, length);
-    }
-
-    @Override
-    public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setBigDecimal(parameterIndex, x);
-    }
-
-    @Override
-    public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream>"));
-        this.ps.setBinaryStream(parameterIndex, x);
-    }
-
-    @Override
-    public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setBinaryStream(parameterIndex, x, length);
-    }
-
-    @Override
-    public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setBinaryStream(parameterIndex, x, length);
-    }
-
-    @Override
-    public void setBlob(int parameterIndex, Blob x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setBlob(parameterIndex, x);
-    }
-
-    @Override
-    public void setBlob(int parameterIndex, InputStream x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<blob stream>"));
-        this.ps.setBlob(parameterIndex, x);
-    }
-
-    @Override
-    public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "<blob stream length= " + length + '>'));
-        this.ps.setBlob(parameterIndex, x, length);
-    }
-
-    @Override
-    public void setBoolean(int parameterIndex, boolean x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Boolean(x));
-        this.ps.setBoolean(parameterIndex, x);
-    }
-
-    @Override
-    public void setByte(int parameterIndex, byte x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Byte(x));
-        this.ps.setByte(parameterIndex, x);
-    }
-
-    @Override
-    public void setBytes(int parameterIndex, byte[] x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : "byte[] length=" + x.length));
-        this.ps.setBytes(parameterIndex, x);
-    }
-
-    @Override
-    public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream>"));
-        this.ps.setCharacterStream(parameterIndex, reader);
-    }
-
-    @Override
-    public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setCharacterStream(parameterIndex, reader, length);
-    }
-
-    @Override
-    public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setCharacterStream(parameterIndex, reader, length);
-    }
-
-    @Override
-    public void setClob(int parameterIndex, Clob x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setClob(parameterIndex, x);
-    }
-
-    @Override
-    public void setClob(int parameterIndex, Reader reader) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream>"));
-        this.ps.setClob(parameterIndex, reader);
-    }
-
-    @Override
-    public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setClob(parameterIndex, reader, length);
-    }
-
-    @Override
-    public void setDate(int parameterIndex, Date x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setDate(parameterIndex, x);
-    }
-
-    @Override
-    public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setDate(parameterIndex, x, cal);
-    }
-
-    @Override
-    public void setDouble(int parameterIndex, double x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Double(x));
-        this.ps.setDouble(parameterIndex, x);
-    }
-
-    @Override
-    public void setFloat(int parameterIndex, float x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Float(x));
-        this.ps.setFloat(parameterIndex, x);
-    }
-
-    /**
-     * Sets the designated parameter to the given Java <code>int</code> value.
-     * The driver converts this
-     * to an SQL <code>INTEGER</code> value when it sends it to the database.
-     *
-     * @param parameterIndex the first parameter is 1, the second is 2, ...
-     * @param x              the parameter value
-     * @param setZeroAsNull  Converts an int value of 0 to an SQL NULL.
-     *                       Should be set TRUE on INSERTS and UPDATES for record pointers
-     *                       (e.g. GuildID) and FALSE for data elements (e.g. player's level).
-     * @throws SQLException if parameterIndex does not correspond to a parameter
-     *                      marker in the SQL statement; if a database access error occurs or
-     *                      this method is called on a closed <code>PreparedStatement</code>
-     */
-    public void setInt(int parameterIndex, int x, boolean setZeroAsNull) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        if (setZeroAsNull && x == 0) {
-            this.ps.setNull(parameterIndex, java.sql.Types.INTEGER);
-            saveObject(parameterIndex, "NULL");
-            return;
-        }
-        saveObject(parameterIndex, new Integer(x));
-        this.ps.setInt(parameterIndex, x);
-
-    }
-
-    @Override
-    public void setInt(int parameterIndex, int x) throws SQLException {
-        setInt(parameterIndex, x, false);
-    }
-
-    @Override
-    public void setLong(int parameterIndex, long x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Long(x));
-        this.ps.setLong(parameterIndex, x);
-    }
-
-    @Override
-    public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (value == null ? "NULL" : "<stream>"));
-        this.ps.setNCharacterStream(parameterIndex, value);
-    }
-
-    @Override
-    public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (value == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setNCharacterStream(parameterIndex, value, length);
-    }
-
-    @Override
-    public void setNClob(int parameterIndex, NClob value) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (value == null ? "NULL" : "<stream>"));
-        this.ps.setNClob(parameterIndex, value);
-    }
-
-    @Override
-    public void setNClob(int parameterIndex, Reader reader) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream>"));
-        this.ps.setNClob(parameterIndex, reader);
-    }
-
-    @Override
-    public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (reader == null ? "NULL" : "<stream length= " + length + '>'));
-        this.ps.setNClob(parameterIndex, reader, length);
-    }
-
-    @Override
-    public void setNString(int parameterIndex, String value) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, value);
-        this.ps.setNString(parameterIndex, value);
-    }
-
-    @Override
-    public void setNull(int parameterIndex, int sqlType) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, "NULL");
-        this.ps.setNull(parameterIndex, sqlType);
-    }
-
-    @Override
-    public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, "NULL");
-        this.ps.setNull(parameterIndex, sqlType, typeName);
-    }
-
-    @Override
-    public void setObject(int parameterIndex, Object x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : x.getClass().getName()));
-        this.ps.setObject(parameterIndex, x);
-    }
-
-    @Override
-    public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : x.getClass().getName()));
-        this.ps.setObject(parameterIndex, x, targetSqlType);
-    }
-
-    @Override
-    public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, (x == null ? "NULL" : x.getClass().getName()));
-        this.ps.setObject(parameterIndex, x, targetSqlType, scaleOrLength);
-    }
-
-    @Override
-    public void setRef(int parameterIndex, Ref x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setRef(parameterIndex, x);
-    }
-
-    @Override
-    public void setRowId(int parameterIndex, RowId x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setRowId(parameterIndex, x);
-    }
-
-    @Override
-    public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, xmlObject);
-        this.ps.setSQLXML(parameterIndex, xmlObject);
-    }
-
-    @Override
-    public void setShort(int parameterIndex, short x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, new Short(x));
-        this.ps.setShort(parameterIndex, x);
-    }
-
-    @Override
-    public void setString(int parameterIndex, String x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setString(parameterIndex, x);
-    }
-
-    @Override
-    public void setTime(int parameterIndex, Time x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setTime(parameterIndex, x);
-    }
-
-    @Override
-    public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setTime(parameterIndex, x, cal);
-    }
-
-    @Override
-    public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setTimestamp(parameterIndex, x);
-    }
-
-    @Override
-    public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setTimestamp(parameterIndex, x, cal);
-    }
-
-    @Override
-    public void setURL(int parameterIndex, URL x) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        saveObject(parameterIndex, x);
-        this.ps.setURL(parameterIndex, x);
-    }
-
-    @Override
-    @Deprecated
-    public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
-        throw new UnsupportedOperationException("setUnicodeStream is unsupported");
-		/*
-		if (this.ps == null) {
-			throw new SQLException(ExceptionMessage);
-		}
-		this.ps.setUnicodeStream(parameterIndex, x, length);
-		*/
-    }
-
-    @Override
-    public void addBatch(String sql) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.addBatch(sql);
-    }
-
-    @Override
-    public void cancel() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.cancel();
-    }
-
-    @Override
-    public void clearBatch() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.clearBatch();
-    }
-
-    @Override
-    public void clearWarnings() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.clearWarnings();
-    }
-
-    /**
-     * Redirected to the {@link #release} method.
-     *
-     * @deprecated
-     **/
-    @Override
-    public void close() throws SQLException {
-        this.release(); // redirect to release method
-    }
-
-    @Override
-    public boolean execute(String sql) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.execute(sql);
-    }
-
-    @Override
-    public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.execute(sql, autoGeneratedKeys);
-    }
-
-    @Override
-    public boolean execute(String sql, int[] columnIndexes) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.execute(sql, columnIndexes);
-    }
-
-    @Override
-    public boolean execute(String sql, String[] columnNames) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.execute(sql, columnNames);
-    }
-
-    @Override
-    public int[] executeBatch() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeBatch();
-    }
-
-    @Override
-    public ResultSet executeQuery(String sql) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeQuery(sql);
-    }
-
-    @Override
-    public int executeUpdate(String sql) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeUpdate(sql);
-    }
-
-    @Override
-    public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeUpdate(sql, autoGeneratedKeys);
-    }
-
-    @Override
-    public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeUpdate(sql, columnIndexes);
-    }
-
-    @Override
-    public int executeUpdate(String sql, String[] columnNames) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.executeUpdate(sql, columnNames);
-    }
-
-    @Override
-    public Connection getConnection() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getConnection();
-    }
-
-    @Override
-    public int getFetchDirection() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getFetchDirection();
-    }
-
-    @Override
-    public void setFetchDirection(int direction) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setFetchDirection(direction);
-    }
-
-    @Override
-    public int getFetchSize() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getFetchSize();
-    }
-
-    @Override
-    public void setFetchSize(int rows) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setFetchSize(rows);
-    }
-
-    @Override
-    public ResultSet getGeneratedKeys() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getGeneratedKeys();
-    }
-
-    @Override
-    public int getMaxFieldSize() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getMaxFieldSize();
-    }
-
-    @Override
-    public void setMaxFieldSize(int max) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setMaxFieldSize(max);
-    }
-
-    @Override
-    public int getMaxRows() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getMaxRows();
-    }
-
-    @Override
-    public void setMaxRows(int max) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setMaxRows(max);
-    }
-
-    @Override
-    public boolean getMoreResults() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getMoreResults();
-    }
-
-    @Override
-    public boolean getMoreResults(int current) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getMoreResults(current);
-    }
-
-    @Override
-    public int getQueryTimeout() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getQueryTimeout();
-    }
-
-    @Override
-    public void setQueryTimeout(int seconds) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setQueryTimeout(seconds);
-    }
-
-    @Override
-    public ResultSet getResultSet() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getResultSet();
-    }
-
-    @Override
-    public int getResultSetConcurrency() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getResultSetConcurrency();
-    }
-
-    @Override
-    public int getResultSetHoldability() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getResultSetHoldability();
-    }
-
-    @Override
-    public int getResultSetType() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getResultSetType();
-    }
-
-    @Override
-    public int getUpdateCount() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getUpdateCount();
-    }
-
-    @Override
-    public SQLWarning getWarnings() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.getWarnings();
-    }
-
-    @Override
-    public boolean isClosed() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.isClosed();
-    }
-
-    @Override
-    public boolean isPoolable() throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.isPoolable();
-    }
-
-    @Override
-    public void setPoolable(boolean poolable) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setPoolable(poolable);
-    }
-
-    @Override
-    public void setCursorName(String name) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setCursorName(name);
-    }
-
-    @Override
-    public void setEscapeProcessing(boolean enable) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        this.ps.setEscapeProcessing(enable);
-    }
-
-    @Override
-    public boolean isWrapperFor(Class<?> iface) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.isWrapperFor(iface);
-    }
-
-    @Override
-    public <T> T unwrap(Class<T> iface) throws SQLException {
-        if (this.ps == null) {
-            throw new SQLException(ExceptionMessage);
-        }
-        return this.ps.unwrap(iface);
-    }
-
-    private class DebugParam {
-        private Object debugObject;
-        private boolean valueAssigned;
-
-        public DebugParam(Object debugObject) {
-            this.debugObject = debugObject;
-            valueAssigned = true;
-        }
-
-        public Object getDebugObject() {
-            return debugObject;
-        }
-
-        public boolean isValueAssigned() {
-            return valueAssigned;
-        }
-    }
-
-}
diff --git a/src/engine/powers/ActionsBase.java b/src/engine/powers/ActionsBase.java
index bf3596c7..6e36031f 100644
--- a/src/engine/powers/ActionsBase.java
+++ b/src/engine/powers/ActionsBase.java
@@ -12,11 +12,17 @@ package engine.powers;
 import engine.Enum.ModType;
 import engine.Enum.SourceType;
 import engine.Enum.StackType;
+import engine.gameManager.DbManager;
 import engine.gameManager.PowersManager;
-import engine.objects.*;
+import engine.objects.AbstractCharacter;
+import engine.objects.AbstractWorldObject;
+import engine.objects.PlayerBonuses;
+import engine.objects.Runegate;
 import engine.powers.poweractions.AbstractPowerAction;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.HashMap;
@@ -133,13 +139,15 @@ public class ActionsBase {
     //	}
 
     public static void getActionsBase(HashMap<String, PowersBase> powers, HashMap<String, AbstractPowerAction> apa) {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_action");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_action")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
             String IDString;
             ActionsBase toAdd;
             PowersBase pb;
+
             while (rs.next()) {
                 IDString = rs.getString("powerID");
                 pb = powers.get(IDString);
@@ -151,11 +159,10 @@ public class ActionsBase {
             rs.close();
         } catch (Exception e) {
             Logger.error(e.toString());
-        } finally {
-            ps.release();
         }
 
         int gateID = 5000;
+
         for (String IDString : Runegate.GetAllOpenGateIDStrings()) {
             gateID++;
             ActionsBase openGateActionBase = new ActionsBase(gateID, "OPENGATE", 5, 9999, 0, 0, true, "IgnoreStack", 0, true, false, false, PowersManager.getPowerActionByIDString("OPENGATE"));
diff --git a/src/engine/powers/EffectsBase.java b/src/engine/powers/EffectsBase.java
index 20150e90..ed6d80e0 100644
--- a/src/engine/powers/EffectsBase.java
+++ b/src/engine/powers/EffectsBase.java
@@ -29,6 +29,8 @@ import engine.powers.effectmodifiers.AbstractEffectModifier;
 import engine.server.MBServerStatics;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -169,21 +171,21 @@ public class EffectsBase {
     }
 
     public static void getFailConditions(HashMap<String, EffectsBase> effects) {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';");
 
-            ResultSet rs = ps.executeQuery();
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
+
             PowerFailCondition failCondition = null;
 
-            Object value;
             while (rs.next()) {
                 String fail = rs.getString("type");
 
 
                 String IDString = rs.getString("IDString");
-                int token = DbManager.hasher.SBStringHash(IDString);
                 failCondition = PowerFailCondition.valueOf(fail);
+
                 if (failCondition == null) {
                     Logger.error("Couldn't Find FailCondition " + fail + " for " + IDString);
                     continue;
@@ -200,11 +202,10 @@ public class EffectsBase {
 
                     case TakeDamage:
 
-
                         // dont go any further.
-                        if (eb == null) {
+
+                        if (eb == null)
                             break;
-                        }
 
                         eb.cancelOnTakeDamage = true;
 
@@ -217,7 +218,6 @@ public class EffectsBase {
                         String damageType2 = rs.getString("damageType2");
                         String damageType3 = rs.getString("damageType3");
 
-
                         if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty())
                             break;
 
@@ -274,10 +274,7 @@ public class EffectsBase {
             rs.close();
         } catch (Exception e) {
             Logger.error(e);
-        } finally {
-            ps.release();
         }
-
     }
 
     private static Enum.SourceType getDamageType(String name) {
diff --git a/src/engine/powers/FailCondition.java b/src/engine/powers/FailCondition.java
deleted file mode 100644
index faeece1e..00000000
--- a/src/engine/powers/FailCondition.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
-// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
-// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
-// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
-// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
-//      Magicbane Emulator Project © 2013 - 2022
-//                www.magicbane.com
-
-
-package engine.powers;
-
-import engine.objects.PreparedStatementShared;
-import org.pmw.tinylog.Logger;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-
-public class FailCondition {
-
-    private String IDString;
-    private Boolean forPower;
-    private String type;
-    private float amount;
-    private float ramp;
-    private boolean rampAdd;
-
-    // private String damageType1;
-    // private String damageType2;
-    // private String damageType3;
-
-    /**
-     * No Table ID Constructor
-     */
-    public FailCondition() {
-
-    }
-
-    /**
-     * ResultSet Constructor
-     */
-    public FailCondition(ResultSet rs) throws SQLException {
-
-        this.IDString = rs.getString("IDString");
-        this.forPower = (rs.getString("powerOrEffect").equals("Power")) ? true : false;
-        this.type = rs.getString("type");
-        this.amount = rs.getFloat("amount");
-        this.ramp = rs.getFloat("ramp");
-        this.rampAdd = (rs.getInt("useAddFormula") == 1) ? true : false;
-        // this.damageType1 = rs.getString("damageType1");
-        // this.damageType2 = rs.getString("damageType2");
-        // this.damageType3 = rs.getString("damageType3");
-    }
-
-    public static ArrayList<FailCondition> getAllFailConditions() {
-        PreparedStatementShared ps = null;
-        ArrayList<FailCondition> out = new ArrayList<>();
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM failconditions");
-            ResultSet rs = ps.executeQuery();
-            while (rs.next()) {
-                FailCondition toAdd = new FailCondition(rs);
-                out.add(toAdd);
-            }
-            rs.close();
-        } catch (Exception e) {
-            Logger.error(e);
-
-        } finally {
-            ps.release();
-        }
-        return out;
-    }
-
-    public String getIDString() {
-        return this.IDString;
-    }
-
-    public String getType() {
-        return this.type;
-    }
-
-    public boolean forPower() {
-        return this.forPower;
-    }
-
-    public float getAmount() {
-        return this.amount;
-    }
-
-    public float getRamp() {
-        return this.ramp;
-    }
-
-    public float getAmountForTrains(float trains) {
-        if (this.rampAdd)
-            return this.amount + (this.ramp * trains);
-        else
-            return this.amount * (1 + (this.ramp * trains));
-    }
-
-    public boolean useRampAdd() {
-        return this.rampAdd;
-    }
-
-    // public String getDamageType1() {
-    // return this.damageType1;
-    // }
-
-    // public String getDamageType2() {
-    // return this.damageType2;
-    // }
-
-    // public String getDamageType3() {
-    // return this.damageType3;
-    // }
-}
diff --git a/src/engine/powers/PowerPrereq.java b/src/engine/powers/PowerPrereq.java
index 086185a5..2085c047 100644
--- a/src/engine/powers/PowerPrereq.java
+++ b/src/engine/powers/PowerPrereq.java
@@ -9,9 +9,11 @@
 
 package engine.powers;
 
-import engine.objects.PreparedStatementShared;
+import engine.gameManager.DbManager;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.HashMap;
@@ -60,14 +62,17 @@ public class PowerPrereq {
     }
 
     public static void getAllPowerPrereqs(HashMap<String, PowersBase> powers) {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_powercastprereq");
-            ResultSet rs = ps.executeQuery();
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powercastprereq\"")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
+
             int type;
             String IDString;
             PowerPrereq toAdd;
             PowersBase pb;
+
             while (rs.next()) {
                 IDString = rs.getString("IDString");
                 pb = powers.get(IDString);
@@ -85,8 +90,6 @@ public class PowerPrereq {
             rs.close();
         } catch (Exception e) {
             Logger.error(e.toString());
-        } finally {
-            ps.release();
         }
     }
 
diff --git a/src/engine/powers/poweractions/AbstractPowerAction.java b/src/engine/powers/poweractions/AbstractPowerAction.java
index 5f8f2131..26197daa 100644
--- a/src/engine/powers/poweractions/AbstractPowerAction.java
+++ b/src/engine/powers/poweractions/AbstractPowerAction.java
@@ -15,12 +15,13 @@ import engine.math.Vector3fImmutable;
 import engine.objects.AbstractCharacter;
 import engine.objects.AbstractWorldObject;
 import engine.objects.Item;
-import engine.objects.PreparedStatementShared;
 import engine.powers.ActionsBase;
 import engine.powers.EffectsBase;
 import engine.powers.PowersBase;
 import org.pmw.tinylog.Logger;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.HashMap;
@@ -64,11 +65,14 @@ public abstract class AbstractPowerAction {
     }
 
     public static void getAllPowerActions(HashMap<String, AbstractPowerAction> powerActions, HashMap<Integer, AbstractPowerAction> powerActionsByID, HashMap<String, EffectsBase> effects) {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM static_power_poweraction");
-            ResultSet rs = ps.executeQuery();
+
+
+        try (Connection connection = DbManager.getConnection();
+             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_poweraction")) {
+
+            ResultSet rs = preparedStatement.executeQuery();
             String IDString, type;
+
             while (rs.next()) {
                 AbstractPowerAction apa;
                 type = rs.getString("type");
@@ -185,45 +189,14 @@ public abstract class AbstractPowerAction {
             rs.close();
         } catch (Exception e) {
             Logger.error(e.toString());
-        } finally {
-            ps.release();
         }
 
-
         //Add OpenGatePowerAction
         AbstractPowerAction openGateAction = new OpenGatePowerAction(5000, "OPENGATE", "OpenGate", false, 0);
         powerActions.put("OPENGATE", openGateAction);
         powerActionsByID.put(openGateAction.UUID, openGateAction);
     }
 
-    public static void loadValidItemFlags(HashMap<String, AbstractPowerAction> powerActions) {
-        PreparedStatementShared ps = null;
-        try {
-            ps = new PreparedStatementShared("SELECT * FROM `static_power_effect_allowed_item`");
-            ResultSet rs = ps.executeQuery();
-            String IDS;
-            long flags;
-            while (rs.next()) {
-                AbstractPowerAction apa;
-                flags = rs.getLong("flags");
-                IDS = rs.getString("IDString");
-                if (powerActions.containsKey(IDS)) {
-                    apa = powerActions.get(IDS);
-                    apa.validItemFlags = flags;
-                } else {
-                    Logger.error("Unable to find PowerAction " + IDS);
-                    continue;
-                }
-            }
-            rs.close();
-        } catch (Exception e) {
-            Logger.error(e.toString());
-        } finally {
-            ps.release();
-        }
-
-    }
-
     public void startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int numTrains, ActionsBase ab, PowersBase pb) {
         this._startAction(source, awo, targetLoc, numTrains, ab, pb);
     }
diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java
index 4b675e7a..7b487426 100644
--- a/src/engine/server/login/LoginServer.java
+++ b/src/engine/server/login/LoginServer.java
@@ -311,12 +311,6 @@ public class LoginServer {
             return false;
         }
 
-        PreparedStatementShared.submitPreparedStatementsCleaningJob();
-
-        if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) {
-            PreparedStatementShared.enableDebugging();
-        }
-
         return true;
     }
 
diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java
index af80feae..25a178a9 100644
--- a/src/engine/server/world/WorldServer.java
+++ b/src/engine/server/world/WorldServer.java
@@ -534,12 +534,6 @@ public class WorldServer {
 			return false;
 		}
 
-		PreparedStatementShared.submitPreparedStatementsCleaningJob();
-
-		if (MBServerStatics.DB_DEBUGGING_ON_BY_DEFAULT) {
-			PreparedStatementShared.enableDebugging();
-		}
-
 		return true;
 	}