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.Fqn; |
13 |
| import org.jboss.cache.pojo.PojoCacheException; |
14 |
| import org.jboss.cache.pojo.impl.MethodDeclarations; |
15 |
| import org.jboss.cache.pojo.util.MethodCall; |
16 |
| |
17 |
| import java.lang.reflect.Field; |
18 |
| import java.lang.reflect.Method; |
19 |
| import java.util.List; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class PojoTxUndoInterceptor extends AbstractInterceptor |
29 |
| { |
30 |
| |
31 |
| public static final String TAG = "PojoCache"; |
32 |
| |
33 |
18019
| public Object invoke(Invocation in) throws Throwable
|
34 |
| { |
35 |
18019
| if (!(in instanceof MethodInvocation))
|
36 |
| { |
37 |
0
| throw new IllegalArgumentException("TxUndoInterceptor.invoke(): invocation not MethodInvocation");
|
38 |
| } |
39 |
18019
| MethodInvocation invocation = (MethodInvocation) in;
|
40 |
| |
41 |
18019
| PojoTxSynchronizationHandler handler =
|
42 |
| PojoTxUndoSynchronizationInterceptor.getSynchronizationHandler(); |
43 |
| |
44 |
18019
| if (handler == null)
|
45 |
| { |
46 |
2344
| return invocation.invokeNext();
|
47 |
| |
48 |
| |
49 |
| |
50 |
| } |
51 |
| |
52 |
| |
53 |
15675
| String methodName = invocation.getMethod().getName();
|
54 |
| |
55 |
15675
| if (methodName.equals(MethodDeclarations.attachInterceptor.getName()))
|
56 |
| { |
57 |
2284
| Method method = MethodDeclarations.undoAttachInterceptor;
|
58 |
2284
| MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
|
59 |
2284
| handler.addToList(mc);
|
60 |
| } |
61 |
13391
| else if (methodName.equals(MethodDeclarations.detachInterceptor.getName()))
|
62 |
| { |
63 |
1885
| Method method = MethodDeclarations.undoDetachInterceptor;
|
64 |
1885
| MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
|
65 |
1885
| handler.addToList(mc);
|
66 |
| } |
67 |
11506
| else if (methodName.equals(MethodDeclarations.inMemorySubstitution.getName()))
|
68 |
| { |
69 |
7334
| Method method = MethodDeclarations.undoInMemorySubstitution;
|
70 |
7334
| Object obj = invocation.getArguments()[0];
|
71 |
7334
| Field field = (Field) invocation.getArguments()[1];
|
72 |
7334
| Object oldValue = field.get(obj);
|
73 |
7334
| Object[] args = new Object[]{obj, field, oldValue};
|
74 |
7334
| MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
|
75 |
7334
| handler.addToList(mc);
|
76 |
| } |
77 |
4172
| else if (methodName.equals(MethodDeclarations.incrementReferenceCount.getName()))
|
78 |
| { |
79 |
4134
| Method method = MethodDeclarations.undoIncrementReferenceCount;
|
80 |
4134
| Fqn fqn = (Fqn) invocation.getArguments()[0];
|
81 |
4134
| int count = (Integer) invocation.getArguments()[1];
|
82 |
4134
| List referenceList = (List) invocation.getArguments()[2];
|
83 |
4134
| Object[] args = new Object[]{fqn, count, referenceList};
|
84 |
4134
| MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
|
85 |
4134
| handler.addToList(mc);
|
86 |
| } |
87 |
38
| else if (methodName.equals(MethodDeclarations.decrementReferenceCount.getName()))
|
88 |
| { |
89 |
38
| Method method = MethodDeclarations.undoDecrementReferenceCount;
|
90 |
38
| Fqn fqn = (Fqn) invocation.getArguments()[0];
|
91 |
38
| int count = (Integer) invocation.getArguments()[1];
|
92 |
38
| List referenceList = (List) invocation.getArguments()[2];
|
93 |
38
| Object[] args = new Object[]{fqn, count, referenceList};
|
94 |
38
| MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
|
95 |
38
| handler.addToList(mc);
|
96 |
| } |
97 |
| else |
98 |
| { |
99 |
0
| throw new PojoCacheException("PojoTxUndoInterceptor: invalid invocation name: " + methodName);
|
100 |
| } |
101 |
| |
102 |
15675
| return invocation.invokeNext();
|
103 |
| } |
104 |
| |
105 |
| } |