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