?? cartejb.java
字號:
package apusic.myshop.cart.ejb;import java.util.List;import java.util.Iterator;import java.util.ArrayList;import java.util.Set;import java.util.Collection;import java.util.HashMap;import java.rmi.RemoteException;import javax.ejb.FinderException;import javax.ejb.SessionBean;import javax.ejb.SessionContext;import javax.ejb.EJBException;import javax.ejb.CreateException;import apusic.myshop.util.EJBUtil;import apusic.myshop.control.GeneralFailureException;import apusic.myshop.util.Debug;import apusic.myshop.product.ejb.ProductHome;import apusic.myshop.product.ejb.Product;import apusic.myshop.cart.model.CartModel;import apusic.myshop.cart.model.CartItem;public class CartEJB implements SessionBean { private HashMap cart; public CartEJB() { cart = new HashMap(); } public CartModel getDetails() { ArrayList items = new ArrayList(); try { ProductHome productHome = EJBUtil.getProductHome(); Set keys = null; if (cart != null) keys = cart.keySet(); Iterator it = null; if (keys != null) it = keys.iterator(); while ((it != null) && it.hasNext()) { String itemId = (String) it.next(); int qtyNeeded = ((Integer) cart.get(itemId)).intValue(); try { Product product = productHome.findByProductId(itemId); String cataId = product.getCatalog(); String productName = product.getName(); String style = product.getStyle(); double listPrice = product.getListPrice(); CartItem cartItem = new CartItem( itemId, cataId, productName, style, qtyNeeded, listPrice); items.add(cartItem); } catch (FinderException fe) { throw new GeneralFailureException(fe); } } } catch (RemoteException re) { throw new GeneralFailureException(re); } CartModel model = new CartModel(items); return model; } public void addItem (String itemNo) { cart.put(itemNo, new Integer(1)); } public void addItem (String itemNo,int qty) { cart.put(itemNo, new Integer(qty)); } public void deleteItem (String itemNo) { cart.remove(itemNo); } public void updateItemQty (String itemNo, int newQty) { cart.remove(itemNo); cart.put(itemNo, new Integer(newQty)); } public void empty () { cart.clear(); } public void ejbCreate() { cart = new HashMap(); } public void ejbCreate(HashMap starting) { cart = (HashMap) starting.clone(); } public void setSessionContext(SessionContext sc) {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -