1 22 package org.jboss.ejb3.test.factory; 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 33 39 @Stateful 40 @Remote (Stateful1.class) 41 public class Stateful1Bean implements Stateful1, java.io.Serializable 42 { 43 @PersistenceContext(unitName="manager1", type =PersistenceContextType.EXTENDED) EntityManager manager1; 44 @PersistenceContext(unitName = "../session2.jar#manager2", type =PersistenceContextType.EXTENDED) EntityManager manager2; 45 46 Entity1 one; 47 Entity2 two; 48 49 public int create1() 50 { 51 one = new Entity1(); 52 one.setString("oneManager"); 53 manager1.persist(one); 54 return one.getId(); 55 } 56 57 public int create2() 58 { 59 two = new Entity2(); 60 two.setString("twoManager"); 61 manager2.persist(two); 62 return two.getId(); 63 } 64 65 public void update1() 66 { 67 one.setString("changed"); 68 } 69 70 public void update2() 71 { 72 two.setString("changed"); 73 } 74 75 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 76 public void never() 77 { 78 one.setString("never"); 79 two.setString("never"); 80 } 81 82 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 83 public void never2(Entity1 uno, Entity2 dos) 84 { 85 if (manager1.merge(uno) != one) throw new RuntimeException ("NOT EQUAL!!"); 86 if (!uno.getString().equals("never2")) throw new RuntimeException ("NOT_EQUAL"); 87 if (manager2.merge(dos) != two) throw new RuntimeException ("NOT EQUAL!"); 88 if (!dos.getString().equals("never2")) throw new RuntimeException ("NOT_EQUAL"); 89 } 90 91 @Remove 92 public void checkout() 93 { 94 101 } 102 103 104 } 105 | Popular Tags |