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
+10 -13
View File
@@ -29,6 +29,8 @@ import engine.powers.effectmodifiers.AbstractEffectModifier;
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;
@@ -169,21 +171,21 @@ public class EffectsBase {
}
public static void getFailConditions(HashMap<String, EffectsBase> effects) {
PreparedStatementShared ps = null;
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';");
ResultSet rs = ps.executeQuery();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_failcondition WHERE powerOrEffect = 'Effect';")) {
ResultSet rs = preparedStatement.executeQuery();
PowerFailCondition failCondition = null;
Object value;
while (rs.next()) {
String fail = rs.getString("type");
String IDString = rs.getString("IDString");
int token = DbManager.hasher.SBStringHash(IDString);
failCondition = PowerFailCondition.valueOf(fail);
if (failCondition == null) {
Logger.error("Couldn't Find FailCondition " + fail + " for " + IDString);
continue;
@@ -200,11 +202,10 @@ public class EffectsBase {
case TakeDamage:
// dont go any further.
if (eb == null) {
if (eb == null)
break;
}
eb.cancelOnTakeDamage = true;
@@ -217,7 +218,6 @@ public class EffectsBase {
String damageType2 = rs.getString("damageType2");
String damageType3 = rs.getString("damageType3");
if (damageType1.isEmpty() && damageType2.isEmpty() && damageType3.isEmpty())
break;
@@ -274,10 +274,7 @@ public class EffectsBase {
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
}
}
private static Enum.SourceType getDamageType(String name) {