Anonymous avatar Anonymous committed 9f7872a

Fixed tx handling for ejb3

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

Comments (0)

Files changed (3)

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

 import java.util.Map;
 
 import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
 import javax.persistence.Query;
 
 
         EntryPK pk = new EntryPK(entityName, entityId, key);
         PropertyEntry item;
 
+        boolean mustCommit = false;
+
+        try {
+            entityManager.joinTransaction();
+        } catch (Exception ex) {
+            EntityTransaction tx = entityManager.getTransaction();
+
+            if (!tx.isActive()) {
+                tx.begin();
+                mustCommit = true;
+            }
+        }
+
         item = entityManager.find(PropertyEntry.class, pk);
 
         boolean update = item != null;
         } else {
             entityManager.persist(item);
         }
+
+        if (mustCommit) {
+            entityManager.getTransaction().commit();
+        }
     }
 
     protected Object get(int type, String key) throws PropertyException {

src/test/com/opensymphony/module/propertyset/DatabaseHelper.java

                 sqlLine = sqls[i].trim();
                 sqlLine.replace("\r", "");
                 sqlLine.replace("\n", "");
-  
+
                 //String s = sqls[i];
                 if ((sqlLine.length() > 0) && (sqlLine.charAt(0) != '#')) {
                     try {

src/test/com/opensymphony/module/propertyset/ejb3/EJBPropertySetTest.java

  *         Date: Nov 8, 2005
  *         Time: 6:11:09 PM
  */
-public class EJBPropertySetTest /*extends AbstractPropertySetTest*/ {
+public class EJBPropertySetTest extends AbstractPropertySetTest {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     private static Properties props = new Properties();
     static {
         DatabaseHelper.createDatabase("");
         props.put("hibernate.dialect", "org.hibernate.dialect.MckoiDialect");
-        props.put("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
+        props.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
     }
 
     private static final EntityManagerFactory factory = Persistence.createEntityManagerFactory("propertyset", props);
         EntityManager em = factory.createEntityManager();
         em.getTransaction().begin();
         args.put("manager", em);
-        //ps = PropertySetManager.getInstance("ejb3", args);
+        ps = PropertySetManager.getInstance("ejb3", args);
     }
 
     protected void tearDown() throws Exception {
-        //ps.remove();
+        ps.remove();
     }
 }
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.