1 |
| package org.jboss.cache.interceptors; |
2 |
| |
3 |
| import org.jboss.cache.CacheSPI; |
4 |
| import org.jboss.cache.InvocationContext; |
5 |
| import org.jboss.cache.config.Option; |
6 |
| import org.jboss.cache.transaction.GlobalTransaction; |
7 |
| import org.jboss.cache.transaction.TransactionEntry; |
8 |
| import org.jboss.cache.transaction.TransactionTable; |
9 |
| |
10 |
| import javax.transaction.Status; |
11 |
| import javax.transaction.SystemException; |
12 |
| import javax.transaction.Transaction; |
13 |
| import javax.transaction.TransactionManager; |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public abstract class BaseTransactionalContextInterceptor extends Interceptor |
21 |
| { |
22 |
| protected TransactionTable txTable; |
23 |
| protected TransactionManager txManager; |
24 |
| |
25 |
17080
| public void setCache(CacheSPI cache)
|
26 |
| { |
27 |
17080
| super.setCache(cache);
|
28 |
17080
| txManager = cache.getTransactionManager();
|
29 |
17080
| txTable = cache.getTransactionTable();
|
30 |
| } |
31 |
| |
32 |
1401750
| protected void copyInvocationScopeOptionsToTxScope(InvocationContext ctx)
|
33 |
| { |
34 |
| |
35 |
1401756
| TransactionEntry entry = txTable.get(ctx.getGlobalTransaction());
|
36 |
1401756
| if (entry != null)
|
37 |
| { |
38 |
1401756
| Option txScopeOption = new Option();
|
39 |
1401756
| txScopeOption.setCacheModeLocal(ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isCacheModeLocal());
|
40 |
1401756
| entry.setOption(txScopeOption);
|
41 |
| } |
42 |
| } |
43 |
| |
44 |
5917247
| protected void setTransactionalContext(Transaction tx, GlobalTransaction gtx, InvocationContext ctx)
|
45 |
| { |
46 |
5917246
| log.trace("Setting up transactional context.");
|
47 |
0
| if (log.isTraceEnabled()) log.trace("Setting tx as " + tx + " and gtx as " + gtx);
|
48 |
5917247
| ctx.setTransaction(tx);
|
49 |
5917247
| ctx.setGlobalTransaction(gtx);
|
50 |
| } |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
0
| protected boolean isRollingBack(Transaction tx)
|
56 |
| { |
57 |
0
| if (tx == null) return false;
|
58 |
0
| int status = -1;
|
59 |
0
| try
|
60 |
| { |
61 |
0
| status = tx.getStatus();
|
62 |
0
| return status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK;
|
63 |
| } |
64 |
| catch (SystemException e) |
65 |
| { |
66 |
0
| log.error("failed getting transaction status", e);
|
67 |
0
| return false;
|
68 |
| } |
69 |
| } |
70 |
| } |