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  package com.ibatis.jpetstore.service;
17  
18  import com.ibatis.common.util.PaginatedList;
19  import com.ibatis.dao.client.DaoManager;
20  import com.ibatis.jpetstore.domain.Category;
21  import com.ibatis.jpetstore.domain.Item;
22  import com.ibatis.jpetstore.domain.Product;
23  import com.ibatis.jpetstore.persistence.DaoConfig;
24  import com.ibatis.jpetstore.persistence.iface.CategoryDao;
25  import com.ibatis.jpetstore.persistence.iface.ItemDao;
26  import com.ibatis.jpetstore.persistence.iface.ProductDao;
27  
28  import java.util.List;
29  
30  public class CatalogService {
31  
32    /* Constants */
33  
34    private static final CatalogService instance = new CatalogService();
35  
36    /* Private Fields */
37  
38    private DaoManager daoManager = DaoConfig.getDaomanager();
39  
40    private CategoryDao categoryDao;
41    private ItemDao itemDao;
42    private ProductDao productDao;
43  
44    /* Constructors */
45  
46    private CatalogService() {
47      categoryDao = (CategoryDao) daoManager.getDao(CategoryDao.class);
48      productDao = (ProductDao) daoManager.getDao(ProductDao.class);
49      itemDao = (ItemDao) daoManager.getDao(ItemDao.class);
50    }
51  
52    /* Public Methods */
53  
54    public static CatalogService getInstance() {
55      return instance;
56    }
57  
58    /* CATEGORY */
59  
60    public List getCategoryList() {
61      return categoryDao.getCategoryList();
62    }
63  
64    public Category getCategory(String categoryId) {
65      return categoryDao.getCategory(categoryId);
66    }
67  
68    /* PRODUCT */
69  
70    public Product getProduct(String productId) {
71      return productDao.getProduct(productId);
72    }
73  
74    public PaginatedList getProductListByCategory(String categoryId) {
75      return productDao.getProductListByCategory(categoryId);
76    }
77  
78    public PaginatedList searchProductList(String keywords) {
79      return productDao.searchProductList(keywords);
80    }
81  
82    /* ITEM */
83  
84    public PaginatedList getItemListByProduct(String productId) {
85      return itemDao.getItemListByProduct(productId);
86    }
87  
88    public Item getItem(String itemId) {
89      return itemDao.getItem(itemId);
90    }
91  
92    public boolean isItemInStock(String itemId) {
93      return itemDao.isItemInStock(itemId);
94    }
95  
96  }