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

📄 groupofforumimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-1-6
 * 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.GroupOfForumDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.GroupOfForum;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.GroupOfForumParameter;


public class GroupOfForumImpl implements GroupOfForumDAO {
	
	private static final String FIND_ALL = "from GroupOfForum";
	
	private static final String FIND_USERID_FORUMID = "from GroupOfForum where userId=? and forumId=?";
	
	private static final String FIND_ID = "from GroupOfForum where groupOfForumId=?";
	
	private static final String DELETE_ID = "delete from GroupOfForum where groupOfForumId=?";
	
	private static final String DELETES_ID = "delete from GroupOfForum where groupOfForumId in(:ids)";
	
	public void create(GroupOfForum item) throws DAOException {
		HibernateProvider<GroupOfForum> facade = new HibernateFacade<GroupOfForum>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

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

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

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

	public GroupOfForum findByUserIdAndForumId(int userId, int forumId) {
		HibernateProvider<GroupOfForum> facade = new HibernateFacade<GroupOfForum>();
    	facade.createQuery(FIND_USERID_FORUMID);
        facade.setInt(0, userId);
        facade.setInt(1, forumId);
        facade.setMaxResults(1);
		return facade.uniqueResult();
	}

	public List<GroupOfForum> findByParameter(GroupOfForumParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from GroupOfForum ");
		if(param.getForumId()!=null){
			hql.append(" where forumId=");
			hql.append(param.getForumId().intValue());
			if(param.getUserId()!=null){
				hql.append(" and userId=");
				hql.append(param.getUserId().intValue());
			}
		}
		else if(param.getUserId()!=null){
			hql.append(" where userId=");
			hql.append(param.getUserId().intValue());
			if(param.getForumId()!=null){
				hql.append(" and forumId=");
				hql.append(param.getForumId().intValue());
			}
		}
		if(param.getGroupId()!=null){
			hql.append(" and groupId=");
			hql.append(param.getGroupId().intValue());
		}
		HibernateProvider<GroupOfForum> facade = new HibernateFacade<GroupOfForum>();
    	facade.createQuery(hql);
    	facade.setFirstResult(param.getPagination().getStartRow());
    	facade.setMaxResults(param.getPagination().getEndRow());
		return facade.executeQuery();  
	}

	public long countByParameter(GroupOfForumParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("select count (groupOfForumId) from GroupOfForum ");
		if(param.getForumId()!=null){
			hql.append(" where forumId=");
			hql.append(param.getForumId().intValue());
			if(param.getUserId()!=null){
				hql.append(" and userId=");
				hql.append(param.getUserId().intValue());
			}
		}
		else if(param.getUserId()!=null){
			hql.append(" where userId=");
			hql.append(param.getUserId().intValue());
			if(param.getForumId()!=null){
				hql.append(" and forumId=");
				hql.append(param.getForumId().intValue());
			}
		}
		if(param.getGroupId()!=null){
			hql.append(" and groupId=");
			hql.append(param.getGroupId().intValue());
		}
		HibernateProvider<GroupOfForum> facade = new HibernateFacade<GroupOfForum>();
    	facade.createQuery(hql);
    	return facade.resultTotal();
	}

	public List<GroupOfForum> findAll(GroupOfForumParameter param) {
		HibernateProvider<GroupOfForum> facade = new HibernateFacade<GroupOfForum>();
    	facade.createQuery(FIND_ALL);
		return facade.executeQuery();  
	}

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

	public Object findByForumId(int forumId) {
		GroupOfForumParameter param = new GroupOfForumParameter();
		param.setForumId(new Integer(forumId));
		return this.findByParameter(param);
	}
	
}

⌨️ 快捷键说明

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