001: package com.odal.petstore.service;
002:
003: import com.completex.objective.components.persistency.transact.Transaction;
004: import com.completex.objective.components.persistency.transact.TransactionManager;
005: import com.odal.petstore.OdalPetstoreException;
006: import com.odal.petstore.domain.Category;
007: import com.odal.petstore.domain.Item;
008: import com.odal.petstore.domain.Product;
009: import com.odal.petstore.persistence.iface.CategoryDao;
010: import com.odal.petstore.persistence.iface.ItemDao;
011: import com.odal.petstore.persistence.iface.ProductDao;
012:
013: import java.util.List;
014:
015: /**
016: * @author Gennady Krizhevsky
017: */
018: public class CatalogService {
019: private CategoryDao categoryDao;
020: private ItemDao itemDao;
021: private ProductDao productDao;
022:
023: private TransactionManager transactionManager;
024:
025: public CatalogService(TransactionManager transactionManager,
026: CategoryDao categoryDao, ItemDao itemDao,
027: ProductDao productDao) {
028: this .categoryDao = categoryDao;
029: this .itemDao = itemDao;
030: this .productDao = productDao;
031: this .transactionManager = transactionManager;
032: }
033:
034: public List getCategoryList() throws OdalPetstoreException {
035: Transaction transaction = transactionManager.beginUnchecked();
036: try {
037: return categoryDao.getCategoryList();
038: } finally {
039: transactionManager.rollbackSilently(transaction);
040: }
041: }
042:
043: public Category getCategory(final String categoryId)
044: throws OdalPetstoreException {
045: Transaction transaction = transactionManager.beginUnchecked();
046: try {
047: return categoryDao.getCategory(categoryId);
048: } finally {
049: transactionManager.rollbackSilently(transaction);
050: }
051: }
052:
053: public Product getProduct(final String productId)
054: throws OdalPetstoreException {
055: Transaction transaction = transactionManager.beginUnchecked();
056: try {
057: return productDao.getProduct(productId);
058: } finally {
059: transactionManager.rollbackSilently(transaction);
060: }
061: }
062:
063: public List getProductListByCategory(final String categoryId,
064: final int pageNumber) throws OdalPetstoreException {
065: Transaction transaction = transactionManager.beginUnchecked();
066: try {
067: return productDao.getProductListByCategory(categoryId,
068: pageNumber);
069: } finally {
070: transactionManager.rollbackSilently(transaction);
071: }
072: }
073:
074: public List searchProductList(final String keywords,
075: final int pageNumber) throws OdalPetstoreException {
076: Transaction transaction = transactionManager.beginUnchecked();
077: try {
078: return productDao.searchProductList(keywords, pageNumber);
079: } finally {
080: transactionManager.rollbackSilently(transaction);
081: }
082: }
083:
084: public List getItemListByProduct(final String productId)
085: throws OdalPetstoreException {
086: Transaction transaction = transactionManager.beginUnchecked();
087: try {
088: return itemDao.getItemListByProduct(productId);
089: } finally {
090: transactionManager.rollbackSilently(transaction);
091: }
092:
093: }
094:
095: public Item getItem(final String itemId)
096: throws OdalPetstoreException {
097: Transaction transaction = transactionManager.beginUnchecked();
098: try {
099: return itemDao.getItem(itemId);
100: } finally {
101: transactionManager.rollbackSilently(transaction);
102: }
103: }
104:
105: public boolean isItemInStock(final String itemId)
106: throws OdalPetstoreException {
107: Transaction transaction = transactionManager.beginUnchecked();
108: try {
109: return itemDao.isItemInStock(itemId);
110: } finally {
111: transactionManager.rollbackSilently(transaction);
112: }
113: }
114: }
|