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

📄 recontentimpl.java

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

import java.util.List;

import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.ReContentDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.ReContent;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.TopicParameter;

public class ReContentImpl implements ReContentDAO {
	
	private static final String FIND_REPLYID = "from ReContent where replyId=?";
	
	private static final String FIND_RECONTENTID = "from ReContent where reContentId=?";
	
	private static final String DELETE_RECONTENTID = "delete from ReContent where reContentId=?";
	
	private static final String DELETES_RECONTENTID = "delete from ReContent where reContentId in (:ids)";

	private static final String DELETE_TOPICID = "delete from ReContent where topicId=?";
	
	private static final String DELETE_REPLYID = "delete from ReContent where replyId=?";
	
	private static final String DELETES_TOPICID = "delete from ReContent where topicId in (:ids)";

	private static final String DELETES_REPLYID = "delete from ReContent where replyId in (:ids)";
	
	
	public int deleteByReplyId(int replyId) throws DAOException{
        HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(DELETE_REPLYID);
        facade.setInt(0, replyId);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public void create(ReContent item) throws DAOException {
		HibernateProvider<ReContent> facade = new HibernateFacade<ReContent>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public void update(ReContent item) throws DAOException {
		HibernateProvider<ReContent> facade = new HibernateFacade<ReContent>();
		try{
			facade.update(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

	public int delete(List<Integer> ids) throws DAOException {
    	HibernateProvider<ReContent> facade = new HibernateFacade<ReContent>();
		facade.createQuery(DELETES_RECONTENTID);
		facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	

	public int deleteByReplyId(List<Integer> ids) throws DAOException {
        HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(DELETES_REPLYID);
        facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}
	
	public int deleteByTopicId(int topicId) throws DAOException {
        HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(DELETE_TOPICID);
        facade.setInt(0, topicId);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public int deleteByTopicId(List<Integer> ids) throws DAOException {
        HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(DELETES_TOPICID);
        facade.setParameterList("ids",ids);
		try{
			return facade.executeUpdate();
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

	public ReContent findById(int id) {
		HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(FIND_RECONTENTID);
        facade.setInt(0,id);
        facade.setMaxResults(1);
		return facade.uniqueResult();
	}
	
	public ReContent findByReplyId(int replyId) {
		HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
        facade.createQuery(FIND_REPLYID);
        facade.setInt(0,replyId);
        facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public List<ReContent> findByParameter(TopicParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from ReContent where reContentId>0 ");
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
		}
		/*
		if(param.getOrderBy()==null){
			hql.append(" order by replyId");
		}else{
			hql.append(" order by replyId");
		}
		*/
		hql.append(" order by replyId");
		HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
		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(reContentId) from ReContent where reContentId>0 ");
		if(param.getTopicId()!=null){
			hql.append(" and topicId=");
			hql.append(param.getTopicId());
		}
		if(param.getIsDeleted()!=null){
			hql.append(" and isDeleted=?");
		}
		HibernateFacade<ReContent> facade = new HibernateFacade<ReContent>();
		facade.createQuery(hql);
		if(param.getIsDeleted()!=null){
			facade.setBoolean(0, param.getIsDeleted().booleanValue());
		}
		return facade.resultTotal();
	}

	public List<ReContent> findAll(TopicParameter param) {
		return this.findByParameter(param);
	}

	public long countAll(TopicParameter param) {
		return this.countByParameter(param);
	}

}

⌨️ 快捷键说明

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