1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.pojo.interceptors; |
9 |
| |
10 |
| import org.jboss.aop.joinpoint.Invocation; |
11 |
| import org.jboss.aop.joinpoint.MethodInvocation; |
12 |
| import org.jboss.cache.pojo.PojoCacheException; |
13 |
| |
14 |
| import javax.transaction.RollbackException; |
15 |
| import javax.transaction.SystemException; |
16 |
| import javax.transaction.Transaction; |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| public class PojoTxUndoSynchronizationInterceptor extends AbstractInterceptor |
26 |
| { |
27 |
| |
28 |
| |
29 |
| |
30 |
| private static ThreadLocal synchronizationHandler_ = new ThreadLocal(); |
31 |
| |
32 |
25118
| public Object invoke(Invocation in) throws Throwable
|
33 |
| { |
34 |
25118
| if (!(in instanceof MethodInvocation))
|
35 |
| { |
36 |
0
| throw new IllegalArgumentException("TxSyncrhonizationInterceptor.invoke(): invocation not MethodInvocation");
|
37 |
| } |
38 |
25118
| MethodInvocation invocation = (MethodInvocation) in;
|
39 |
25118
| try
|
40 |
| { |
41 |
25118
| registerTxHandler(invocation);
|
42 |
25118
| return invocation.invokeNext();
|
43 |
| } |
44 |
| finally |
45 |
| { |
46 |
| } |
47 |
| } |
48 |
| |
49 |
25118
| private void registerTxHandler(MethodInvocation invocation) throws PojoCacheException
|
50 |
| { |
51 |
25118
| try
|
52 |
| { |
53 |
| |
54 |
25118
| PojoTxSynchronizationHandler handler = (PojoTxSynchronizationHandler) synchronizationHandler_.get();
|
55 |
25118
| if (handler == null)
|
56 |
| { |
57 |
| |
58 |
3208
| Transaction tx = (Transaction) invocation.getMetaData(PojoTxInterceptor.TAG, PojoTxInterceptor.TX);
|
59 |
3208
| if (tx == null)
|
60 |
| { |
61 |
0
| throw new IllegalStateException("PojoCache.registerTxHanlder(). Can't have null tx handle.");
|
62 |
| } |
63 |
| |
64 |
3208
| handler = new PojoTxSynchronizationHandler();
|
65 |
| |
66 |
3208
| log.debug("Registering PojoTxSynchronizationHandler for rollback if ncessary " + handler);
|
67 |
| |
68 |
3208
| tx.registerSynchronization(handler);
|
69 |
| |
70 |
3208
| synchronizationHandler_.set(handler);
|
71 |
| } |
72 |
| } |
73 |
| catch (RollbackException e) |
74 |
| { |
75 |
0
| throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
|
76 |
| } |
77 |
| catch (SystemException e) |
78 |
| { |
79 |
0
| throw new PojoCacheException("PojoTxUndoSynchronizationInterceptor.registerTxHandler(): Exception: " + e);
|
80 |
| } |
81 |
| } |
82 |
| |
83 |
18019
| public static PojoTxSynchronizationHandler getSynchronizationHandler()
|
84 |
| { |
85 |
18019
| return (PojoTxSynchronizationHandler) synchronizationHandler_.get();
|
86 |
| } |
87 |
| |
88 |
3208
| public static void reset()
|
89 |
| { |
90 |
3208
| synchronizationHandler_.set(null);
|
91 |
| } |
92 |
| } |