⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commentdao.java

📁 在线读书交流平台
💻 JAVA
字号:
package com.olr.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.olr.beans.Book;
import com.olr.beans.Comment;
import com.olr.util.Pager;

/**
 * A data access object (DAO) providing persistence and search support for
 * Comment 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.Comment
 * @author MyEclipse Persistence Tools
 */

public class CommentDAO extends HibernateDaoSupport implements ICommentDAO{

	public void deleteComment(int commentId) {
		Object c=this.getHibernateTemplate().load(Comment.class,new Integer(commentId));
		this.getHibernateTemplate().delete(c);
		
	}

	public Pager getCommentsPager(int chapterId, int pageNo, int pageSize) {
         Session session=this.getHibernateTemplate().getSessionFactory().openSession();
		
		Criteria criteria=session.createCriteria(Comment.class);
		criteria.add(Restrictions.eq("chapterId", chapterId));
		int rowCount=((Integer)criteria.setProjection(
				Projections.rowCount()).uniqueResult()).intValue();
		criteria.setProjection(null);
		int startIndex=pageSize*(pageNo-1);
		criteria.addOrder(Order.desc("postdate"));
		criteria.setFirstResult(startIndex);
		criteria.setMaxResults(pageSize);
		List result=criteria.list();
		session.close();
		return new Pager(pageSize,pageNo,rowCount,result); 
	}

	public List<Comment> getTopComments(int chapterId, int topNum) {
		Session session=this.getHibernateTemplate().getSessionFactory().openSession();
		Criteria criteria=session.createCriteria(Comment.class);
		criteria.add(Restrictions.eq("chapterId", chapterId));
		criteria.addOrder(Order.desc("postdate"));
		criteria.setMaxResults(topNum);
		List result=criteria.list();
		return result;
	}
	public void insertCommnet(Comment comment) {
		this.getHibernateTemplate().save(comment);
		
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -