package com.newvideo.service.imp; import java.io.Serializable; import java.util.List; import javax.annotation.Resource; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.newvideo.dao.FindVideoDao; import com.newvideo.domain.FindVideo; import com.newvideo.util.Constant; @Service public class FindVideoService { @Resource private FindVideoDao dao; public List getFindVideoList(long cid, int page) { return dao.list( "from FindVideo where findClass.id = ? order by orderBy desc", (page - 1) * Constant.pageCount, Constant.pageCount, new Serializable[] { cid }); } public FindVideo getFindVideo(long id) { return dao.find(FindVideo.class, id); } @Transactional public void delete(long id) { dao.delete(new FindVideo(id)); } @Transactional public void update(FindVideo fv) { dao.update(fv); } @Transactional public Long save(FindVideo fv) { return (Long) dao.save(fv); } public int getCount(long cid) { return (int) dao.getCount("select count(*) from FindVideo where findClass.id=?", new Serializable[]{cid}); } @Transactional public void deleteByCid(final Long id) { dao.excute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("delete FindVideo fv where fv.findClass.id = ? "); query.setParameter(0, id); query.executeUpdate(); return null; } }); } }