⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productmanagerimp.java

📁 Java/J2EE框架Jdon-Framework系统的源代码
💻 JAVA
字号:
/*
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.jdon.framework.samples.jpetstore.service.bo;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jdon.controller.model.PageIterator;
import com.jdon.controller.pool.Poolable;
import com.jdon.framework.samples.jpetstore.domain.Category;
import com.jdon.framework.samples.jpetstore.domain.Item;
import com.jdon.framework.samples.jpetstore.domain.Product;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.CategoryDao;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.ItemDao;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.OrderDao;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.ProductDao;
import com.jdon.framework.samples.jpetstore.service.ProductManager;
import com.jdon.util.Debug;

/**
 * @author <a href="mailto:banqiao@jdon.com">banq </a>
 *  
 */
public class ProductManagerImp implements ProductManager, Poolable {
    private final static String module = ProductManagerImp.class.getName();

    private CategoryDao categoryDao;

    private ProductDao productDao;

    private OrderDao orderDao;

    private ItemDao itemDao;

    /**
     * @param categoryDao
     * @param productDao
     * @param orderDao
     * @param itemDao
     */
    public ProductManagerImp(CategoryDao categoryDao, ProductDao productDao,
            OrderDao orderDao, ItemDao itemDao) {
        super();
        this.categoryDao = categoryDao;
        this.productDao = productDao;
        this.orderDao = orderDao;
        this.itemDao = itemDao;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getCategoryList()
     */
    public List getCategoryList() {
        try {
            return categoryDao.getCategoryList();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return new ArrayList();
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getCategory(java.lang.String)
     */
    public Category getCategory(String categoryId) {
        Category category = null;
        try {
            category = categoryDao.getCategory(categoryId);
            //other business logic
        } catch (Exception daoe) {
            Debug.logError(" Dao error : " + daoe, module);
        }
        return category;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getProductListByCategory(java.lang.String)
     */
     
  	public PageIterator getProductIDsListByCategory(String categoryId, int start, int count)
  	{
        Debug.logVerbose(" getProductIDsListByCategory", module);  	    
  	    PageIterator pageIterator = null;
  	     try {

  	         List list = productDao.getProductIDsListByCategory(categoryId, start, count);
  	         int allCount = productDao.getProductIDsListByCategoryCount(categoryId);
  	         int currentCount = start + list.size();
  	         pageIterator = new PageIterator(allCount, list.toArray(), start,
  	                 (currentCount < allCount)?true:false);

         } catch (Exception daoe) {
             Debug.logError(" Dao error : " + daoe, module);
         }
        
       return pageIterator;
    }
  	
  	
    public int getProductIDsListByCategoryCount(String categoryId) {
        try {
            return productDao.getProductIDsListByCategoryCount(categoryId);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }
    }

  	
  	
    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#searchProductList(java.lang.String)
     */
    public PageIterator searchProductIDsList(String keywords, int start, int count){
  	    PageIterator pageIterator = null;
 	     try {
 	         List list = productDao.searchProductIDsList(keywords, start, count);
 	         int allCount = productDao.searchProductIDsListCount(keywords);
 	         int currentCount = start + list.size();
 	         pageIterator = new PageIterator(allCount, list.toArray(), start,
 	                 (currentCount < allCount)?true:false);

        } catch (Exception daoe) {
            Debug.logError(" Dao error : " + daoe, module);
        }
       
      return pageIterator;
    }
  	
  	public int searchProductIDsListCount(String keywords){
  	    try {
            return productDao.searchProductIDsListCount(keywords);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }
  	}

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getProduct(java.lang.String)
     */
    public Product getProduct(String productId) {
        Product product = null;
        try {
            product = productDao.getProduct(productId);
            //other business logic
        } catch (Exception daoe) {
            Debug.logError(" Dao error : " + daoe, module);
        }
        return product;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getItemListByProduct(java.lang.String)
     */

  	
    public PageIterator getItemIDsListByProduct(String productId,  int start, int count){
  	    PageIterator pageIterator = null;
  	     try {
  	         List list = itemDao.getItemIDsListByProduct(productId, start, count);
  	         int allCount = itemDao.getItemIDsListByProductCount(productId);
  	         int currentCount = start + list.size();
  	         pageIterator = new PageIterator(allCount, list.toArray(), start,
  	                 (currentCount < allCount)?true:false);

         } catch (Exception daoe) {
             Debug.logError(" Dao error : " + daoe, module);
         }
        
       return pageIterator;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#getItem(java.lang.String)
     */
    public Item getItem(String itemId) {
        Item item = null;
        try {
            item = itemDao.getItem(itemId);
            
            //other business logic
        } catch (Exception daoe) {
            Debug.logError(" Dao error : " + daoe, module);
        }
        return item;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.jdon.framework.samples.jpetstore.service.ProductManager#isItemInStock(java.lang.String)
     */
    public boolean isItemInStock(String itemId) {
        boolean res = false;
        ;
        try {
            res = itemDao.isItemInStock(itemId);
            //other business logic
        } catch (Exception daoe) {
            Debug.logError(" Dao error : " + daoe, module);
        }
        return res;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -