/*
* Copyright 2006 - 2012 Hannes Holtzhausen
*
* 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.
*/
/*
* $Id: ProductServiceImpl.java,v 1.3 2007/11/01 22:53:15 hannes Exp $
*
* Description:
*
*/
package app.services;
import java.util.*;
import app.beans.*;
import toolbox.dao.*;
import toolbox.dao.orm.*;
import toolbox.services.*;
import toolbox.services.dao.*;
/**
* Default implementation of the ProductService interface.
*
* This implementation demonstrates the following Toolbox Framework features:
*
* - Complete abstraction of JDBC interfaces via the toolbox.dao and
* and toolbox.services.dao packages.
*
* - Basic Java Beans persistence.
* - Basic Object Relational Mapping queries using the toolbox.dao.orm
* package.
*
* - Access to external configuration properties.
* - Service dependency injection.
*
*
* @author Hannes Holtzhausen
*/
public class ProductServiceImpl extends DaoService implements ProductService
{
/**
* Default constructor.
*/
public ProductServiceImpl()
{
}
/**
* Add the product information contained in the given Product.
*
* @param product Product containing product information.
*
* @throws ProductException if the information cannot be committed.
*/
public void addProduct(Product product) throws ProductException
{
try
{
m_ormService.setReferences("product",product);
logInfo("Adding product: "+product.toString());
insertDaoBean("product",product);
}
catch (ServiceException se)
{
logSevere("addProduct exception",se);
throw new ProductException(getProperty("messages.commit.product_error"));
}
catch (DaoException de)
{
logSevere("addProduct ref exception",de);
throw new ProductException(getProperty("messages.commit.product_error"));
}
}
/**
* Add the product type information contained in the given ProductType.
*
* @param type ProductType containing type information.
*
* @throws ProductException if the information cannot be committed.
*/
public void addProductType(ProductType type) throws ProductException
{
try
{
insertDaoBean("product_type",type);
}
catch (ServiceException se)
{
logSevere("addProductType exception",se);
throw new ProductException(getProperty("messages.commit.type_error"));
}
}
/**
* Add the vendor information contained in the given Vendor.
*
* @param vendor Vendor containing information.
*
* @throws ProductException if the information cannot be committed.
*/
public void addVendor(Vendor vendor) throws ProductException
{
try
{
insertDaoBean("vendor",vendor);
}
catch (ServiceException se)
{
logSevere("addVendor exception",se);
throw new ProductException(getProperty("messages.commit.vendor_error"));
}
}
/**
* Update the product information contained in the given Product.
*
* @param product Product containing product information.
*
* @throws ProductException if the information cannot be committed.
*/
public void updateProduct(Product product) throws ProductException
{
try
{
updateDaoBean("product",product);
}
catch (ServiceException se)
{
logSevere("updateProduct exception",se);
throw new ProductException(getProperty("messages.commit.product_error"));
}
}
/**
* Update the product type information contained in the given ProductType.
*
* @param type ProductType containing type information.
*
* @throws ProductException if the information cannot be committed.
*/
public void updateProductType(ProductType type) throws ProductException
{
try
{
updateDaoBean("product_type",type);
}
catch (ServiceException se)
{
logSevere("updateProductType exception",se);
throw new ProductException(getProperty("messages.commit.type_error"));
}
}
/**
* Update the vendor information contained in the given Vendor.
*
* @param vendor Vendor containing vendor information.
*
* @throws ProductException if the information cannot be committed.
*/
public void updateVendor(Vendor vendor) throws ProductException
{
try
{
updateDaoBean("vendor",vendor);
}
catch (ServiceException se)
{
logSevere("updateVendor exception",se);
throw new ProductException(getProperty("messages.commit.vendor_error"));
}
}
/**
* Return product information as a Product instance using the given id.
*
* @param id Product identifier.
*
* @return Product instance containing product information.
*/
public Product getProduct(Integer id) throws ProductException
{
try
{
Product prd = (Product)m_ormService.resolve("product",id);
logInfo("Returning product: "+prd.toString());
return prd;
/* return (Product)getDaoWorker().getEntryByPrimaryKey("product",
id,
Product.class);
*/
}
catch (DaoException de)
{
logSevere("getProduct exception",de);
throw new ProductException(getProperty("messages.get.product_error"));
}
}
/**
* Return product type information as a ProductType instance using the given
* id.
*
* @param id ProductType identifier.
*
* @return ProductType instance containing type information.
*/
public ProductType getProductType(Integer id) throws ProductException
{
try
{
return (ProductType)getDaoWorker().getEntryByPrimaryKey(
"product_type",
id,
ProductType.class);
}
catch (DaoException de)
{
logSevere("getProductType exception",de);
throw new ProductException(getProperty("messages.get.type_error"));
}
}
/**
* Return vendor information as a Vendor instance using the given id.
*
* @param id Vendor identifier.
*
* @return Vendor instance containing vendor information.
*/
public Vendor getVendor(Integer id) throws ProductException
{
try
{
return (Vendor)getDaoWorker().getEntryByPrimaryKey("vendor",
id,
Vendor.class);
}
catch (DaoException de)
{
logSevere("getVendor exception",de);
throw new ProductException(getProperty("messages.get.vendor_error"));
}
}
/**
* Remove the product with the given identifier.
*
* @param id Product identifier.
*
* @throws ProductException if the product cannot be removed.
*/
public void removeProduct(Integer id) throws ProductException
{
try
{
getDaoWorker().removeEntryByPrimaryKey("product",id);
}
catch (DaoException de)
{
logSevere("removeProduct exception",de);
throw new ProductException(getProperty("messages.commit.product_error"));
}
}
/**
* Remove the product type with the given identifier.
*
* @param id ProductType identifier.
*
* @throws ProductException if the product type cannot be removed.
*/
public void removeProductType(Integer id) throws ProductException
{
try
{
getDaoWorker().removeEntryByPrimaryKey("product_type",id);
}
catch (DaoException de)
{
logSevere("removeProductType exception",de);
throw new ProductException(getProperty("messages.commit.type_error"));
}
}
/**
* Remove the vendor with the given identifier.
*
* @param id Vendor identifier.
*
* @throws ProductException if the vendor cannot be removed.
*/
public void removeVendor(Integer id) throws ProductException
{
try
{
getDaoWorker().removeEntryByPrimaryKey("vendor",id);
}
catch (DaoException de)
{
logSevere("removeVendor exception",de);
throw new ProductException(getProperty("messages.commit.vendor_error"));
}
}
/**
* Return all products.
*
* @return List containing Product instances.
*
* @throws ProductException if the product information cannot be retrieved.
*/
public List getProducts() throws ProductException
{
try
{
return m_ormService.resolve("product");
//return getDaoWorker().getAllEntries("product",Product.class);
}
catch (DaoException de)
{
logSevere("getProducts exception",de);
throw new ProductException(getProperty("messages.get.product_error"));
}
}
/**
* Return all product types.
*
* @return List containing ProductType instances.
*
* @throws ProductException if the product type information cannot be
* retrieved.
*/
public List getProductTypes() throws ProductException
{
try
{
return getDaoWorker().getAllEntries("product_type",ProductType.class);
}
catch (DaoException de)
{
logSevere("getProductTypes exception",de);
throw new ProductException(getProperty("messages.get.type_error"));
}
}
/**
* Return all vendors.
*
* @return List containing Vendor instances.
*
* @throws ProductException if the vendor information cannot be retrieved.
*/
public List getVendors() throws ProductException
{
try
{
return getDaoWorker().getAllEntries("vendor",Vendor.class);
}
catch (DaoException de)
{
logSevere("getVendors exception",de);
throw new ProductException(getProperty("messages.get.vendor_error"));
}
}
/**
* The injection point of the ORMQueryService dependency of this
* service implementation.
*
* @param ormService ORMQueryService dependency.
*/
public void setORMQueryService(ORMQueryService ormService)
{
m_ormService = ormService;
}
//members
private ORMQueryService m_ormService = null;
}