View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }