📄 linkcontroldao.java
字号:
package com.afuer.hib.dao.orgModel.Dao;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.common.tree.TreeUtil;
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.ILinkControlDao;
import com.afuer.hib.form.LinkControl;
import com.afuer.hib.form.OrgInfo;
import com.afuer.hib.form.RoleInfo;
import com.afuer.hib.form.UserAcl;
public class LinkControlDao extends HibernateDaoSupport implements
ILinkControlDao {
public Serializable saveLinkcontrol(LinkControl link)
throws DataAccessException {
// TODO Auto-generated method stub
return getHibernateTemplate().save(link);
}
public List find(LinkControl link) throws DataAccessException {
// TODO Auto-generated method stub
return find(link.getId());
}
public List find(final Integer 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 LinkControl where id=" + id);
return query.list();
}
});
}
public Serializable saveUserACL(UserAcl ua) throws DataAccessException {
return getHibernateTemplate().save(ua);
}
public List getRolesByLink(final Integer linkid)throws DataAccessException {
List temp = new ArrayList();
List list = getUserAclsbyLink(linkid);
Iterator it = list.iterator();
while (it.hasNext()) {
UserAcl ua = (UserAcl) it.next();
temp.add(getRoleInfo(ua.getRoleid()));
}
temp.addAll(getAllGlobalRoles());
return temp;
}
public List getUserAclsbyLink(final Integer linkid)throws DataAccessException
{
return(List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from UserAcl where linkid="
+ linkid);
return query.list();
}
});
}
public List getUserAclsbyLink(final Integer linkid,final Integer roleid)throws DataAccessException
{
return(List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from UserAcl where linkid="
+ linkid+" and roleid="+roleid );
return query.list();
}
});
}
//获得本联结自由角色列表
public List getFreeRoles(final Integer linkid)throws DataAccessException
{
List temp=new ArrayList();
List list=getAllOrgRoles() ;
Iterator it=list.iterator();
while(it.hasNext())
{
RoleInfo ri=(RoleInfo)it.next();
if(getUserAclsbyLink(linkid,ri.getId()).size()==0)
{
temp.add(ri);
}
}
return temp;
}
public List getAllGlobalRoles() throws DataAccessException {
// TODO Auto-generated method stub
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session.createQuery("from RoleInfo where scope='1' order by id");
return query.list();
}
});
}
public List getAllOrgRoles() throws DataAccessException {
// TODO Auto-generated method stub
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session.createQuery("from RoleInfo where scope='0' order by id ");
return query.list();
}
});
}
public RoleInfo getRoleInfo(final Integer id) throws DataAccessException {
// TODO Auto-generated method stub
return (RoleInfo) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from RoleInfo where id='" + id
+ "'");
return (RoleInfo) query.uniqueResult();
}
});
}
public List getSubListByParentid(final String parentid)
throws DataAccessException {
// TODO Auto-generated method stub
return (List) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("from LinkControl where parentid='"
+ parentid + "'");
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 LinkControl order by id");
return query.list();
}
});
}
public LinkControl get(final Integer id) throws DataAccessException {
// TODO Auto-generated method stub
return (LinkControl) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
LinkControl linkcontrol = (LinkControl) session
.createQuery("from LinkControl where id=" + id)
.uniqueResult();
return linkcontrol;
}
});
}
public void UpdateLinkControl(LinkControl link) throws DataAccessException {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(link);
}
public void delSubLinkTree(final Integer id) throws DataAccessException {
List subList = getSubListByParentid(id + "");
LinkControl lt = get(id);
lt = get(new Integer(lt.getParentid()));
if (lt.getChildren() != null) {
lt.setChildren(new Integer(lt.getChildren().intValue() - 1));
}
UpdateLinkControl(lt);
Iterator it = subList.iterator();
while (it.hasNext()) {
LinkControl lc = (LinkControl) it.next();
delSubLinkTree(lc.getId());
}
deleteLinkInfo(id);
}
public void deleteUserAcl(final Integer roleid,final Integer linkid) throws DataAccessException {
// TODO Auto-generated method stub
System.out.println("Link delete.............................");
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("delete UserAcl where roleid ="+roleid+" and linkid="+linkid);
query.executeUpdate();
return null;
}
});
}
public void deleteLinkInfo(final Integer id) throws DataAccessException {
// TODO Auto-generated method stub
System.out.println("Link delete.............................");
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
Query query = session
.createQuery("delete LinkControl where id =:Rid");
query.setInteger("Rid", id.intValue());
query.executeUpdate();
query = session
.createQuery("delete UserAcl where linkid=:Rid");
query.setInteger("Rid", id.intValue());
query.executeUpdate();
return null;
}
});
}
public void deleteLinkControl(LinkControl link) throws DataAccessException {
// TODO Auto-generated method stub
this.getHibernateTemplate().delete(link);
}
public String getLinkTree() throws DataAccessException {
// 定义根节点
String rootid = "1";
String url = "orgModel/getLinkInfo.do";
// System.err.println("dddddddddddd:"+findAll().size());
return TreeUtil.TreeStr(findAll(), rootid, url);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -