1 22 package org.jboss.ejb3.test.longlived; 23 24 import javax.ejb.EJB ; 25 import javax.ejb.Remote ; 26 import javax.ejb.Remove ; 27 import javax.ejb.Stateful ; 28 import javax.ejb.TransactionAttribute ; 29 import javax.ejb.TransactionAttributeType ; 30 import javax.persistence.PersistenceContext; 31 import javax.persistence.PersistenceContextType; 32 import org.hibernate.Session; 33 import org.jboss.annotation.ejb.RemoteBinding; 34 35 40 @Stateful 41 @Remote (ShoppingCart.class) 42 @RemoteBinding(jndiBinding = "HibernateShoppingCart") 43 public class HibernateShoppingCartBean implements ShoppingCart 44 { 45 @PersistenceContext(type=PersistenceContextType.EXTENDED) Session em; 46 47 @EJB StatelessLocal stateless; 48 49 @EJB private Contained contained; 50 51 private Customer customer; 52 53 public long createCustomer() 54 { 55 customer = new Customer(); 56 customer.setName("William"); 57 em.save(customer); 58 System.out.println("********* created *****"); 59 return customer.getId(); 60 } 61 62 public boolean isContainedActivated() 63 { 64 return false; 65 } 66 67 public void update() 68 { 69 System.out.println("********* update() *****"); 70 customer.setName("Bill"); 71 } 72 public void update2() 73 { 74 customer.setName("Billy"); 75 } 76 77 public void update3() 78 { 79 stateless.update(customer); 80 } 81 82 public Customer find(long id) 83 { 84 return (Customer)em.get(Customer.class, new Long (id)); 85 } 86 87 public void findAndUpdateStateless() 88 { 89 stateless.findAndUpdate(customer.getId()); 90 if (!customer.getName().equals("stateless modified")) throw new RuntimeException ("stateless didn't get propagated pc"); 91 } 92 93 @TransactionAttribute (TransactionAttributeType.NOT_SUPPORTED) 94 public void never() 95 { 96 customer.setName("Bob"); 97 } 98 99 public void updateContained() 100 { 101 contained.updateCustomer(); 102 } 103 104 public void setContainedCustomer() 105 { 106 contained.setCustomer(customer.getId()); 107 } 108 109 public void checkContainedCustomer() 110 { 111 if (contained.getCustomer() != customer) throw new RuntimeException ("not same customer"); 112 } 113 114 115 116 117 @Remove 118 public void checkout() {} 119 } 120 | Popular Tags |