⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 authdaohibernate.java

📁 《JSP网站开发典型模块与实例精讲》一书光盘源码
💻 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);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -