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);
}
}
版权声明:本文为woaixuweisi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。