1 22 package org.jboss.ejb3.test.initial; 23 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import javax.ejb.Stateless ; 27 import javax.ejb.TransactionAttribute ; 28 import javax.ejb.TransactionAttributeType ; 29 import javax.transaction.Transaction ; 30 import javax.transaction.TransactionManager ; 31 import org.jboss.annotation.JndiInject; 32 33 39 @Stateless 40 public class TestBean implements TestLocal, TestRemote 41 { 42 private TransactionManager tm; 43 public static Map obj = new HashMap (); 44 45 public Map getObject() 46 { 47 return obj; 48 } 49 50 public Object echo(Object e) 51 { 52 return e; 53 } 54 55 @JndiInject(jndiName = "java:/TransactionManager") 56 public void setTransactionManager(TransactionManager tm) 57 { 58 this.tm = tm; 59 System.out.println("TransactionManager set: " + tm); 60 } 61 62 public String testMe(String echo) 63 { 64 System.out.println("JDK15 testMe worked"); 65 return echo; 66 } 67 68 @TransactionAttribute (TransactionAttributeType.NEVER) 69 public void never() 70 { 71 } 72 73 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 74 public void notSupported() throws Exception 75 { 76 if (tm.getTransaction() != null) throw new Exception ("notsupported() method has tx set"); 77 } 78 79 @TransactionAttribute (TransactionAttributeType.SUPPORTS) 80 public void supports(Transaction tx) throws Exception 81 { 82 Transaction tmTx = tm.getTransaction(); 83 if (tx != tmTx) throw new Exception ("supports didn't work"); 84 } 85 86 @TransactionAttribute (TransactionAttributeType.REQUIRED) 87 public void required() throws Exception 88 { 89 if (tm.getTransaction() == null) throw new Exception ("rquired() method has no tx set"); 90 } 91 92 93 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 94 public void requiresNew(Transaction tx) throws Exception 95 { 96 Transaction tmTx = tm.getTransaction(); 97 if (tx == tmTx || (tx != null && tx.equals(tmTx))) 98 throw new Exception ("transactions shouldn't be equal"); 99 if (tmTx == null) throw new Exception ("tx is null in RequiresNew"); 100 } 101 102 103 @TransactionAttribute (TransactionAttributeType.MANDATORY) 104 public void mandatory() 105 { 106 } 107 } 108 109 110 111 | Popular Tags |