roleimpl.java

来自「野蔷薇论坛源码 java 自己看看吧。 学习用」· Java 代码 · 共 113 行

JAVA
113
字号
/* 
 * Created on 2007-1-19
 * 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 org.apache.log4j.Logger;

import com.yeqiangwei.club.dao.RoleDAO;
import com.yeqiangwei.club.dao.hibernate.support.HibernateFacade;
import com.yeqiangwei.club.dao.hibernate.support.HibernateProvider;
import com.yeqiangwei.club.dao.model.Role;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.RoleParameter;

public class  RoleImpl implements RoleDAO {
	
	private static final String FIND_ALL = "from Role";
	
	private static final String FIND_USERGROUPID = "from Role where roleId=?";
	
	private static final String DELETE_USERGROUPID = "delete from Role where roleId=?";
	
	private static final String DELETES_USERGROUPID = "delete from Role where roleId in(:ids)";
	
	//private static final Logger logger = Logger.getLogger(RoleImpl.class);
	
	public void create(Role item) throws DAOException {
		HibernateProvider<Role> facade = new HibernateFacade<Role>();
		try{
			facade.save(item);
		}catch(HibernateException e){
			throw new DAOException(e);
		}
	}

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

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

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

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

	public List<Role> findByParameter(RoleParameter param) {
		StringBuffer hql = new StringBuffer();
		hql.append("from Role ");
		if(param.getForumId()==null){
			//hql.append(" where forumId=");
			//hql.append(param.getForumId());
			hql.append("  order by roleId desc");
		}
		else if(param.getForumId().intValue()>0){
			hql.append(" where forumId=");
			hql.append(param.getForumId().intValue());
			hql.append("  order by forumId asc, roleId asc");
		}
		HibernateFacade<Role> facade = new HibernateFacade<Role>();
		facade.createQuery(hql);
		return facade.executeQuery();
	}

	public long countByParameter(RoleParameter param) {
		return 0;
	}

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

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

⌨️ 快捷键说明

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