1 package org.cacert.gigi.dbObjects;
3 import java.sql.PreparedStatement;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
7 import org.cacert.gigi.database.DatabaseConnection;
9 public class DomainPingConfiguration implements IdCachable {
11 public static enum PingType {
12 EMAIL, DNS, HTTP, SSL;
17 private Domain target;
19 private PingType type;
23 private DomainPingConfiguration(int id) throws SQLException {
24 PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id, domainid, type, info FROM pingconfig WHERE id=?");
27 ResultSet rs = ps.executeQuery();
29 throw new IllegalArgumentException("Invalid pingconfig id " + id);
31 this.id = rs.getInt("id");
32 target = Domain.getById(rs.getInt("domainid"));
33 type = PingType.valueOf(rs.getString("type").toUpperCase());
34 info = rs.getString("info");
42 public Domain getTarget() {
46 public PingType getType() {
50 public String getInfo() {
54 private static ObjectCache<DomainPingConfiguration> cache = new ObjectCache<>();
56 public static DomainPingConfiguration getById(int id) {
57 DomainPingConfiguration res = cache.get(id);
60 cache.put(res = new DomainPingConfiguration(id));
61 } catch (SQLException e) {
62 throw new IllegalArgumentException(e);
68 public void requestReping() {
70 PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE pingconfig set reping='y' WHERE id=?");
73 } catch (SQLException e) {