📄 chapterdao.java
字号:
package com.olr.dao;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.olr.beans.Chapter;
import com.olr.beans.Comment;
import com.olr.util.Pager;
/**
* A data access object (DAO) providing persistence and search support for
* Chapter entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.olr.beans.Chapter
* @author MyEclipse Persistence Tools
*/
public class ChapterDAO extends HibernateDaoSupport implements IChapterDAO{
public void deleteChapter(int chapterId) {
Object c=this.getHibernateTemplate().load(Chapter.class,new Integer(chapterId));
this.getHibernateTemplate().delete(c);
}
public Chapter getChapterById(int chapterId){
return (Chapter) this.getHibernateTemplate().load(Chapter.class, new Integer(chapterId));
}
public Chapter getChapterByNum(int chapterNum, int bookId) {
Session session=this.getHibernateTemplate().getSessionFactory().openSession();
Criteria criteria=session.createCriteria(Chapter.class);
List<Chapter> result=criteria.add(Restrictions.eq("bookId",bookId)).add(
Restrictions.eq("chapterNum", chapterNum)
).list();
Chapter chapter=result.get(0);
session.close();
return chapter;
}
public int getChapterCount(int bookId){
Session session=this.getHibernateTemplate().getSessionFactory().openSession();
Criteria criteria=session.createCriteria(Chapter.class);
criteria.add(Restrictions.eq("bookId", bookId));
int rowCount = ((Integer) criteria.setProjection(
Projections.rowCount()).uniqueResult()).intValue();
session.close();
return rowCount;
}
public void insertChapter(Chapter chapter) {
this.getHibernateTemplate().saveOrUpdate(chapter);
}
public void updateChapter(Chapter chapter) {
this.getHibernateTemplate().update(chapter);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -