Guushuuse .NET

领域驱动设计==哲学

导航

ASP.NET&Spring.NET&NHibernate最佳实践(十一)——第4章权限子系统(4)

4.3. 权限子系统数据访问层(Dao)
应用程序数据访问接口(IApplicationDao.cs)
using System;
using Guushuuse.SalaryPrj.Security.DomainModel;
using System.Collections;

namespace Guushuuse.SalaryPrj.Security.Dao
{
    
/// <summary>
    
/// 应用程序数据访问接口
    
/// </summary>

    public interface IApplicationDao
    
{
        
void CreateApplication(Application application);
        
void DeleteApplication(Application application);
        IList GetAllApplications();
        Application GetApplication(
int applicationID);
        Application GetApplication(
string applicationName);
        
void UpdateApplication(Application application);
    }

}


应用程序数据访问类(ApplicationDao.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate.Support;
using Guushuuse.SalaryPrj.Security.DomainModel;
using System.Collections;
using Spring.Transaction.Interceptor;
using Spring.Dao.Support;

namespace Guushuuse.SalaryPrj.Security.Dao
{
    
/// <summary>
    
/// 应用程序数据访问类
    
/// </summary>

    public class ApplicationDao : HibernateDaoSupport, IApplicationDao
    
{
        
public ApplicationDao()
        
{

        }


        [Transaction(ReadOnly 
= false)]
        
public void CreateApplication(Application application)
        
{
            HibernateTemplate.Save(application);
        }


        [Transaction(ReadOnly 
= false)]
        
public void UpdateApplication(Application application)
        
{
            HibernateTemplate.Update(application);
        }


        [Transaction(ReadOnly 
= false)]
        
public void DeleteApplication(Application application)
        
{
            HibernateTemplate.Delete(application);
        }


        
public IList GetAllApplications()
        
{
            
return HibernateTemplate.LoadAll(typeof(Application));
        }


        
public Application GetApplication(int applicationID)
        
{
            
return (Application)HibernateTemplate.Get(typeof(Application), applicationID);
        }


        
public Application GetApplication(string applicationName)
        
{
            
string hql = " from Application application where application.Name = ?";

            IList applications 
= HibernateTemplate.Find(hql, new object[] { applicationName });

            
if (applications.Count > 0)
            
{
                
return (Application)DataAccessUtils.RequiredUniqueResultSet(applications);
            }

            
else
            
{
                
return null;
            }

        }

    }

}

posted on 2008-05-17 14:37  guushuuse  阅读(852)  评论(1编辑  收藏  举报