KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > jpetstore > persistence > sqlmapdao > ItemSqlMapDao


1 /**
2  * User: Clinton Begin
3  * Date: Jul 13, 2003
4  * Time: 7:21:08 PM
5  */

6 package com.ibatis.jpetstore.persistence.sqlmapdao;
7
8 import com.ibatis.common.util.PaginatedList;
9 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 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18 public class ItemSqlMapDao extends BaseSqlMapDao implements ItemDao {
19
20   public ItemSqlMapDao(DaoManager daoManager) {
21     super(daoManager);
22   }
23
24   public void updateQuantity(Order order) {
25     for (int i = 0; i < order.getLineItems().size(); i++) {
26       LineItem lineItem = (LineItem) order.getLineItems().get(i);
27       String JavaDoc itemId = lineItem.getItemId();
28       Integer JavaDoc increment = new Integer JavaDoc(lineItem.getQuantity());
29       Map JavaDoc param = new HashMap JavaDoc(2);
30       param.put("itemId", itemId);
31       param.put("increment", increment);
32       update("updateInventoryQuantity", param);
33     }
34   }
35
36   public boolean isItemInStock(String JavaDoc itemId) {
37     Integer JavaDoc i = (Integer JavaDoc) queryForObject("getInventoryQuantity", itemId);
38     return (i != null && i.intValue() > 0);
39   }
40
41   public PaginatedList getItemListByProduct(String JavaDoc productId) {
42     return queryForPaginatedList("getItemListByProduct", productId, PAGE_SIZE);
43   }
44
45   public Item getItem(String JavaDoc itemId) {
46     Integer JavaDoc i = (Integer JavaDoc) queryForObject("getInventoryQuantity", itemId);
47     Item item = (Item) queryForObject("getItem", itemId);
48     item.setQuantity(i.intValue());
49     return item;
50   }
51
52 }
53
Popular Tags