1 22 package org.jboss.ejb3.test.standalone.flushmodenever; 23 24 import javax.ejb.Remote ; 25 import javax.ejb.Remove ; 26 import javax.ejb.Stateful ; 27 import javax.ejb.TransactionAttribute ; 28 import javax.ejb.TransactionAttributeType ; 29 import javax.persistence.EntityManager; 30 import javax.persistence.PersistenceContext; 31 import javax.persistence.PersistenceContextType; 32 import javax.transaction.TransactionManager ; 33 import javax.transaction.Transaction ; 34 import javax.transaction.SystemException ; 35 import org.jboss.annotation.JndiInject; 36 import org.jboss.ejb3.entity.ExtendedEntityManager; 37 38 44 @Stateful 45 @Remote (Stateful1.class) 46 public class Stateful1Bean implements Stateful1, java.io.Serializable 47 { 48 @PersistenceContext(unitName="manager1", type =PersistenceContextType.EXTENDED) EntityManager manager1; 49 @PersistenceContext(unitName = "../flushmodenever-session2.jar#manager2", type =PersistenceContextType.EXTENDED) EntityManager manager2; 50 51 Entity1 one; 52 Entity2 two; 53 54 @JndiInject(jndiName="java:/TransactionManager") TransactionManager tm; 55 56 public int create1() 57 { 58 one = new Entity1(); 59 one.setString("oneManager"); 60 if (!(manager1 instanceof ExtendedEntityManager)) throw new RuntimeException ("assert failed"); 61 manager1.persist(one); 62 return one.getId(); 63 } 64 65 public int create2() 66 { 67 two = new Entity2(); 68 two.setString("twoManager"); 69 manager2.persist(two); 70 return two.getId(); 71 } 72 73 public void update1() 74 { 75 if (!manager1.contains(one)) throw new RuntimeException ("assert failed"); 76 one.setString("changed"); 77 } 78 79 public void update2() 80 { 81 if (!manager2.contains(two)) throw new RuntimeException ("assert failed"); 82 two.setString("changed"); 83 } 84 85 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 86 public void never() 87 { 88 one.setString("never"); 89 two.setString("never"); 90 } 91 92 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 93 public void never2(Entity1 uno, Entity2 dos) 94 { 95 Transaction tx = null; 96 try 97 { 98 tx = tm.getTransaction(); 99 } 100 catch (SystemException e) 101 { 102 throw new RuntimeException (e); 103 } 104 if (tx != null) throw new RuntimeException ("TRANSACTION IS NOT NULL!"); 105 if (manager1.merge(uno) != one) throw new RuntimeException ("NOT EQUAL!!"); 106 if (!uno.getString().equals("never2")) throw new RuntimeException ("NOT_EQUAL"); 107 if (manager2.merge(dos) != two) throw new RuntimeException ("NOT EQUAL!"); 108 if (!dos.getString().equals("never2")) throw new RuntimeException ("NOT_EQUAL"); 109 } 110 111 @Remove 112 public void checkout() 113 { 114 121 } 122 123 124 } 125 | Popular Tags |