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