1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.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
27
28
29 public class AnnotationAndNameMatchingTransactionAttributeSource extends NameMatchTransactionAttributeSource {
30 private AnnotationTransactionAttributeSource annotationTransactionAttributeSource;
31 private Integer transactionTimeout;
32
33
34
35
36
37 @Override
38 public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
39 TransactionAttribute transactionAttribute = annotationTransactionAttributeSource.getTransactionAttribute(method, targetClass);
40 if (transactionAttribute != null) {
41 TransactionAttribute overridingTransactionAttribute = super.getTransactionAttribute(method, targetClass);
42 if (overridingTransactionAttribute != null) {
43 transactionAttribute = overridingTransactionAttribute;
44 }
45 }
46 setTimeout(transactionAttribute);
47 return transactionAttribute;
48 }
49
50
51
52
53
54
55 public void setAnnotationTransactionAttributeSource(AnnotationTransactionAttributeSource annotationTransactionAttributeSource) {
56 this.annotationTransactionAttributeSource = annotationTransactionAttributeSource;
57 }
58
59 public void setTransactionTimeout(Integer transactionTimeout) {
60 this.transactionTimeout = transactionTimeout;
61 }
62
63
64
65
66
67 protected void setTimeout(TransactionAttribute transactionAttribute) {
68 try {
69 if (transactionTimeout != null) {
70 PropertyUtils.setSimpleProperty(transactionAttribute, "timeout", new Integer(transactionTimeout));
71 }
72 } catch (Exception e) {
73
74 }
75 }
76 }