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