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 | 0 | 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 | 0 | TransactionAttribute transactionAttribute = annotationTransactionAttributeSource.getTransactionAttribute(method, targetClass); |
40 | 0 | if (transactionAttribute != null) { |
41 | 0 | TransactionAttribute overridingTransactionAttribute = super.getTransactionAttribute(method, targetClass); |
42 | 0 | if (overridingTransactionAttribute != null) { |
43 | 0 | transactionAttribute = overridingTransactionAttribute; |
44 | |
} |
45 | |
} |
46 | 0 | setTimeout(transactionAttribute); |
47 | 0 | return transactionAttribute; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void setAnnotationTransactionAttributeSource(AnnotationTransactionAttributeSource annotationTransactionAttributeSource) { |
56 | 0 | this.annotationTransactionAttributeSource = annotationTransactionAttributeSource; |
57 | 0 | } |
58 | |
|
59 | |
public void setTransactionTimeout(Integer transactionTimeout) { |
60 | 0 | this.transactionTimeout = transactionTimeout; |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
protected void setTimeout(TransactionAttribute transactionAttribute) { |
68 | |
try { |
69 | 0 | if (transactionTimeout != null) { |
70 | 0 | PropertyUtils.setSimpleProperty(transactionAttribute, "timeout", new Integer(transactionTimeout)); |
71 | |
} |
72 | 0 | } catch (Exception e) { |
73 | |
|
74 | 0 | } |
75 | 0 | } |
76 | |
} |