forked from MagicBane/Server
Refactored out duplicate db interface.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user