forumimpl.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 125 行

JAVA
125
字号
/* 
 * Created on 2005-12-25
 * Last modified on 2007-12-20
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.dao.hibernate.impl;

import java.util.List;
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.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>();
		facade.save(item);
	}
	
	public Forum findByForumName(String name){
		HibernateProvider<Forum> facade = new HibernateFacade<Forum>("from Forum where forumName=?");
        facade.setString(0, name);
        facade.setMaxResults(1);
        return facade.uniqueResult();
	}

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

	public int delete(Forum item) {
    	HibernateProvider<Forum> facade = new HibernateFacade<Forum>();
		facade.createQuery(DELETE_FORUMID);
		facade.setInt(0, item.getForumId());
		return facade.executeUpdate();
	}

	public int delete(List<Integer> ids) {
    	HibernateProvider<Forum> facade = new HibernateFacade<Forum>();
		facade.createQuery(DELETES_FORUMID);
		facade.setParameterList("ids",ids);
		return facade.executeUpdate();
	}

	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 + =
减小字号Ctrl + -
显示快捷键?