📄 roledaoimpl.java
字号:
package com.isoftstone.isscrmweb.web.dao.frame;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Projections;
import org.pontifex.orm.hibernate3.DaoImpl;
import org.pontifex.orm.hibernate3.PageInfoCriteriaCallback;
import org.pontifex.orm.hibernate3.PageInfoQueryCallback;
import org.pontifex.web.mapping.PageInfo;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.isoftstone.isscrmweb.web.mapping.Roleandmenu;
import com.isoftstone.isscrmweb.web.mapping.Roleinfo;
import com.isoftstone.isscrmweb.web.mapping.Userinfo;
public class RoleDaoImpl extends DaoImpl implements RoleDao {
/**
* 角色列表
*/
public PageInfo getRoleList1(final Roleinfo role) {
return pageInfoLookup( role ,new PageInfoCriteriaCallback(){
public Criteria doInPageInfo(Session session) throws HibernateException {
Criteria criteria = session.createCriteria(Roleinfo.class);
if(role.getRolename()!=null&&!role.getRolename().equals("")){
criteria.add(Expression.like("rolename", role.getRolename(),MatchMode.ANYWHERE));
}
if(role.getState()!=null&&!role.getState().equals("")){
criteria.add(Expression.eq("state", role.getState()));
}
return criteria ;
}
});
}
public PageInfo getRoleList(final Roleinfo role) {
// return (PageInfo) this.getHibernateTemplate().execute(new HibernateCallback(){
//
// public Object doInHibernate(Session session) throws HibernateException, SQLException {
// String hql = "from Roleinfo as r where r.roleid is not null ";
// if(role.getRolename()!=null&&!role.getRolename().equals("")){
// hql+=" and r.rolename like :rolename ";
// }
// if(role.getState()!=null&&!role.getState().equals("")){
// hql+=" and r.state = :state ";
// }
// hql += " order by r.roleid";
//
//
//
// Query query = session.createQuery(hql);
//
// if(role.getRolename()!=null&&!role.getRolename().equals("")){
// query.setString("rolename", "%"+role.getRolename()+"%");
// }
// if(role.getState()!=null&&!role.getState().equals("")){
// query.setString("state", role.getState());
// }
// String hql1 = "select count(*) from Roleinfo as r where r.roleid is not null ";
// if(role.getRolename()!=null&&!role.getRolename().equals("")){
// hql1+=" and r.rolename like :rolename ";
// }
// if(role.getState()!=null&&!role.getState().equals("")){
// hql1+=" and r.state = :state ";
// }
// hql += " order by r.roleid";
// Query query1 = session.createQuery(hql1);
//
// if(role.getRolename()!=null&&!role.getRolename().equals("")){
// query1.setString("rolename", "%"+role.getRolename()+"%");
// }
// if(role.getState()!=null&&!role.getState().equals("")){
// query1.setString("state", role.getState());
// }
// Integer num = (Integer) query1.uniqueResult();
// role.setTotalRows(num);
// List list = query.setFirstResult(role.getStartIndex()).setMaxResults(role.getPerPageRows()).list();
//// Criteria criteria = session.createCriteria(Roleinfo.class);
//// if(role.getRolename()!=null&&!role.getRolename().equals("")){
//// criteria.add(Expression.like("rolename", role.getRolename(),MatchMode.ANYWHERE));
//// }
//// if(role.getState()!=null&&!role.getState().equals("")){
//// criteria.add(Expression.eq("state", role.getState()));
//// }
//// Integer num = (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult();
//// role.setTotalRows(num);
//// List list = criteria.setFirstResult(role.getStartIndex()).setMaxResults(role.getPerPageRows()).list();
// role.setPageList(list);
// return role;
// }
//
// });
return pageInfoLookup( role ,new PageInfoQueryCallback(){
public void doInPageInfoString(PageInfoBuffer hql ) {
hql.append("from Roleinfo as r where roleid is not null ");
if(role.getRolename()!=null&&!role.getRolename().equals("")){
hql.append("and r.rolename like :rolename ");
}
if(role.getState()!=null&&!role.getState().equals("")){
hql.append("and r.state=:state ");
}
hql.append(" order by r.roleid");
}
public void doInPageInfoValues(PageInfoMapValues values) {
values.put("state", role.getState(),PageInfoQueryCallback.EQ);
values.put("rolename", role.getRolename(), PageInfoQueryCallback.LIKE);
}
});
}
/**
* 角色添加保存
*/
public void saveRoleinfo(Roleinfo role) {
this.getHibernateTemplate().save(role);
}
public Roleinfo getDetailRoleinfo(final Roleinfo role){
return (Roleinfo) this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(Roleinfo.class);
criteria.add(Expression.eq("roleid", role.getRoleid()));
return criteria.uniqueResult();
}
});
}
public void deleteRoleinfo(Roleinfo role) {
this.getHibernateTemplate().delete(role);
}
public int getRoleByName(final Roleinfo role) {
return (Integer) this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return session.createCriteria(Roleinfo.class).add(Expression.eq("rolename", role.getRolename())).setProjection(Projections.rowCount()).uniqueResult();
}
});
}
public int getHaveSameNameRole(final Roleinfo role) {
return (Integer) this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return session.createCriteria(Roleinfo.class).add(Expression.eq("rolename", role.getRolename())).add(Expression.not(Expression.eq("roleid", role.getRoleid()))).setProjection(Projections.rowCount()).uniqueResult();
}
});
}
public void updateRoleinfo(Roleinfo roleinfo) {
this.getHibernateTemplate().update(roleinfo);
}
public void deleteRoleAndMenuinfo(final Roleandmenu roleandmenu) {
this.getHibernateTemplate().delete(roleandmenu);
}
public void updateRoleState(final Roleinfo role) {
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("update Roleinfo set state=:state where roleid=:roleid");
query.setString("state", role.getState());
query.setString("roleid", role.getRoleid());
return query.executeUpdate();
}
});
}
/**
* 登陆用户根据帐户ID查询所有的角色信息
*/
public List getRoleinfoListByUserID(final Userinfo userinfo_temp) {
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("select new Roleinfo(r.roleid , r.rolename, r.state) from Roleinfo as r inner join r.userandroles as ur inner join ur.userinfo as u where u.userid=:userid");
query.setString("userid", userinfo_temp.getUserid());
return query.list();
}
});
}
public void saveRoleAndMenu(Roleandmenu roleandmenu) {
this.getHibernateTemplate().save(roleandmenu);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -