[seam-commits] Seam SVN: r13514 - in modules/persistence/trunk/impl/src: test/java/org/jboss/seam/persistence/transactions/test and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jul 27 04:32:40 EDT 2010


Author: swd847
Date: 2010-07-27 04:32:39 -0400 (Tue, 27 Jul 2010)
New Revision: 13514

Modified:
   modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java
   modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
   modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java
Log:
update tests and NPE fix


Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java	2010-07-27 07:48:57 UTC (rev 13513)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java	2010-07-27 08:32:39 UTC (rev 13514)
@@ -29,7 +29,9 @@
 import javax.interceptor.InterceptorBinding;
 
 /**
- * Interceptor binding for {@link Transactional} beans
+ * Interceptor binding for the seam transaction interceceptor. This binding is
+ * applied automatically by a portable extension, the user should not need to
+ * apply it themselves
  * 
  * @author Stuart Douglas
  * 
@@ -37,7 +39,7 @@
 @Retention(RetentionPolicy.RUNTIME)
 @InterceptorBinding
 @Target( { ElementType.TYPE, ElementType.METHOD })
-public @interface TransactionalInterceptorBinding
+ at interface TransactionalInterceptorBinding
 {
 
 }

Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java	2010-07-27 07:48:57 UTC (rev 13513)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java	2010-07-27 08:32:39 UTC (rev 13514)
@@ -23,7 +23,6 @@
 
 import javax.ejb.ApplicationException;
 import javax.transaction.Status;
-import javax.transaction.UserTransaction;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,14 +48,13 @@
       boolean transactionActive = transaction.isActiveOrMarkedRollback() || transaction.isRolledBack();
       // TODO: temp workaround, what should we really do in this case??
       boolean newTransactionRequired = isNewTransactionRequired(transactionActive);
-      UserTransaction userTransaction = newTransactionRequired ? transaction : null;
 
       try
       {
          if (newTransactionRequired)
          {
             log.debug("beginning transaction");
-            userTransaction.begin();
+            transaction.begin();
          }
 
          T result = work();
@@ -65,34 +63,34 @@
             if (transaction.isMarkedRollback())
             {
                log.debug("rolling back transaction");
-               userTransaction.rollback();
+               transaction.rollback();
             }
             else
             {
                log.debug("committing transaction");
-               userTransaction.commit();
+               transaction.commit();
             }
          }
          return result;
       }
       catch (Exception e)
       {
-         if (newTransactionRequired && userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION )
+         if (newTransactionRequired && transaction.getStatus() != Status.STATUS_NO_TRANSACTION)
          {
-            if(isRollbackRequired(e, true))
+            if (isRollbackRequired(e, true))
             {
                log.debug("rolling back transaction");
-               userTransaction.rollback();
+               transaction.rollback();
             }
             else
             {
                log.debug("committing transaction after ApplicationException(rollback=false):" + e.getMessage());
-               userTransaction.commit();
+               transaction.commit();
             }
          }
-         else if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION && isRollbackRequired(e, true))
+         else if (transaction.getStatus() != Status.STATUS_NO_TRANSACTION && isRollbackRequired(e, true))
          {
-            userTransaction.setRollbackOnly();
+            transaction.setRollbackOnly();
          }
 
          throw e;

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java	2010-07-27 07:48:57 UTC (rev 13513)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java	2010-07-27 08:32:39 UTC (rev 13514)
@@ -26,6 +26,7 @@
 import javax.inject.Inject;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
+import javax.persistence.TransactionRequiredException;
 import javax.transaction.HeuristicMixedException;
 import javax.transaction.HeuristicRollbackException;
 import javax.transaction.NotSupportedException;
@@ -112,6 +113,12 @@
       assertHotels(2);
    }
 
+   @Test(expected = TransactionRequiredException.class)
+   public void testTransactionInterceptorMethodOverrides()
+   {
+      bean.tryAndAddHotelWithNoTransaction();
+   }
+
    public void assertHotels(int count) throws NotSupportedException, SystemException
    {
       transaction.begin();

Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java	2010-07-27 07:48:57 UTC (rev 13513)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java	2010-07-27 08:32:39 UTC (rev 13514)
@@ -62,4 +62,13 @@
       throw new DontRollBackException();
    }
 
+   @Transactional(TransactionPropagation.NEVER)
+   public void tryAndAddHotelWithNoTransaction()
+   {
+      entityManager.joinTransaction();
+      Hotel h = new Hotel("test3", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+      entityManager.persist(h);
+      entityManager.flush();
+   }
+
 }



More information about the seam-commits mailing list