View Javadoc

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