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

📄 forumimpl.java

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

import java.util.List;

import org.hibernate.HibernateException;

import com.yeqiangwei.club.dao.ForumDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Forum;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.ForumParameter;

public class ForumImpl implements ForumDAO {
	
	private static final String FIND_FORUMID = "from Forum where forumId=?";
	
	private static final String DELETE_FORUMID = "delete from Forum where forumId=?";
	
	private static final String DELETES_FORUMID = "delete from Forum where forumId in (:ids)";
	
	public void create(Forum item) throws DAOException {
		HibernateProvider<Forum> facade = new HibernateFacade<Forum>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

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

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

	public Forum findById(int id) {
        HibernateProvider<Forum> facade = new HibernateFacade<Forum>(FIND_FORUMID);
        facade.setInt(0, id);
        facade.setMaxResults(1);
        return facade.uniqueResult();
	}

	public List<Forum> findByParameter(ForumParameter param) {
        StringBuffer hql = new StringBuffer();
        hql.append("from Forum where forumId>0 "); 
    	if(param.getForumId()!=null){
    		hql.append(" and forumId=");
    		hql.append(param.getForumId().intValue());
    	}
    	if(param.getForumIdd()!=null){
    		hql.append(" and forumIdd=");
    		hql.append(param.getForumIdd().intValue());
    	}
    	if(param.getType()!=null){
    		hql.append(" and type=");
    		hql.append(param.getType().byteValue());
    	}
    	if(param.getIsHidden()!=null){
    		hql.append(" and isHidden=?");
    	}
    	hql.append(" order by orderList desc");
		HibernateProvider<Forum> facade = new HibernateFacade<Forum>();
	    facade.createQuery(hql);
	    if(param.getIsHidden()!=null){
	    	facade.setBoolean(0, param.getIsHidden().booleanValue());
	    }
	    facade.setFirstResult(param.getPagination().getStartRow());
	    facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();  
	}

	public long countByParameter(ForumParameter param) {
        StringBuffer hql = new StringBuffer();
        hql.append("select count(forumId) from Forum where forumId>0 "); 
    	if(param.getForumId()!=null){
    		hql.append(" and forumId=");
    		hql.append(param.getForumId().intValue());
    	}
    	if(param.getForumIdd()!=null){
    		hql.append(" and forumIdd=");
    		hql.append(param.getForumIdd().intValue());
    	}
    	if(param.getType()!=null){
    		hql.append(" and type=");
    		hql.append(param.getType().byteValue());
    	}
    	if(param.getIsHidden()!=null){
    		hql.append(" and isHidden=?");
    	}
    	HibernateProvider<Forum> facade = new HibernateFacade<Forum>();
    	facade.createQuery(hql);
	    if(param.getIsHidden()!=null){
	    	facade.setBoolean(0, param.getIsHidden().booleanValue());
	    }
		return facade.resultTotal();
	}

	public List<Forum> findAll(ForumParameter param) {
		return null;
	}

	public long countAll(ForumParameter param) {
		return 0;
	}
}

⌨️ 快捷键说明

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