]> WPIA git - gigi.git/commitdiff
Fix: synchronization for db objects
authorFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 23:00:46 +0000 (00:00 +0100)
committerFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 23:00:46 +0000 (00:00 +0100)
src/org/cacert/gigi/dbObjects/EmailAddress.java

index 3ca39b6d2c9d2178b6e2564965d772c1e5d804db..13e2e457c769c58b9159e2ab6b3ce72fedbfde40 100644 (file)
@@ -47,16 +47,16 @@ public class EmailAddress implements IdCachable {
 
     public void insert(Language l) throws GigiApiException {
         try {
-            if (id != 0) {
-                throw new IllegalStateException("already inserted.");
-            }
-            GigiPreparedStatement psCheck = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `emails` WHERE email=? AND deleted is NULL");
-            GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `emails` SET memid=?, hash=?, email=?");
-            ps.setInt(1, owner.getId());
-            ps.setString(2, hash);
-            ps.setString(3, address);
-            psCheck.setString(1, address);
             synchronized (EmailAddress.class) {
+                if (id != 0) {
+                    throw new IllegalStateException("already inserted.");
+                }
+                GigiPreparedStatement psCheck = DatabaseConnection.getInstance().prepare("SELECT 1 FROM `emails` WHERE email=? AND deleted is NULL");
+                GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `emails` SET memid=?, hash=?, email=?");
+                ps.setInt(1, owner.getId());
+                ps.setString(2, hash);
+                ps.setString(3, address);
+                psCheck.setString(1, address);
                 GigiResultSet res = psCheck.executeQuery();
                 if (res.next()) {
                     throw new GigiApiException("The email is currently valid");