ASP.NET&Spring.NET&NHibernate最佳實務(十二)——第4章許可權子系統(5)

來源:互聯網
上載者:User
角色資料提供者(IRoleDao.cs)using System;
using Guushuuse.SalaryPrj.Security.DomainModel;
using System.Collections;

namespace Guushuuse.SalaryPrj.Security.Dao
{
    /**//// <summary>
    /// 角色資料提供者
    /// </summary>
    public interface IRoleDao
    {
        void CreateRole(Role role);
        void DeleteRole(Role role);
        IList GetAllRoles();
        Role GetRole(int roleID);
        Role GetRole(Application application, string roleName);
        IList GetRoles(Application application);
        void UpdateRole(Role role);
    }
}

角色資料訪問類(RoleDao.cs)using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate.Support;
using Spring.Transaction.Interceptor;
using Guushuuse.SalaryPrj.Security.DomainModel;
using System.Collections;
using Spring.Dao.Support;

namespace Guushuuse.SalaryPrj.Security.Dao
{
    /**//// <summary>
    /// 角色資料訪問類
    /// </summary>
    public class RoleDao : HibernateDaoSupport, IRoleDao
    {
        public RoleDao()
        {

        }

        [Transaction(ReadOnly = false)]
        public void CreateRole(Role role)
        {
            HibernateTemplate.Save(role);
        }

        [Transaction(ReadOnly = false)]
        public void UpdateRole(Role role)
        {
            HibernateTemplate.Update(role);
        }

        [Transaction(ReadOnly = false)]
        public void DeleteRole(Role role)
        {
            HibernateTemplate.Delete(role);
        }

        public IList GetAllRoles()
        {
            return HibernateTemplate.LoadAll(typeof(Role));
        }

        public IList GetRoles(Application application)
        {
            string hql = " from Role r where r.Application = ?";

            return HibernateTemplate.Find(hql, new object[] { application });
        }

        public Role GetRole(int roleID)
        {
            return (Role)HibernateTemplate.Get(typeof(Role), roleID);
        }

        public Role GetRole(Application application, string roleName)
        {
            string hql = " from Role role where role.Application = ? and role.Name = ?";

            IList roles = HibernateTemplate.Find(hql, new object[] { application, roleName });

            if (roles.Count > 0)
            {
                return (Role)DataAccessUtils.RequiredUniqueResultSet(roles);
            }
            else
            {
                return null;
            }
        }
    }
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.