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