1 22 package org.jboss.aspects.tx; 23 24 import javax.transaction.Transaction ; 25 import javax.transaction.TransactionManager ; 26 import org.jboss.aop.advice.Interceptor; 27 import org.jboss.aop.joinpoint.Invocation; 28 import org.jboss.tm.TransactionManagerLocator; 29 import org.jboss.tm.TransactionPropagationContextUtil; 30 31 37 public class TxPropagationInterceptor implements Interceptor 38 { 39 private TransactionManager tm; 40 41 public TxPropagationInterceptor(TransactionManager tm) 42 { 43 this.tm = tm; 44 } 45 46 public TxPropagationInterceptor() 47 { 48 tm = TransactionManagerLocator.getInstance().locate(); 49 } 50 51 public String getName() 52 { 53 return "TxPropagationInterceptor"; 54 } 55 56 public Object invoke(Invocation invocation) throws Throwable 57 { 58 Object tpc = invocation.getMetaData(ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT, ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT); 59 if (tpc != null) 60 { 61 Transaction tx = tm.getTransaction(); 62 if (tx != null) throw new RuntimeException ("cannot import a transaction context when a transaction is already associated with the thread"); 63 Transaction importedTx = TransactionPropagationContextUtil.getTPCImporter().importTransactionPropagationContext(tpc); 64 tm.resume(importedTx); 65 try 66 { 67 return invocation.invokeNext(); 68 } 69 finally 70 { 71 tm.suspend(); 72 } 73 } 74 else 75 { 76 return invocation.invokeNext(); 77 } 78 } 79 } 80 | Popular Tags |