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