01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package jfox.test.ejb3.synchronization;
08:
09: 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: /**
21: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
22: */
23: @Stateful(name="sychronization.ShoppingCartBean")
24: public class ShoppingCartBean implements ShoppingCart, Serializable,
25: SessionSynchronization {
26:
27: private Map<String, Integer> cart = new HashMap<String, Integer>();
28:
29: @Resource
30: SessionContext sessionContext;
31:
32: public void buy(String product, int quantity) {
33: if (cart.containsKey(product)) {
34: int currq = cart.get(product);
35: currq += quantity;
36: cart.put(product, currq);
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,
56: RemoteException {
57: System.out.println("afterCompletion: " + committed);
58: }
59:
60: public void beforeCompletion() throws EJBException, RemoteException {
61: System.out.println("beforeCompletion...");
62: }
63: }
|