]> WPIA git - gigi.git/commitdiff
fix: make domain initialization pattern compliant to other dbObject
authorFelix Dörre <felix@dogcraft.de>
Thu, 18 Aug 2016 17:52:14 +0000 (19:52 +0200)
committerFelix Dörre <felix@dogcraft.de>
Fri, 19 Aug 2016 07:30:04 +0000 (09:30 +0200)
Change-Id: I07ee56f1b63e6da3c5dc11e65be4ccdcbad0aca5

src/org/cacert/gigi/dbObjects/Domain.java

index eecf37669a3e91438e40ba0c8bf103c7de87caca..043277cf4ab3f2108a90efe040635e25d172ec12 100644 (file)
@@ -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 {
@@ -163,10 +155,17 @@ public class Domain implements IdCachable, Verifyable {
 
     private static final ObjectCache<Domain> 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;
     }