📄 categoryserviceimpl.java
字号:
package cn.hxex.library.service.impl;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataIntegrityViolationException;
import cn.hxex.library.dao.CategoryDao;
import cn.hxex.library.exception.LibraryException;
import cn.hxex.library.model.Category;
import cn.hxex.library.service.CategoryService;
/**
* CategoryService的实现类
*
* @author galaxy
*
*/
public class CategoryServiceImpl implements CategoryService
{
// the logger for this class
private Log logger = LogFactory.getLog(this.getClass());
private CategoryDao categoryDao;
/**
* @return Returns the categoryDao.
*/
public CategoryDao getCategoryDao()
{
return categoryDao;
}
/**
* @param categoryDao The categoryDao to set.
*/
public void setCategoryDao(CategoryDao categoryDao)
{
this.categoryDao = categoryDao;
}
public Category saveCategory(Category category)
throws LibraryException
{
try
{
Category c = this.getCategoryDao().saveCategory( category );
return c;
}
catch( DataIntegrityViolationException de )
{
throw LibraryException.getDuplicateCategoryNameException();
}
catch( Exception e )
{
String msg = "Could not save category " + e.toString();
this.logger.error(msg, e);
throw new LibraryException(msg, e);
}
}
public List getAllCategorys()
{
return this.categoryDao.getAllCategorys();
}
public void deleteCategory( String categoryId ) throws LibraryException
{
Category category = getCategory( categoryId );
if( !category.getProducts().isEmpty() )
{
throw LibraryException.getCategoryExistProductException();
}
this.categoryDao.deleteCategory( category );
}
public Category getCategory( String categoryId )
throws LibraryException
{
Category category = this.categoryDao.getCategory( categoryId );
if( category==null )
{
throw LibraryException.getCategoryNotExistException();
}
return category;
}
public Category updateCategory(Category category) throws LibraryException
{
try
{
Category c = this.getCategoryDao().updateCategory( category );
return c;
}
catch( DataIntegrityViolationException de )
{
throw LibraryException.getDuplicateCategoryNameException();
}
catch( Exception e )
{
String msg = "Could not save category " + e.toString();
this.logger.error(msg, e);
throw new LibraryException(msg, e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -