Coverage Report - org.kuali.rice.core.impl.util.spring.AnnotationAndNameMatchingTransactionAttributeSource
 
Classes in this File Line Coverage Branch Coverage Complexity
AnnotationAndNameMatchingTransactionAttributeSource
0%
0/17
0%
0/6
2
 
 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.core.impl.util.spring;
 17  
 
 18  
 import java.lang.reflect.Method;
 19  
 
 20  
 import org.apache.commons.beanutils.PropertyUtils;
 21  
 import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
 22  
 import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource;
 23  
 import org.springframework.transaction.interceptor.TransactionAttribute;
 24  
 
 25  
 /**
 26  
  * Classes are not considered for name matching, if they do not have the specified annotation on the class or method. However, the
 27  
  * name matching takes precendence, if they do.
 28  
  */
 29  0
 public class AnnotationAndNameMatchingTransactionAttributeSource extends NameMatchTransactionAttributeSource {
 30  
     
 31  
         private static final long serialVersionUID = 6119879657045541414L;
 32  
         
 33  
         private AnnotationTransactionAttributeSource annotationTransactionAttributeSource;
 34  
     private Integer transactionTimeout;
 35  
 
 36  
     /**
 37  
      * @see org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource#getTransactionAttribute(java.lang.reflect.Method,
 38  
      *      java.lang.Class)
 39  
      */
 40  
     @Override
 41  
     public TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass) {
 42  0
         TransactionAttribute transactionAttribute = annotationTransactionAttributeSource.getTransactionAttribute(method, targetClass);
 43  0
         if (transactionAttribute != null) {
 44  0
             TransactionAttribute overridingTransactionAttribute = super.getTransactionAttribute(method, targetClass);
 45  0
             if (overridingTransactionAttribute != null) {
 46  0
                 transactionAttribute = overridingTransactionAttribute;
 47  
             }
 48  
         }
 49  0
         setTimeout(transactionAttribute);
 50  0
         return transactionAttribute;
 51  
     }
 52  
 
 53  
     /**
 54  
      * Sets the annotationTransactionAttributeSource attribute value.
 55  
      *
 56  
      * @param annotationTransactionAttributeSource The annotationTransactionAttributeSource to set.
 57  
      */
 58  
     public void setAnnotationTransactionAttributeSource(AnnotationTransactionAttributeSource annotationTransactionAttributeSource) {
 59  0
         this.annotationTransactionAttributeSource = annotationTransactionAttributeSource;
 60  0
     }
 61  
 
 62  
     public void setTransactionTimeout(Integer transactionTimeout) {
 63  0
         this.transactionTimeout = transactionTimeout;
 64  0
     }
 65  
 
 66  
     /**
 67  
      * If the TransactionAttribute has a setTimeout() method, then this method will invoke it and pass the configured
 68  
      * transaction timeout.  This is to allow for proper setting of the transaction timeout on a JTA transaction.
 69  
      */
 70  
     protected void setTimeout(TransactionAttribute transactionAttribute) {
 71  
         try {
 72  0
             if (transactionTimeout != null) {
 73  0
                 PropertyUtils.setSimpleProperty(transactionAttribute, "timeout", new Integer(transactionTimeout));
 74  
             }
 75  0
         } catch (Exception e) {
 76  
             // failed to set the timeout
 77  0
         }
 78  0
     }
 79  
 }