1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.interceptors; |
8 |
| |
9 |
| import org.jboss.cache.CacheException; |
10 |
| import org.jboss.cache.CacheSPI; |
11 |
| import org.jboss.cache.Fqn; |
12 |
| import org.jboss.cache.InvocationContext; |
13 |
| import org.jboss.cache.NodeSPI; |
14 |
| import org.jboss.cache.optimistic.TransactionWorkspace; |
15 |
| import org.jboss.cache.transaction.GlobalTransaction; |
16 |
| import org.jboss.cache.transaction.OptimisticTransactionEntry; |
17 |
| import org.jboss.cache.transaction.TransactionTable; |
18 |
| |
19 |
| import javax.transaction.Transaction; |
20 |
| import javax.transaction.TransactionManager; |
21 |
| import java.util.List; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class OptimisticInterceptor extends Interceptor |
29 |
| { |
30 |
| protected TransactionManager txManager = null; |
31 |
| protected TransactionTable txTable = null; |
32 |
| protected boolean trace; |
33 |
| |
34 |
3505
| public void setCache(CacheSPI cache)
|
35 |
| { |
36 |
3505
| super.setCache(cache);
|
37 |
3505
| txManager = cache.getTransactionManager();
|
38 |
3505
| txTable = cache.getTransactionTable();
|
39 |
3505
| trace = log != null && log.isTraceEnabled();
|
40 |
| } |
41 |
| |
42 |
2110165
| protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws CacheException
|
43 |
| { |
44 |
2110165
| OptimisticTransactionEntry transactionEntry = (OptimisticTransactionEntry) txTable.get(gtx);
|
45 |
| |
46 |
2110165
| if (transactionEntry == null)
|
47 |
| { |
48 |
0
| throw new CacheException("Unable to map global transaction " + gtx + " to transaction entry when trying to retrieve transaction workspace.");
|
49 |
| } |
50 |
| |
51 |
| |
52 |
2110165
| return transactionEntry.getTransactionWorkSpace();
|
53 |
| } |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
38
| protected void greedyGetFqns(List<Fqn> list, NodeSPI<?, ?> n, Fqn newBase)
|
62 |
| { |
63 |
38
| list.add(n.getFqn());
|
64 |
38
| Fqn newFqn = new Fqn(newBase, n.getFqn().getLastElement());
|
65 |
38
| list.add(newFqn);
|
66 |
| |
67 |
38
| for (NodeSPI child : n.getChildrenDirect())
|
68 |
| { |
69 |
10
| greedyGetFqns(list, child, newFqn);
|
70 |
| } |
71 |
| } |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
3162599
| protected GlobalTransaction getGlobalTransaction(InvocationContext ctx) throws CacheException
|
79 |
| { |
80 |
3162599
| Transaction tx = ctx.getTransaction();
|
81 |
3
| if (tx == null) throw new CacheException("Transaction associated with the current invocation is null!");
|
82 |
3162596
| GlobalTransaction gtx = ctx.getGlobalTransaction();
|
83 |
0
| if (gtx == null) throw new CacheException("GlobalTransaction associated with the current invocation is null!");
|
84 |
3162596
| return gtx;
|
85 |
| } |
86 |
| |
87 |
| |
88 |
| } |