1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.pojo.impl; |
9 |
| |
10 |
| import java.lang.reflect.Field; |
11 |
| import java.util.List; |
12 |
| |
13 |
| import org.jboss.aop.Advised; |
14 |
| import org.jboss.aop.Domain; |
15 |
| import org.jboss.aop.InstanceAdvisor; |
16 |
| import org.jboss.aop.advice.Interceptor; |
17 |
| import org.jboss.cache.Fqn; |
18 |
| import org.jboss.cache.pojo.PojoCacheException; |
19 |
| import org.jboss.cache.pojo.annotation.TxUndo; |
20 |
| import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor; |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class PojoUtil |
29 |
| { |
30 |
| private static final String BindingName = "ReentrancyStopperInterceptor."; |
31 |
| |
32 |
2454
| @TxUndo
|
33 |
| public void attachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor) |
34 |
| { |
35 |
2454
| _attachInterceptor(pojo, advisor, interceptor);
|
36 |
| } |
37 |
| |
38 |
1885
| @TxUndo
|
39 |
| public void detachInterceptor(InstanceAdvisor advisor, Interceptor interceptor) |
40 |
| { |
41 |
1885
| _detachInterceptor(advisor, interceptor);
|
42 |
| } |
43 |
| |
44 |
31
| public void undoAttachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor)
|
45 |
| { |
46 |
31
| _detachInterceptor(advisor, interceptor);
|
47 |
| } |
48 |
| |
49 |
15
| public void undoDetachInterceptor(InstanceAdvisor advisor, Interceptor interceptor)
|
50 |
| { |
51 |
15
| Object pojo = ((CacheFieldInterceptor) interceptor).getAopInstance().get();
|
52 |
15
| if (pojo == null)
|
53 |
| { |
54 |
0
| throw new PojoCacheException("PojoUtil.detachInterceptor(): null pojo");
|
55 |
| } |
56 |
| |
57 |
15
| _attachInterceptor(pojo, advisor, interceptor);
|
58 |
| } |
59 |
| |
60 |
9508
| @TxUndo
|
61 |
| public void inMemorySubstitution(Object obj, Field field, Object newValue) |
62 |
| { |
63 |
9508
| _inMemorySubstitution(obj, field, newValue);
|
64 |
| } |
65 |
| |
66 |
53
| public void undoInMemorySubstitution(Object obj, Field field, Object oldValue)
|
67 |
| { |
68 |
53
| _inMemorySubstitution(obj, field, oldValue);
|
69 |
| } |
70 |
| |
71 |
2469
| private void _attachInterceptor(Object pojo, InstanceAdvisor advisor, Interceptor interceptor)
|
72 |
| { |
73 |
2469
| advisor.appendInterceptor(interceptor);
|
74 |
| } |
75 |
| |
76 |
0
| private Domain getInstanceDomain(Object obj)
|
77 |
| { |
78 |
0
| Advised advised = ((Advised) obj);
|
79 |
0
| InstanceAdvisor advisor = advised._getInstanceAdvisor();
|
80 |
0
| return advisor.getDomain();
|
81 |
| } |
82 |
| |
83 |
9561
| private void _inMemorySubstitution(Object obj, Field field, Object newValue)
|
84 |
| { |
85 |
9561
| try
|
86 |
| { |
87 |
9561
| field.set(obj, newValue);
|
88 |
| } |
89 |
| catch (IllegalAccessException e) |
90 |
| { |
91 |
0
| throw new PojoCacheException(
|
92 |
| "PojoUtil.inMemorySubstitution(): Can't swap out the class of field \" " + |
93 |
| "+field.getLastElementAsString()," + e); |
94 |
| } |
95 |
| } |
96 |
| |
97 |
1916
| private void _detachInterceptor(InstanceAdvisor advisor, Interceptor interceptor)
|
98 |
| { |
99 |
1916
| advisor.removeInterceptor(interceptor.getName());
|
100 |
| |
101 |
1916
| Object pojo = ((CacheFieldInterceptor) interceptor).getAopInstance().get();
|
102 |
| |
103 |
1916
| if (pojo == null)
|
104 |
| { |
105 |
0
| throw new PojoCacheException("PojoUtil.detachInterceptor(): null pojo");
|
106 |
| } |
107 |
| } |
108 |
| |
109 |
4134
| @TxUndo
|
110 |
| public int incrementReferenceCount(Fqn sourceFqn, int count, List refList) |
111 |
| { |
112 |
4134
| return _incrementReferenceCount(sourceFqn, count, refList);
|
113 |
| } |
114 |
| |
115 |
53
| public int undoIncrementReferenceCount(Fqn sourceFqn, int count, List refList)
|
116 |
| { |
117 |
53
| return _decrementReferenceCount(sourceFqn, count, refList);
|
118 |
| } |
119 |
| |
120 |
4140
| private int _incrementReferenceCount(Fqn sourceFqn, int count, List refList)
|
121 |
| { |
122 |
4140
| refList.add(sourceFqn);
|
123 |
4140
| return count + 1;
|
124 |
| } |
125 |
| |
126 |
38
| @TxUndo
|
127 |
| public int decrementReferenceCount(Fqn sourceFqn, int count, List refList) |
128 |
| { |
129 |
38
| return _decrementReferenceCount(sourceFqn, count, refList);
|
130 |
| } |
131 |
| |
132 |
6
| public int undoDecrementReferenceCount(Fqn sourceFqn, int count, List refList)
|
133 |
| { |
134 |
6
| return _incrementReferenceCount(sourceFqn, count, refList);
|
135 |
| } |
136 |
| |
137 |
91
| private int _decrementReferenceCount(Fqn sourceFqn, int count, List refList)
|
138 |
| { |
139 |
91
| refList.remove(sourceFqn);
|
140 |
91
| return count - 1;
|
141 |
| } |
142 |
| } |