Coverage Report - org.kuali.rice.ken.util.TracingTransactionInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
TracingTransactionInterceptor
0%
0/25
0%
0/13
6.25
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ken.util;
 17  
 
 18  
 import javax.transaction.Status;
 19  
 import javax.transaction.UserTransaction;
 20  
 
 21  
 import org.aopalliance.intercept.MethodInterceptor;
 22  
 import org.aopalliance.intercept.MethodInvocation;
 23  
 import org.apache.log4j.Level;
 24  
 import org.apache.log4j.Logger;
 25  
 import org.springframework.transaction.jta.JtaTransactionManager;
 26  
 
 27  
 /**
 28  
  * Interceptor implementation that simply logs the JTA transaction status
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class TracingTransactionInterceptor implements MethodInterceptor {
 32  0
     private static final Logger LOG = Logger.getLogger(TracingTransactionInterceptor.class);
 33  
 
 34  
     private Level level;
 35  
     private JtaTransactionManager txManager;
 36  
 
 37  
     /**
 38  
      * @param lvl
 39  
      */
 40  
     public void setLevel(String lvl) {
 41  0
         level = Level.toLevel(lvl);
 42  0
     }
 43  
 
 44  
     /**
 45  
      * @param manager
 46  
      */
 47  
     public void setJtaTransactionManager(JtaTransactionManager manager) {
 48  0
         this.txManager = manager;
 49  0
     }
 50  
 
 51  
     /**
 52  
      * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
 53  
      */
 54  
     public Object invoke(MethodInvocation invocation) throws Throwable {
 55  0
         StringBuilder sb = new StringBuilder();
 56  0
         UserTransaction tx = txManager.getUserTransaction();
 57  0
         if (tx == null) {
 58  0
             sb.append("null");
 59  
         } else {
 60  0
             sb.append(toString(tx.getStatus()));
 61  
         }
 62  0
         LOG.log(level, invocation.getMethod() +" UserTransaction: " + sb);
 63  0
         return invocation.proceed();
 64  
     }
 65  
 
 66  
     /**
 67  
      * @param txStatus
 68  
      * @return String
 69  
      */
 70  
     private static final String toString(int txStatus) {
 71  0
         switch (txStatus) {
 72  0
             case Status.STATUS_ACTIVE: return "STATUS_ACTIVE";
 73  0
             case Status.STATUS_COMMITTED: return "STATUS_COMMITTED";  
 74  0
             case Status.STATUS_COMMITTING: return "STATUS_COMMITTING";
 75  0
             case Status.STATUS_MARKED_ROLLBACK: return "STATUS_MARKED_ROLLBACK";
 76  0
             case Status.STATUS_NO_TRANSACTION: return "STATUS_NO_TRANSACTION";
 77  0
             case Status.STATUS_PREPARED: return "STATUS_PREPARED";
 78  0
             case Status.STATUS_PREPARING: return "STATUS_PREPARING";
 79  0
             case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK";
 80  0
             case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK";
 81  0
             case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN";
 82  0
             default: return "unknown status: " + txStatus;
 83  
         }
 84  
     }
 85  
 }