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);
}
}
Service基本功能封装
最新推荐文章于 2021-08-17 09:36:26 发布