X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomain.java;h=d4ffd8e28d377b038953a1cc2e2d808aeb16fd05;hp=eecf37669a3e91438e40ba0c8bf103c7de87caca;hb=36658ae4a12bea7095e02e45b1fe8400d85add8b;hpb=b05ce94112d4aa98c6fe6eba0ceddf973d3f09b2 diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index eecf3766..d4ffd8e2 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -17,18 +17,10 @@ public class Domain implements IdCachable, Verifyable { private int id; - private Domain(int id) { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `memid`, `domain` FROM `domains` WHERE `id`=? AND `deleted` IS NULL")) { - ps.setInt(1, id); - - GigiResultSet rs = ps.executeQuery(); - if ( !rs.next()) { - throw new IllegalArgumentException("Invalid domain id " + id); - } - this.id = id; - owner = CertificateOwner.getById(rs.getInt(1)); - suffix = rs.getString(2); - } + private Domain(GigiResultSet rs, int id) { + this.id = id; + owner = CertificateOwner.getById(rs.getInt(1)); + suffix = rs.getString(2); } public Domain(User actor, CertificateOwner owner, String suffix) throws GigiApiException { @@ -74,9 +66,12 @@ public class Domain implements IdCachable, Verifyable { if (id == 0) { throw new GigiApiException("not inserted."); } - try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domains` SET `deleted`=CURRENT_TIMESTAMP WHERE `id`=?")) { - ps.setInt(1, id); - ps.execute(); + synchronized (Domain.class) { + myCache.remove(this); + try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domains` SET `deleted`=CURRENT_TIMESTAMP WHERE `id`=?")) { + ps.setInt(1, id); + ps.execute(); + } } } @@ -163,10 +158,17 @@ public class Domain implements IdCachable, Verifyable { private static final ObjectCache myCache = new ObjectCache<>(); - public static synchronized Domain getById(int id) throws IllegalArgumentException { + public static synchronized Domain getById(int id) { Domain em = myCache.get(id); if (em == null) { - myCache.put(em = new Domain(id)); + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `memid`, `domain` FROM `domains` WHERE `id`=? AND `deleted` IS NULL")) { + ps.setInt(1, id); + GigiResultSet rs = ps.executeQuery(); + if ( !rs.next()) { + return null; + } + myCache.put(em = new Domain(rs, id)); + } } return em; }