package com.javaniu.dao.impl; import java.util.List; import org.hibernate.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.javaniu.dao.FileDao; import com.javaniu.module.File; @Transactional(readOnly = false, propagation = Propagation.SUPPORTS) @Repository public class FileDaoImpl extends BaseDaoImpl implements FileDao { @Override public void save(File file) { getSession().save(file); } @Override public void delete(Long id) { File file = findById(id); getSession().delete(file); } @Override public void delete(File file) { getSession().delete(file); } @Override public void update(File file) { getSession().update(file); } @Override public File findById(Long id) { return (File) getSession().get(File.class, id); } @Override public List<File> loadAll(int p, int ps) { String hql = "from File order by id desc"; Query query = getSession().createQuery(hql); query.setFirstResult((p - 1) * ps); query.setMaxResults(ps); List<File> list = query.list(); return list; } @Override public int countAll() { String hql = "select count(*) from File"; Query query = getSession().createQuery(hql); return ((Number) query.uniqueResult()).intValue(); } }
最近下载更多