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