]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Domain.java
UPD: minor consistency cleanups
[gigi.git] / src / org / cacert / gigi / dbObjects / Domain.java
index 283efdae6557441f5bc748334d5f14529c1e81bd..6b0e82830d07a2f9e0c4121a0910c3217d7674aa 100644 (file)
@@ -15,53 +15,10 @@ 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.dbObjects.DomainPingConfiguration.PingType;
 import org.cacert.gigi.util.PublicSuffixes;
 
 public class Domain implements IdCachable, Verifyable {
 
-    public class DomainPingExecution {
-
-        private String state;
-
-        private String type;
-
-        private String info;
-
-        private String result;
-
-        private DomainPingConfiguration config;
-
-        public DomainPingExecution(GigiResultSet rs) {
-            state = rs.getString(1);
-            type = rs.getString(2);
-            info = rs.getString(3);
-            result = rs.getString(4);
-            config = DomainPingConfiguration.getById(rs.getInt(5));
-        }
-
-        public String getState() {
-            return state;
-        }
-
-        public String getType() {
-            return type;
-        }
-
-        public String getInfo() {
-            return info;
-        }
-
-        public String getResult() {
-            return result;
-        }
-
-        public DomainPingConfiguration getConfig() {
-            return config;
-        }
-
-    }
-
     private User owner;
 
     private String suffix;
@@ -95,10 +52,12 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public Domain(User owner, String suffix) throws GigiApiException {
-        checkCertifyableDomain(suffix, owner.isInGroup(Group.CODESIGNING));
-        this.owner = owner;
-        this.suffix = suffix;
-
+        synchronized (Domain.class) {
+            checkCertifyableDomain(suffix, owner.isInGroup(Group.CODESIGNING));
+            this.owner = owner;
+            this.suffix = suffix;
+            insert();
+        }
     }
 
     public static void checkCertifyableDomain(String s, boolean hasPunycodeRight) throws GigiApiException {
@@ -169,19 +128,17 @@ public class Domain implements IdCachable, Verifyable {
         }
     }
 
-    public void insert() throws GigiApiException {
-        synchronized (Domain.class) {
-            if (id != 0) {
-                throw new GigiApiException("already inserted.");
-            }
-            checkInsert(suffix);
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
-            ps.setInt(1, owner.getId());
-            ps.setString(2, suffix);
-            ps.execute();
-            id = ps.lastInsertId();
-            myCache.put(this);
+    private void insert() throws GigiApiException {
+        if (id != 0) {
+            throw new GigiApiException("already inserted.");
         }
+        checkInsert(suffix);
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?");
+        ps.setInt(1, owner.getId());
+        ps.setString(2, suffix);
+        ps.execute();
+        id = ps.lastInsertId();
+        myCache.put(this);
     }
 
     public void delete() throws GigiApiException {
@@ -225,8 +182,8 @@ public class Domain implements IdCachable, Verifyable {
         return Collections.unmodifiableList(configs);
     }
 
-    public void addPing(PingType type, String config) throws GigiApiException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `pingconfig` `SET` `domainid`=?, `type`=?, `info`=?");
+    public void addPing(DomainPingType type, String config) throws GigiApiException {
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `pingconfig` SET `domainid`=?, `type`=?::`pingType`, `info`=?");
         ps.setInt(1, id);
         ps.setString(2, type.toString().toLowerCase());
         ps.setString(3, config);
@@ -235,7 +192,7 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public synchronized void verify(String hash) throws GigiApiException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` `SET` `state`='success' WHERE `challenge`=? AND `configId` `IN` (SELECT `id` FROM `pingconfig` WHERE `domainId`=?)");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=?)");
         ps.setString(1, hash);
         ps.setInt(2, id);
         ps.executeUpdate();
@@ -249,7 +206,7 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public DomainPingExecution[] getPings() throws GigiApiException {
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `state`, `type`, `info`, `result`, `configId` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configid` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepareScrollable("SELECT `state`, `type`, `info`, `result`, `configId` FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `pingconfig`.`domainid`=? ORDER BY `when` DESC;");
         ps.setInt(1, id);
         GigiResultSet rs = ps.executeQuery();
         rs.last();