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

📄 replyimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
字号:
/* 
 * Created on 2007-1-22
 * Last modified on 2007-3-28
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;

import org.apache.log4j.Logger;

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.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 Reply create(Reply item) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		item = facade.save(item);		
		return item;
	}

	public Reply update(Reply item) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		item = facade.update(item);		
		return item;
	}
	
	/*
	 * tree utils method
	 */
	public int updatesOrderlistByTopicId(Reply item)
	{
        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());
		int c = facade.executeUpdate();
		return c;
	}

	public int delete(Reply item) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETE_REPLYID);
		facade.setInt(0, item.getReplyId());
		int c = facade.executeUpdate();
		return c;
	}

	public int delete(List<Integer> ids) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETES_REPLYID);
		facade.setParameterList("ids",ids);
		int c = facade.executeUpdate();
		return c;
	}
	
	public int deleteByTopicId(List<Integer> ids) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETES_TOPICID);
		facade.setParameterList("ids",ids);
		int c = facade.executeUpdate();
		return c;
	}
	
	public int deleteByTopicId(int topicId) {
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(DELETE_TOPICID);
		facade.setInt(0, topicId);
		int c = facade.executeUpdate();
		return c;
	}
	
	public Reply findById(int id) {
		Reply item = null;
		HibernateFacade<Reply> facade = new HibernateFacade<Reply>();
		facade.createQuery(FIND_REPLYID);
		facade.setInt(0, id);
		facade.setMaxResults(1);
		item = (Reply) facade.uniqueResult();
		return item;
	}

	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());
		List<Reply> list = facade.executeQuery();
		return list;
	}

	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());
		}
		facade.setCacheable(true);
		long c = facade.resultTotal();
		//logger.debug(c);
		return c;
	}

	public List 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());
		List list = facade.executeQuery();
		return list;
	}

	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());
		}
		long c = facade.resultTotal();
		return c;
	}

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


}

⌨️ 快捷键说明

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