1 7 package jfox.test.ejb3.synchronization; 8 9 import java.io.Serializable ; 10 import java.util.HashMap ; 11 import java.util.Map ; 12 import java.rmi.RemoteException ; 13 import javax.ejb.Remove ; 14 import javax.ejb.Stateful ; 15 import javax.ejb.SessionContext ; 16 import javax.ejb.SessionSynchronization ; 17 import javax.ejb.EJBException ; 18 import javax.annotation.Resource; 19 20 23 @Stateful (name = "sychronization.ShoppingCartBean") 24 public class ShoppingCartBean implements ShoppingCart, Serializable , SessionSynchronization { 25 26 private Map <String , Integer > cart = new HashMap <String , Integer >(); 27 28 @Resource 29 SessionContext sessionContext; 30 31 public void buy(String product, int quantity) { 32 if (cart.containsKey(product)) { 33 int currq = cart.get(product); 34 currq += quantity; 35 cart.put(product, currq); 36 } 37 else { 38 cart.put(product, quantity); 39 } 40 } 41 42 public Map <String , Integer > getCartContents() { 43 return cart; 44 } 45 46 @Remove 47 public void checkout() { 48 System.out.println("To be implemented"); 49 } 50 51 public void afterBegin() throws EJBException , RemoteException { 52 System.out.println("afterBegin..."); 53 } 54 55 public void afterCompletion(boolean committed) throws EJBException , RemoteException { 56 System.out.println("afterCompletion: " + committed); 57 } 58 59 public void beforeCompletion() throws EJBException , RemoteException { 60 System.out.println("beforeCompletion..."); 61 } 62 } 63 64 | Popular Tags |