Service基本功能封装

import com.iloosen.imall.commons.util.BusinessException;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
@Transactional(readOnly = true)
public abstract class BaseEntityManager <E,PK extends Serializable>{
	
//	private Log log = LogFactory.getLog(getClass());

	protected abstract EntityDao<E,PK> getEntityDao();

	@Transactional(readOnly=true) 
	public E getById(PK id) throws BusinessException {
		return getEntityDao().getById(id);
	}
	
	@Transactional(readOnly=true)
	public List<E> findAll() throws BusinessException {
		return getEntityDao().findAll();
	}
	
	/** 根据id检查是否插入或是更新数据 */
	@Transactional
	public void saveOrUpdate(E entity) throws BusinessException {
		getEntityDao().saveOrUpdate(entity);
	}
	
	/** 插入数据 */
	@Transactional
	public void save(E entity) throws BusinessException {
		getEntityDao().save(entity);
	}
	
	@Transactional
	public void removeById(PK id) throws BusinessException {
		getEntityDao().deleteById(id);
	}
	
	@Transactional
	public void update(E entity) throws BusinessException {
		getEntityDao().update(entity);
	}
	
	@Transactional(readOnly=true)
	public boolean isUnique(E entity, String[] uniquePropertyNames) {
		return getEntityDao().isUnique(entity, uniquePropertyNames);
	}

	@Transactional
	public void flush() {
		getEntityDao().flush();
	}

	@Transactional(readOnly=true)
	public void refresh(BaseEntity entity) {
		getEntityDao().refresh(entity);
	}
}

猜你喜欢

转载自iweisi.iteye.com/blog/1032670