1 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 ; 16 import java.util.Map ; 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 itemId = lineItem.getItemId(); 28 Integer increment = new Integer (lineItem.getQuantity()); 29 Map param = new HashMap (2); 30 param.put("itemId", itemId); 31 param.put("increment", increment); 32 update("updateInventoryQuantity", param); 33 } 34 } 35 36 public boolean isItemInStock(String itemId) { 37 Integer i = (Integer ) queryForObject("getInventoryQuantity", itemId); 38 return (i != null && i.intValue() > 0); 39 } 40 41 public PaginatedList getItemListByProduct(String productId) { 42 return queryForPaginatedList("getItemListByProduct", productId, PAGE_SIZE); 43 } 44 45 public Item getItem(String itemId) { 46 Integer i = (Integer ) queryForObject("getInventoryQuantity", itemId); 47 Item item = (Item) queryForObject("getItem", itemId); 48 item.setQuantity(i.intValue()); 49 return item; 50 } 51 52 } 53 | Popular Tags |