【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“AuthDAOHibernate.java”一文,供大家参考学习!
package org.appfuse.dao.hibernate;
import java.util.List;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.appfuse.dao.*;
import org.appfuse.model.RoleAuth;
import org.appfuse.model.Auth;
/**
* @author user
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class AuthDAOHibernate
extends BaseDAOHibernate
implements AuthDAO {
public Auth getAuth(int authid) {
Auth auth = (Auth) getHibernateTemplate().get(Auth.class,
new Integer(authid));
if (auth == null) {
throw new ObjectRetrievalFailureException(Auth.class,
new Integer(authid));
}
return auth;
}
public void saveAuth(final Auth moduleFunction) {
getHibernateTemplate().saveOrUpdate(moduleFunction);
getHibernateTemplate().flush();
}
public Auth getAuth(int moduleid, int functionid) {
List list = getHibernateTemplate()
.find("from Auth a where a.functionid = " + functionid +
" and a.moduleid = " + moduleid);
if (list != null && list.size() > 0) {
return (Auth) list.get(0);
}
return null;
}
//删除Auth的同时,要删除RoleAuth
public void removeAuth(Auth auth) {
auth = getAuth(auth.getModuleid(), auth.getFunctionid());
List roleAuths = getHibernateTemplate().find(
"select a from RoleAuth a where a.authid=" + auth.getAuthid());
for (int j = 0; j < roleAuths.size(); j++) {
RoleAuth roleAuth = (RoleAuth) roleAuths.get(j);
getHibernateTemplate().delete(roleAuth);
}
getHibernateTemplate().delete(auth);
}
}
上一篇:
AuthDAO.java
下一篇:
餐饮管理系统