Guushuuse .NET

专注于ASP.NET 2.0、ASP.NET AJAX、Spring.NET、NHiberbate技术

博客园 首页 新随笔 联系 订阅 管理
  41 Posts :: 0 Stories :: 92 Comments :: 18 Trackbacks
角色数据访问接口(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;
            }

        }

    }

}

posted on 2008-05-17 15:59 guushuuse 阅读(181) 评论(1)  编辑 收藏 所属分类: ASP.NET&Spring.NET&NHibernate最佳实践

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-05-17 16:01 编辑过


相关链接: