1 22 package org.jboss.ejb3.test.arjuna; 23 24 import javax.ejb.Remote ; 25 import javax.ejb.Stateful ; 26 import javax.ejb.TransactionAttribute ; 27 import javax.ejb.TransactionAttributeType ; 28 import javax.persistence.EntityManager; 29 import javax.persistence.PersistenceContext; 30 import javax.transaction.TransactionManager ; 31 32 import org.jboss.annotation.JndiInject; 33 import org.jboss.annotation.ejb.RemoteBinding; 34 import org.jboss.ejb3.test.arjuna.Entity; 35 import org.jboss.logging.Logger; 36 37 40 @Stateful (name="StatefulTx") 41 @Remote (StatefulTx.class) 42 @RemoteBinding(jndiBinding = "StatefulTx") 43 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 44 public class StatefulTxBean implements StatefulTx 45 { 46 private static final Logger log = Logger.getLogger(StatefulTxBean.class); 47 48 @JndiInject(jndiName="java:/TransactionManager") private TransactionManager tm; 49 50 @PersistenceContext private EntityManager manager; 51 52 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 53 public boolean clear(Entity entity) throws javax.transaction.SystemException 54 { 55 entity = manager.find(Entity.class, entity.getId()); 56 if (entity != null) 57 manager.remove(entity); 58 59 return getReturn(); 60 } 61 62 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 63 public boolean persist(Entity entity) throws javax.transaction.SystemException 64 { 65 manager.persist(entity); 66 67 return getReturn(); 68 } 69 70 @TransactionAttribute (TransactionAttributeType.REQUIRED) 71 public boolean isArjunaTransactedRequired() throws javax.transaction.SystemException 72 { 73 return getReturn(); 74 } 75 76 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 77 public boolean isArjunaTransactedRequiresNew() throws javax.transaction.SystemException 78 { 79 return getReturn(); 80 } 81 82 protected boolean getReturn() throws javax.transaction.SystemException 83 { 84 if (tm.getTransaction() == null) 85 return false; 86 87 if (!tm.getClass().toString().contains("arjuna")) 88 return false; 89 90 if (!tm.getTransaction().getClass().toString().contains("arjuna")) 91 return false; 92 93 return true; 94 } 95 96 } 97 | Popular Tags |