authdaohibernate.java

来自「飞机订票系统」· Java 代码 · 共 62 行

JAVA
62
字号
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 + =
减小字号Ctrl + -
显示快捷键?