📄 orginfodao.java
字号:
package com.afuer.hib.dao.orgModel.Dao;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.afuer.hib.dao.orgModel.Idao.IOrgInfoDao;
import com.afuer.hib.form.ITreeForm;
import com.afuer.hib.form.OrgInfo;
import com.afuer.hib.form.Roleorg;
import com.afuer.hib.form.Userrole;
import com.common.util.StringTool;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class OrgInfoDao extends HibernateDaoSupport implements IOrgInfoDao {
private static final Log log = LogFactory.getLog(RoleInfoDao.class);
public List find(OrgInfo OI) throws DataAccessException {
// TODO Auto-generated method stub
return find(OI.getId()+"");
}
public String getOrgTree() {
//定义的根节点
String ot = "1";
ot=TreeStr(findAll(),ot);
return ot;
}
public Serializable saveOrgInfo(OrgInfo ro) throws DataAccessException {
// TODO Auto-generated method stub
return this.getHibernateTemplate().save(ro);
}
public void UpdateOrgInfo(OrgInfo oi) throws DataAccessException {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(oi);
}
// 待用
public List find(final String id) throws DataAccessException {
// TODO Auto-generated method stub
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session.createQuery("from OrgInfo where parentid='"+id+"'");
return query.list();
}
});
}
public List findAll() throws DataAccessException {
// TODO Auto-generated method stub
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from OrgInfo order by id ");
return query.list();
}
});
}
public OrgInfo loadOrginfo(final Integer id) throws DataAccessException {
// TODO Auto-generated method stub
return (OrgInfo) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from OrgInfo where id=" + id);
return (OrgInfo) query.uniqueResult();
}
});
}
public void delSubOrgTree(final Integer id)throws DataAccessException
{
List subList=find(id+"");
OrgInfo or=loadOrginfo(id);
or=loadOrginfo(new Integer(or.getParentid()));
if(or.getChildren()!=null)
{
or.setChildren(new Integer(or.getChildren().intValue()-1));
}
UpdateOrgInfo(or);
Iterator it=subList.iterator();
while(it.hasNext())
{
OrgInfo oi=(OrgInfo)it.next();
delSubOrgTree(oi.getId());
}
deleteOrgInfo(id);
}
public void deleteOrgInfo(final Integer id) throws DataAccessException {
// TODO Auto-generated method stub
log.error("org delete.............................");
//删除下面的用户和角色(注释掉了)
//deleteRolesAndUsersUnderOrg(id);
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("delete OrgInfo where id =:Rid");
query.setInteger("Rid", id.intValue());
query.executeUpdate();
return null;
}
});
//删除Roleorg中的连接
deleteRoleOrg(id);
}
//以下删除函数没用到。。。。。。。。。。。。。。。。。。
public void deleteRolesAndUsersUnderOrg(final Integer orgid)
{
//查找所有的角色
List list=(List)this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from Roleorg where orgid=" + orgid);
return (List) query.list();
}
});
//查找角色和用户来删除
Iterator it=list.iterator();
while(it.hasNext())
{
Roleorg ro=(Roleorg)it.next();
deleteUserrole(ro.getRoleid());
}
}
public void deleteRoleOrg(final Integer orgid) throws DataAccessException {
// TODO Auto-generated method stub
log.warn("Roleorg delete.............................");
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("delete Roleorg where orgid =:Rid");
query.setInteger("Rid", orgid.intValue());
query.executeUpdate();
return null;
}
});
}
public void deleteUserrole(final Integer orgid) throws DataAccessException {
// TODO Auto-generated method stub
log.warn("Userrole delete.............................");
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("delete Userrole where roleid =:Rid");
query.setInteger("Rid", orgid.intValue());
query.executeUpdate();
return null;
}
});
}
List findUsersByRole(final Integer roleid)
{
return(List)this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from Userrole where roleid=" + roleid);
return (List) query.list();
}
});
}
public String TreeStr(List list,String parentid) {
String str = "";
Iterator it = list.iterator();
while (it.hasNext()) {
ITreeForm tf = (ITreeForm) it.next();
if(parentid.equals(tf.getParentid()))
{
str += "<FuzerTree text=\"" + StringTool.InitStr(tf.getName())
+ "\" open=\"false\" href=\"/orgModel/getOrgInfo.do\""
+ " treeId=\"" + tf.getId() + "\">";
if(tf.getChildren()!=null)
{
if(tf.getId().intValue()!=0)
{
str+=TreeStr(list,tf.getId().toString());
}
}
str+="</FuzerTree>";
}
}
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -