X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fping%2FDomainPinger.java;h=942334920fc0432b434913379b0cb641959046e2;hb=ab158a1d59d4fc38f2ebffb4939199870314dcb6;hp=550c86afa176f6391e5b83e001c6d07efbb6d42a;hpb=33a87a70ba2320451c3b3b1faa9b487dbcbd3540;p=gigi.git diff --git a/src/org/cacert/gigi/ping/DomainPinger.java b/src/org/cacert/gigi/ping/DomainPinger.java index 550c86af..94233492 100644 --- a/src/org/cacert/gigi/ping/DomainPinger.java +++ b/src/org/cacert/gigi/ping/DomainPinger.java @@ -1,6 +1,5 @@ package org.cacert.gigi.ping; -import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.dbObjects.CertificateOwner; import org.cacert.gigi.dbObjects.Domain; @@ -14,22 +13,24 @@ public abstract class DomainPinger { public abstract void ping(Domain domain, String configuration, CertificateOwner target, int confId); protected static void enterPingResult(int configId, String state, String result, String token) { - GigiPreparedStatement enterPingResult = DatabaseConnection.getInstance().prepare("INSERT INTO `domainPinglog` SET `configId`=?, `state`=?::`pingState`, `result`=?, `challenge`=?"); - enterPingResult.setInt(1, configId); - enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == state ? "open" : DomainPinger.PING_SUCCEDED.equals(state) ? "success" : "failed"); - enterPingResult.setString(3, result); - enterPingResult.setString(4, token); - enterPingResult.execute(); + try (GigiPreparedStatement enterPingResult = new GigiPreparedStatement("INSERT INTO `domainPinglog` SET `configId`=?, `state`=?::`pingState`, `result`=?, `challenge`=?")) { + enterPingResult.setInt(1, configId); + enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == state ? "open" : DomainPinger.PING_SUCCEDED.equals(state) ? "success" : "failed"); + enterPingResult.setString(3, result); + enterPingResult.setString(4, token); + enterPingResult.execute(); + } } - protected static void updatePingResult(int configId, String token, String state, String result) { - GigiPreparedStatement updatePingResult = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`=?::`pingState`, `result`=? WHERE `configId`=? AND `challenge`=?"); - updatePingResult.setString(1, DomainPinger.PING_STILL_PENDING == state ? "open" : DomainPinger.PING_SUCCEDED.equals(state) ? "success" : "failed"); - updatePingResult.setString(2, result); - updatePingResult.setInt(3, configId); - updatePingResult.setString(4, token); - updatePingResult.execute(); + protected static void updatePingResult(int configId, String state, String result, String token) { + try (GigiPreparedStatement updatePingResult = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`=?::`pingState`, `result`=? WHERE `configId`=? AND `challenge`=?")) { + updatePingResult.setString(1, DomainPinger.PING_STILL_PENDING == state ? "open" : DomainPinger.PING_SUCCEDED.equals(state) ? "success" : "failed"); + updatePingResult.setString(2, result); + updatePingResult.setInt(3, configId); + updatePingResult.setString(4, token); + updatePingResult.execute(); + } } }