1 22 package org.jboss.tm; 23 24 import javax.transaction.InvalidTransactionException ; 25 import javax.transaction.SystemException ; 26 import javax.transaction.Transaction ; 27 import javax.transaction.TransactionManager ; 28 29 import org.jboss.util.NestedRuntimeException; 30 31 37 public class TransactionDemarcationSupport 38 { 39 private static final TransactionManagerLocator locator = TransactionManagerLocator.getInstance(); 40 41 46 public static Transaction suspendAnyTransaction() 47 { 48 TransactionManager tm = locator.locate(); 49 try 50 { 51 return tm.suspend(); 52 } 53 catch (SystemException e) 54 { 55 throw new NestedRuntimeException("Unable to suspend transaction", e); 56 } 57 } 58 59 64 public static void resumeAnyTransaction(Transaction tx) 65 { 66 if (tx == null) 68 return; 69 70 TransactionManager tm = locator.locate(); 71 try 72 { 73 tm.resume(tx); 74 } 75 catch (InvalidTransactionException e) 76 { 77 throw new NestedRuntimeException("Unable to resume an invalid transaction", e); 78 } 79 catch (SystemException e) 80 { 81 throw new NestedRuntimeException("Unable to suspend transaction", e); 82 } 83 } 84 } 85 | Popular Tags |