Refactored out duplicate db interface.

This commit is contained in:
2024-03-14 15:22:38 -04:00
parent 4646d03bdd
commit f2d28fd7af
13 changed files with 86 additions and 1576 deletions
+16 -12
View File
@@ -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
*/