X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomainPingConfiguration.java;h=baa7b7b00b69c1affad4e21391f67e425f08b01a;hb=ccfe74bbb68976be461d215c1d313966de7ee3d5;hp=4c4931f5a13280c814d05667279a8b8fb892b3a9;hpb=0dbbc40ce4e48c40e08ab43f6e5a02441ed6c90c;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java b/src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java index 4c4931f5..baa7b7b0 100644 --- a/src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java +++ b/src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java @@ -7,7 +7,6 @@ import java.util.Map; import org.cacert.gigi.Gigi; import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.output.template.Scope; @@ -15,30 +14,27 @@ import org.cacert.gigi.output.template.SprintfCommand; public class DomainPingConfiguration implements IdCachable { - public static enum PingType { - EMAIL, DNS, HTTP, SSL; - } - private int id; private Domain target; - private PingType type; + private DomainPingType type; private String info; private DomainPingConfiguration(int id) { - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `id`, `domainid`, `type`, `info` FROM `pingconfig` WHERE `id`=?"); - ps.setInt(1, id); - - GigiResultSet rs = ps.executeQuery(); - if ( !rs.next()) { - throw new IllegalArgumentException("Invalid pingconfig id " + id); + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id`, `domainid`, `type`, `info` FROM `pingconfig` WHERE `id`=?")) { + ps.setInt(1, id); + + GigiResultSet rs = ps.executeQuery(); + if ( !rs.next()) { + throw new IllegalArgumentException("Invalid pingconfig id " + id); + } + this.id = rs.getInt("id"); + target = Domain.getById(rs.getInt("domainid")); + type = DomainPingType.valueOf(rs.getString("type").toUpperCase()); + info = rs.getString("info"); } - this.id = rs.getInt("id"); - target = Domain.getById(rs.getInt("domainid")); - type = PingType.valueOf(rs.getString("type").toUpperCase()); - info = rs.getString("info"); } @Override @@ -50,7 +46,7 @@ public class DomainPingConfiguration implements IdCachable { return target; } - public PingType getType() { + public DomainPingType getType() { return type; } @@ -69,23 +65,25 @@ public class DomainPingConfiguration implements IdCachable { } public Date getLastExecution() { - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? ORDER BY `when` DESC LIMIT 1"); - ps.setInt(1, id); - GigiResultSet rs = ps.executeQuery(); - if (rs.next()) { - return new Date(rs.getTimestamp("stamp").getTime()); + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? ORDER BY `when` DESC LIMIT 1")) { + ps.setInt(1, id); + GigiResultSet rs = ps.executeQuery(); + if (rs.next()) { + return new Date(rs.getTimestamp("stamp").getTime()); + } + return new Date(0); } - return new Date(0); } public Date getLastSuccess() { - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? AND state='success' ORDER BY `when` DESC LIMIT 1"); - ps.setInt(1, id); - GigiResultSet rs = ps.executeQuery(); - if (rs.next()) { - return new Date(rs.getTimestamp("stamp").getTime()); + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? AND state='success' ORDER BY `when` DESC LIMIT 1")) { + ps.setInt(1, id); + GigiResultSet rs = ps.executeQuery(); + if (rs.next()) { + return new Date(rs.getTimestamp("stamp").getTime()); + } + return new Date(0); } - return new Date(0); } public synchronized void requestReping() throws GigiApiException {