具体的 Data Access Logic 实现技术,作者感觉已没有必要多加讨
论,相信只要是有过 ADO.NET 开发经验的同志都比较清楚应该怎
么做,网上的资料也浩如烟海,非常齐全!
在此,就以作者自己的一段 Data Access Logic 代码来结束关于它的讨论:
代码 11 :使用 Data Access Logic 进行 Remoting 调用 – 1 ,基本操作
class ** CustomerDal_ORM ** : ** MyDal **
{
protected internal ** MyCustomer ** GetAllCustomers()
{
** MyCustomer ** cust = null ;
// 获取 Distributed Process 类型
string typeDist = GetDistributionType();
switch (typeDist)
{
case ** DistributionType ** .REMOTING :
{
// 通过 Cache Management 访问数据,第 2 参数是个 delegate ,
// 一旦 Cache 失效,就直接通过该 delegate 刷新数据
** ArrayList ** al = ** CacheManager ** .Current.GetCache(
GetCacheParam(), GetAllCustomers_Remoting_delegate);
... // 对 Remoting 返回的数据进行处理
break ;
}
default :
throw new ** Exception ** (
"Unsupported DistributionType: " +
typeDist + "!");
}
return cust;
}
}
}
上面的是基本访问代码,由于使用了 Cache Management ,所以
我们还需要一段真正可以访问数据的代码,一旦 Cache 失效,就可
以通过它来再次获得数据并刷新缓存!
需要特别注意的是:上面的代码使用了 C# 2.0 中的 Anonymous
Delegate 功能,如果在 Visual Studio .NET 2003 种进行编译,必须将
GetAllCustomers_Remoting_delegate 参数修改为如下方式:
new ** GetArrayList ** (GetAllCustomers_Remoting_delegate)
(这里的 ** GetArrayList ** 就是真正定义的 delegate 类型)