From 4daee03f0da63186937c6556b0d81c793904bfaa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 20 May 2023 19:09:28 -0400 Subject: [PATCH] Refactored to remove abstraction. --- src/engine/db/handlers/dbAccountHandler.java | 6 ++-- .../db/handlers/dbBlueprintHandler.java | 31 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/engine/db/handlers/dbAccountHandler.java b/src/engine/db/handlers/dbAccountHandler.java index f94f9fab..577c264e 100644 --- a/src/engine/db/handlers/dbAccountHandler.java +++ b/src/engine/db/handlers/dbAccountHandler.java @@ -196,11 +196,11 @@ public class dbAccountHandler extends dbHandlerBase { return this.GET_ACCOUNT(Account.AccountsMap.get(uname)); try (Connection connection = DbManager.getConnection(); - PreparedStatement accountQuery = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { - accountQuery.setString(1, uname); + preparedStatement.setString(1, uname); - ResultSet rs = accountQuery.executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); account = (Account) getObjectFromRs(rs); } catch (SQLException e) { diff --git a/src/engine/db/handlers/dbBlueprintHandler.java b/src/engine/db/handlers/dbBlueprintHandler.java index 7ecd4dfe..194ca9fe 100644 --- a/src/engine/db/handlers/dbBlueprintHandler.java +++ b/src/engine/db/handlers/dbBlueprintHandler.java @@ -1,8 +1,11 @@ package engine.db.handlers; +import engine.gameManager.DbManager; import engine.objects.Blueprint; 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; @@ -22,10 +25,10 @@ public class dbBlueprintHandler extends dbHandlerBase { int doorNum; int recordsRead = 0; - prepareCallable("SELECT * FROM static_building_doors ORDER BY doorMeshUUID ASC"); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_doors ORDER BY doorMeshUUID ASC")) { - try { - ResultSet rs = executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { @@ -35,13 +38,11 @@ public class dbBlueprintHandler extends dbHandlerBase { doorInfo.put(doorUUID, doorNum); } - Logger.info( "read: " + recordsRead + " cached: " + doorInfo.size()); - } catch (SQLException e) { - Logger.error("LoadAllDoorNumbers: " + e.getErrorCode() + ' ' + e.getMessage(), e); - } finally { - closeCallable(); + Logger.error(e); } + + Logger.info("read: " + recordsRead + " cached: " + doorInfo.size()); return doorInfo; } @@ -53,10 +54,10 @@ public class dbBlueprintHandler extends dbHandlerBase { blueprints = new HashMap<>(); int recordsRead = 0; - prepareCallable("SELECT * FROM static_building_blueprint"); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { - try { - ResultSet rs = executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { @@ -74,13 +75,11 @@ public class dbBlueprintHandler extends dbHandlerBase { } - Logger.info( "read: " + recordsRead + " cached: " + blueprints.size()); - } catch (SQLException e) { - Logger.error("LoadAllBlueprints: " + e.getErrorCode() + ' ' + e.getMessage(), e); - } finally { - closeCallable(); + Logger.error(e); } + + Logger.info("read: " + recordsRead + " cached: " + blueprints.size()); return blueprints; } }