1 22 package org.jboss.ejb3.test.bmt; 23 24 import javax.annotation.Resource; 25 import javax.ejb.Stateful ; 26 import javax.ejb.TransactionManagement ; 27 import javax.ejb.TransactionManagementType ; 28 import javax.transaction.TransactionManager ; 29 import javax.transaction.UserTransaction ; 30 import javax.transaction.Transaction ; 31 import org.jboss.annotation.JndiInject; 32 33 39 @Stateful 40 @TransactionManagement (TransactionManagementType.BEAN) 41 public class StatefulBean implements StatefulLocal 42 { 43 @Resource UserTransaction ut; 44 @JndiInject(jndiName="java:/TransactionManager") TransactionManager tm; 45 46 public Transaction beginNoEnd() throws Exception 47 { 48 if (tm.getTransaction() != null) throw new TestException("THERE IS AN EXISTING TRANSACTION"); 49 ut.begin(); 50 return tm.getTransaction(); 51 } 52 53 public void endCommit(Transaction old) throws Exception 54 { 55 if (old != tm.getTransaction()) throw new TestException("No matching TX"); 56 ut.commit(); 57 } 58 59 public void endRollback(Transaction old) throws Exception 60 { 61 if (old != tm.getTransaction()) throw new TestException("No matching TX"); 62 ut.rollback(); 63 } 64 65 public void beginCommitEnd() throws Exception 66 { 67 if (tm.getTransaction() != null) throw new TestException("THERE IS AN EXISTING TRANSACTION"); 68 ut.begin(); 69 ut.commit(); 70 } 71 72 public void beginRollbackEnd() throws Exception 73 { 74 if (tm.getTransaction() != null) throw new TestException("THERE IS AN EXISTING TRANSACTION"); 75 ut.begin(); 76 ut.rollback(); 77 } 78 79 } 80 | Popular Tags |