📄 moduledaohibernate.java
字号:
/*
* Created on 2006-2-3
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.appfuse.dao.hibernate;
import java.util.List;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.appfuse.dao.ModuleDAO;
import org.appfuse.model.Module;
import org.appfuse.util.exception.AppDAOException;
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 ModuleDAOHibernate
extends BaseDAOHibernate
implements ModuleDAO {
public Module getModule(int moduleid) throws AppDAOException {
Module module = (Module) getHibernateTemplate().get(Module.class,
new Integer(moduleid));
if (module == null) {
throw new ObjectRetrievalFailureException(Module.class,
new Integer(moduleid));
}
return module;
}
public List getModules(Module module) throws AppDAOException {
return getHibernateTemplate().find(
"from Module");
}
public List getFunctions(int moduleid) throws AppDAOException {
// List list = getHibernateTemplate().find(
// "select c from Auth a, Module b, Function c" +
// " where a.moduleid = ? and a.moduleid = b.moduleid and " +
// " a.functionid=c.functionid ",
// new Integer(moduleid));
// return list;
List list = getHibernateTemplate().find(
"select b from Auth a, Function b" +
" where a.moduleid = ? and a.functionid = b.functionid ",
new Integer(moduleid));
return list;
}
public void saveModule(final Module module) throws AppDAOException {
getHibernateTemplate().saveOrUpdate(module);
getHibernateTemplate().flush();
}
//删除一个模块的同时要删除RoleAuth、Auth表的对应的行
public void removeModule(int moduleid) throws AppDAOException {
removeAuth(moduleid);
Module module = getModule(moduleid);
getHibernateTemplate().delete(module);
}
private void removeAuth(int moduleid) throws AppDAOException {
List list = getHibernateTemplate().find("select a from Auth a where a.moduleid=" + moduleid);
for(int i = 0; i < list.size(); i++){
Auth auth = (Auth)list.get(i);
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);
}
}
//
// private List getRoleAuth(int moduleid) throws AppDAOException {
// return getHibernateTemplate().find(
// "select a from RoleAuth a, Auth b where a.authid = b.authid and b.moduleid = " +
// moduleid);
// }
//
// private void removeRoleAuth(int moduleid) throws AppDAOException {
// List list = getRoleAuth(moduleid);
// for (int i = 0; i < list.size(); i++) {
// RoleAuth roleAuth = (RoleAuth) list.get(i);
// getHibernateTemplate().delete(roleAuth);
// }
// }
//
// private void removeAuth(int moduleid) throws AppDAOException {
// List list = getHibernateTemplate().find(
// "select a from Auth a where a.moduleid = " + moduleid);
// for (int i = 0; i < list.size(); i++) {
// Auth auth = (Auth) list.get(i);
// getHibernateTemplate().delete(auth);
// }
//
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -