1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
29 | |
|
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 | |
|
39 | |
|
40 | |
public void setLevel(String lvl) { |
41 | 0 | level = Level.toLevel(lvl); |
42 | 0 | } |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public void setJtaTransactionManager(JtaTransactionManager manager) { |
48 | 0 | this.txManager = manager; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
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 | |
|
68 | |
|
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 | |
} |