[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...

Gavin King gavin.king at jboss.com
Mon Oct 23 14:09:29 EDT 2006


  User: gavin   
  Date: 06/10/23 14:09:29

  Modified:    src/main/org/jboss/seam/interceptors 
                        RollbackInterceptor.java
  Log:
  exceptions.xml
  apply ejb3 rollback rules to javabeans
  
  Revision  Changes    Path
  1.11      +37 -24    jboss-seam/src/main/org/jboss/seam/interceptors/RollbackInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RollbackInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/RollbackInterceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- RollbackInterceptor.java	10 Oct 2006 06:43:16 -0000	1.10
  +++ RollbackInterceptor.java	23 Oct 2006 18:09:29 -0000	1.11
  @@ -1,9 +1,11 @@
  -//$Id: RollbackInterceptor.java,v 1.10 2006/10/10 06:43:16 gavin Exp $
  +//$Id: RollbackInterceptor.java,v 1.11 2006/10/23 18:09:29 gavin Exp $
   package org.jboss.seam.interceptors;
   
  +import java.lang.reflect.Method;
   import java.util.Arrays;
   import java.util.List;
   
  +import javax.ejb.ApplicationException;
   import javax.interceptor.AroundInvoke;
   import javax.interceptor.InvocationContext;
   
  @@ -28,14 +30,7 @@
         try
         {
            final Object result = invocation.proceed();
  -         if (invocation.getMethod().isAnnotationPresent(Rollback.class)) 
  -         {
  -            String[] outcomes = invocation.getMethod().getAnnotation(Rollback.class).ifOutcome();
  -            List<String> outcomeList = Arrays.asList(outcomes);
  -            boolean isRollback = outcomes.length==0 || 
  -                  ( result==null && outcomeList.contains(Outcome.REDISPLAY) ) || 
  -                  outcomeList.contains(result);
  -            if ( isRollback )
  +         if ( isRollbackRequired( invocation.getMethod(), result ) )
               {
                  if ( getComponent().getType()==ComponentType.JAVA_BEAN )
                  {
  @@ -49,23 +44,41 @@
                     Transactions.getEJBContext().setRollbackOnly();
                  }
               }
  -         }
            return result;
         }
         catch (Exception e)
         {
  -         //Any exception that propagates out of a JavaBean component
  -         //causes a transaction rollback
  +         //Reproduce the EJB3 rollback rules for JavaBean components
            if ( getComponent().getType()==ComponentType.JAVA_BEAN )
            {
  +            if ( isRollbackRequired(e) )
  +            {
               try
               {
                  Transactions.setUserTransactionRollbackOnly();
               }
               catch (Exception te) {} //swallow
            }
  +         }
            throw e;
         }
      }
      
  +   private boolean isRollbackRequired(Method method, final Object result)
  +   {
  +      if ( !method.isAnnotationPresent(Rollback.class) ) return false;
  +      String[] outcomes = method.getAnnotation(Rollback.class).ifOutcome();
  +      List<String> outcomeList = Arrays.asList(outcomes);
  +      return outcomes.length==0 || 
  +            ( result==null && outcomeList.contains(Outcome.REDISPLAY) ) || 
  +            outcomeList.contains(result);
  +   }
  +
  +   private boolean isRollbackRequired(Exception e)
  +   {
  +      Class<? extends Exception> clazz = e.getClass();
  +      return ( (e instanceof RuntimeException) && !clazz.isAnnotationPresent(ApplicationException.class) ) || 
  +            ( clazz.isAnnotationPresent(ApplicationException.class) && clazz.getAnnotation(ApplicationException.class).rollback() );
  +   }
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list