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

📄 replyimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-1-22
 * Last modified on 2007-10-1
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.ReplyDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.model.Reply;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.TopicParameter;

public class ReplyImpl implements ReplyDAO{
	
	private static final String FIND_REPLYID = "from Reply where replyId=?";
	
	//private static final String FIND_TOPICID = "from Reply where topicId=?";
	
	private static final String DELETE_REPLYID = "delete from Reply where replyId=?";
	
	private static final String DELETES_REPLYID = "delete from Reply where replyId in (:ids)";
	
	private static final String DELETE_TOPICID = "delete from Reply where topicId=?";
	
	private static final String DELETES_TOPICID = "delete from Reply where topicId in (:ids)";
	
	private static final Logger logger = Logger.getLogger(ReplyImpl.class);

	public void create(Reply item) throws DAOException {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(Reply item) throws DAOException {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
        try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}	
	}
	
	/*
	 * tree utils method
	 */
	public int updatesOrderlistByTopicId(Reply item) throws DAOException
	{
        StringBuffer hql = new StringBuffer();
		hql.append("update Reply set orderlist=orderlist+1 ");
		if(item.getReplyId()==0){
			hql.append(" where topicId=");
			hql.append(item.getTopicId());
		}else{
			hql.append(" where topicId=");
			hql.append(item.getTopicId());
			hql.append(" and orderlist>");
			hql.append(item.getOrderlist());
		}
		logger.debug(hql);
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(hql.toString());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(Reply item) throws DAOException {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETE_REPLYID);
		facade.setInt(0, item.getReplyId());
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int delete(List<Integer> ids) throws DAOException {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETES_REPLYID);
		facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public int deleteByTopicId(List<Integer> ids) throws DAOException {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETES_TOPICID);
		facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public int deleteByTopicId(int topicId) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETE_TOPICID);
		facade.setInt(0, topicId);
		return facade.executeUpdate();
	}
	
	public Reply findById(int id) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(FIND_REPLYID);
		facade.setInt(0, id);
		facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public List<Reply> findByParameter(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Reply where replyId>0");
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId().intValue());
		}
		if(param.getUserId()!=null){
			hql.append(" and userId=");
			hql.append(param.getUserId().intValue());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
		}
		if(param.getOrderBy()==null){
			hql.append(" order by replyId");
		}
		else if(param.getOrderBy().byteValue()==0){
			hql.append(" order by replyId");
		}
		else if(param.getOrderBy().byteValue()==1){
			hql.append(" order by orderlist");
		}
		else if(param.getOrderBy().byteValue()==2){
			hql.append(" order by replyId desc");
		}
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0,param.getIsDeleted().booleanValue());
		}
		facade.setFirstResult(param.getPagination().getStartRow());
		facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();
	}

	public long countByParameter(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count(replyId) from Reply where replyId>0 ");
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId().intValue());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
			
		}
		//logger.debug(hql);
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0,param.getIsDeleted().booleanValue());
		}
		return facade.resultTotal();
	}

	public List<Reply> findAll(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Reply ");
		if(param.getIsDeleted()!=null){
			hql.append(" where isDeleted=?");
		}
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0,param.getIsDeleted().booleanValue());
		}
		facade.setFirstResult(param.getPagination().getStartRow());
		facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();
	}

	public long countAll(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count(replyId) from Reply ");
		if(param.getIsDeleted()!=null){
			hql.append(" where isDeleted=?");
		}
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0,param.getIsDeleted().booleanValue());
		}
		return facade.resultTotal();
	}

	public Reply findLastReply() {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery("from Reply order by replyId desc");
		facade.setMaxResults(1);
		return facade.uniqueResult();
	}


}

⌨️ 快捷键说明

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