📄 functiondaohibernate.java
字号:
package org.appfuse.dao.hibernate;
import java.util.List;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.appfuse.dao.*;
import org.appfuse.model.Function;
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 FunctionDAOHibernate
extends BaseDAOHibernate
implements FunctionDAO {
public Function getFunction(int functionid) throws AppDAOException {
Function function = (Function) getHibernateTemplate().get(Function.class,
new Integer(functionid));
if (function == null) {
throw new ObjectRetrievalFailureException(Function.class,
new Integer(functionid));
}
return function;
}
public List getFunctions(Function function) throws AppDAOException {
return getHibernateTemplate().find(
"from Function");
}
public void saveFunction(final Function function) throws AppDAOException {
getHibernateTemplate().saveOrUpdate(function);
getHibernateTemplate().flush();
}
//删除功能的同时,要删除权限表、角色权限表中对应的行
public void removeFunction(int functionid) throws AppDAOException {
Function function = getFunction(functionid);
removeAuth(function);
getHibernateTemplate().delete(function);
}
private void removeAuth(Function function) throws AppDAOException {
List list = getHibernateTemplate().find("select a from Auth a where a.functionid=" + function.getFunctionid());
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 void removeRoleAuth(Function function) throws AppDAOException {
// List list = getHibernateTemplate().find("select a from Auth a where a.functionid=" + function.getFunctionid());
// for(int i = 0; i < list.size(); i++){
// Auth auth = (Auth)list.get(i);
// getHibernateTemplate().clear();
// 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);
// }
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -