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