[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/interceptors ...

Ben Wang bwang at jboss.com
Sun Jul 30 22:27:37 EDT 2006


  User: bwang   
  Date: 06/07/30 22:27:37

  Added:       src-50/org/jboss/cache/pojo/interceptors 
                        PojoFailedTxMockupInterceptor.java
  Log:
  Test cases for undo operation.
  
  Revision  Changes    Path
  1.1      date: 2006/07/31 02:27:37;  author: bwang;  state: Exp;JBossCache/src-50/org/jboss/cache/pojo/interceptors/PojoFailedTxMockupInterceptor.java
  
  Index: PojoFailedTxMockupInterceptor.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.interceptors;
  
  import org.jboss.aop.joinpoint.Invocation;
  import org.jboss.aop.joinpoint.MethodInvocation;
  
  import javax.transaction.Transaction;
  
  /**
   * Interceptor to mockup tx failure that resulting in rollback. User can simulate a rollback
   * by setting the static method <code>setRollback</code>. Note that you will need to use
   * setRollback for every method call, that is, it will reset itself after a rollback
   * has been performed.
   *
   * @author Ben Wang
   * @version $Id: PojoFailedTxMockupInterceptor.java,v 1.1 2006/07/31 02:27:37 bwang Exp $
   */
  public class PojoFailedTxMockupInterceptor extends AbstractInterceptor
  {
     public static boolean TX_ROLLBACK = false;
  
     public static void setTxRollback(boolean isTrue)
     {
        TX_ROLLBACK = isTrue;
     }
  
     public Object invoke(Invocation in) throws Throwable
     {
        if (!(in instanceof MethodInvocation))
        {
           throw new IllegalArgumentException(
                   "PojoFailedTxMockupInterceptor.invoke(): invocation not MethodInvocation");
        }
        MethodInvocation invocation = (MethodInvocation) in;
  
        Transaction tx = getCache(invocation).getTransaction();
        try
        {
           Object obj = null;
           obj = invocation.invokeNext(); // proceed to next advice or actual call
           if(TX_ROLLBACK)
           {
              tx.setRollbackOnly();
              TX_ROLLBACK = false;
           }
           return obj;
        } finally
        {
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list