Commits

Anonymous committed 5f44dc6

Remove should be in a transaction

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@181bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

Comments (0)

Files changed (2)

providers/ejb3/src/com/opensymphony/module/propertyset/ejb3/EJBPropertySet.java

 import java.io.IOException;
 import java.io.Serializable;
 
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
+import java.util.*;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
     }
 
     public void remove(String entityName, long entityId) throws PropertyException {
-        Query q = entityManager.createQuery("delete PropertyEntry p where p.primaryKey.entityId=:entityId and p.primaryKey.entityName=:entityName");
+        boolean mustCommit = joinTransaction();
+        Query q = entityManager.createNamedQuery("values");
         q.setParameter("entityId", entityId);
         q.setParameter("entityName", entityName);
-        q.executeUpdate();
+
+        //idiot jalopy blows up on a real man's for loop, so we have to use jdk14 wanky version
+        List l = q.getResultList();
+
+        for (Iterator iterator = l.iterator(); iterator.hasNext();) {
+            Object o = iterator.next();
+            entityManager.remove(o);
+        }
+
+        if (mustCommit) {
+            entityManager.getTransaction().commit();
+        }
     }
 
     public boolean supportsType(int type) {
         EntryPK pk = new EntryPK(entityName, entityId, key);
         PropertyEntry item;
 
-        boolean mustCommit = false;
-
-        switch (transactionType) {
-        case JTA:
-            entityManager.joinTransaction();
-
-            break;
-
-        case RESOURCE_LOCAL:
-
-            EntityTransaction tx = entityManager.getTransaction();
-
-            if (!tx.isActive()) {
-                tx.begin();
-                mustCommit = true;
-            }
-
-            break;
-        }
+        boolean mustCommit = joinTransaction();
 
         item = entityManager.find(PropertyEntry.class, pk);
 
         throw new PropertyException("type " + type(type) + " not supported");
     }
 
+    private boolean joinTransaction() {
+        boolean mustCommit = false;
+
+        switch (transactionType) {
+        case JTA:
+            entityManager.joinTransaction();
+
+            break;
+
+        case RESOURCE_LOCAL:
+
+            EntityTransaction tx = entityManager.getTransaction();
+
+            if (!tx.isActive()) {
+                tx.begin();
+                mustCommit = true;
+            }
+
+            break;
+        }
+
+        return mustCommit;
+    }
+
     /**
      * Parse XML document from String in byte array.
      */

providers/ejb3/src/com/opensymphony/module/propertyset/ejb3/PropertyEntry.java

 @Entity
 @Table(name="OS_PROPERTIES")
 @NamedQueries({
+@NamedQuery(name="entries", query="select p from PropertyEntry p where p.primaryKey.entityName=:entityName and p.primaryKey.entityId=:entityId"),
 @NamedQuery(name="keys", query="select p.primaryKey.key from PropertyEntry p where p.primaryKey.entityName=:entityName and p.primaryKey.entityId=:entityId"),
 @NamedQuery(name="keys.prefix", query="select p.primaryKey.key from PropertyEntry p where p.primaryKey.entityName=:entityName and p.primaryKey.entityId=:entityId and p.primaryKey.key like :prefix"),
 @NamedQuery(name="keys.type", query="select p.primaryKey.key from PropertyEntry p where p.primaryKey.entityName=:entityName and p.primaryKey.entityId=:entityId and p.type=:type"),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.