package com.forveross.plane.service.impl; import java.util.List; import org.hibernate.Query; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.forveross.plane.service.TaskInfoService; import com.forveross.plane.vo.TaskInfo; import com.kit.common.dao.abstr.AbstractDao; /** * 数据持久化处理类实现 * * @author ahomeeye * */ @Transactional @Scope("singleton") @Service("taskInfoServiceImpl") public class TaskInfoServiceImpl extends AbstractDao implements TaskInfoService { @Override public TaskInfo findTaskInfo(long id) throws Exception { return (TaskInfo) getHibernateDao().getHibernateTemplate().get( TaskInfo.class, id); } @Override public void deleteTaskInfo(long id) throws Exception { getHibernateDao().getHibernateTemplate().delete(findTaskInfo(id)); getOscacheFactory().removeObjectByGroup(TaskInfo.class.getName()); } @Override public void deleteTaskInfo(TaskInfo ti) throws Exception { getHibernateDao().getHibernateTemplate().delete(ti); getOscacheFactory().removeObjectByGroup(TaskInfo.class.getName()); } @Override public void updateTaskInfo(TaskInfo ti) throws Exception { getHibernateDao().getHibernateTemplate().update(ti); getOscacheFactory().removeObjectByGroup(TaskInfo.class.getName()); } @Override public void saveOrUpdateTaskInfo(TaskInfo ti) throws Exception { getHibernateDao().getHibernateTemplate().saveOrUpdate(ti); getOscacheFactory().removeObjectByGroup(TaskInfo.class.getName()); } @Override public void saveTaskInfo(TaskInfo ti) throws Exception { getHibernateDao().getHibernateTemplate().save(ti); getOscacheFactory().removeObjectByGroup(TaskInfo.class.getName()); } public int countTaskInfo() { String hql = "select count(*) from TaskInfo"; Object o = getHibernateDao().getSessionFactory().getCurrentSession() .createQuery(hql).uniqueResult(); return Integer.parseInt(o.toString()); } @Override @SuppressWarnings("unchecked") public List<TaskInfo> findTaskInfoList(int pageNum, int pageSize) { pageNum = pageNum > 1 ? pageNum - 1 : 0; pageSize = pageSize > 0 ? pageSize : 10; String hql = "from TaskInfo t order by t.grabChannel asc"; Query query = getHibernateDao().getSessionFactory().getCurrentSession() .createQuery(hql); query.setFirstResult(pageNum * pageSize); query.setMaxResults(pageSize); return (List<TaskInfo>) query.list(); } }