📄 roleimpl.java
字号:
/*
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -