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