01: /**
02: * User: Clinton Begin Date: Jul 13, 2003 Time: 7:21:08 PM
03: */package com.ibatis.jpetstore.persistence.sqlmapdao;
04:
05: import java.util.HashMap;
06: import java.util.Map;
07:
08: import com.ibatis.common.util.PaginatedList;
09: import com.ibatis.dao.client.DaoManager;
10: import com.ibatis.jpetstore.domain.Item;
11: import com.ibatis.jpetstore.domain.LineItem;
12: import com.ibatis.jpetstore.domain.Order;
13: import com.ibatis.jpetstore.persistence.iface.ItemDao;
14:
15: public class ItemSqlMapDao extends BaseSqlMapDao implements ItemDao {
16:
17: public ItemSqlMapDao(DaoManager daoManager) {
18: super (daoManager);
19: }
20:
21: public void updateQuantity(Order order) {
22: for (int i = 0; i < order.getLineItems().size(); i++) {
23: LineItem lineItem = (LineItem) order.getLineItems().get(i);
24: String itemId = lineItem.getItemId();
25: Integer increment = new Integer(lineItem.getQuantity());
26: Map param = new HashMap(2);
27: param.put("itemId", itemId);
28: param.put("increment", increment);
29: update("updateInventoryQuantity", param);
30: }
31: }
32:
33: public boolean isItemInStock(String itemId) {
34: Integer i = (Integer) queryForObject("getInventoryQuantity",
35: itemId);
36: return (i != null && i.intValue() > 0);
37: }
38:
39: public PaginatedList getItemListByProduct(String productId) {
40: return queryForPaginatedList("getItemListByProduct", productId,
41: PAGE_SIZE);
42: }
43:
44: public Item getItem(String itemId) {
45: Integer i = (Integer) queryForObject("getInventoryQuantity",
46: itemId);
47: Item item = (Item) queryForObject("getItem", itemId);
48: item.setQuantity(i.intValue());
49: return item;
50: }
51:
52: }
|