Facade 层基类设计,通过实现模版方法设计模式和底层DBDataAccss类来实现业务层控制事务的功能。...

ExpandedBlockStart.gif ContractedBlock.gif /**/ ////
InBlock.gif
///
InBlock.gif
///    Copyright (C), 2002-2008, Murphy Corporation.
InBlock.gif
///    
InBlock.gif
///    FileName:        FacadeBase.cs
InBlock.gif
///    Author:            胡晓伟
InBlock.gif
///    Version:        beta
InBlock.gif
///    Description:    BizFacade Foundation Class : Basic Biz Function Class ..
InBlock.gif
///    
InBlock.gif
///                    
ExpandedBlockEnd.gif
////

None.gif using  System;
None.gif
using  System.Reflection;
None.gif
None.gif
using  COM.Makinfo.DataAccess;
None.gif
namespace  COM.Makinfo.Facade
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// FacadeBase 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public abstract class FacadeBase:IDisposable
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected DBAccess[] aryDBAccess;
InBlock.gif        
public FacadeBase()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设置同在一个事务中的DBAccess实例。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="aryDBAccess"></param>

InBlock.gif        protected void SetAryDBAccess(params DBAccess[] aryDBAccess)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.aryDBAccess = aryDBAccess;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 运行事务处理方法。
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="strMesthodeName">要运行的方法名。</param>
InBlock.gif        
/// <param name="paramerts">方法的参数。</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        protected object RunCooperation(string strMesthodeName,params object[] paramerts)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//Begin cooperation work.
InBlock.gif
                BeginCooperation();
InBlock.gif
InBlock.gif                MethodBase method    
= this.GetType().GetMethod(strMesthodeName,
InBlock.gif                    BindingFlags.Instance
|BindingFlags.NonPublic|BindingFlags.Public);
InBlock.gif                
object oResult        = method.Invoke(this,paramerts);
InBlock.gif
InBlock.gif                
//Commit.
InBlock.gif
                CommitCooperation();
InBlock.gif
InBlock.gif                
//Return value
InBlock.gif
                return oResult;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//Rollback.
InBlock.gif
                RollbackCooperation();
InBlock.gif                
throw ex;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 开始事务。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void BeginCooperation()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Begin cooperation work.
InBlock.gif
            DBAccess.BeginCooperation(aryDBAccess);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 提交事务。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void CommitCooperation()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Commit.
InBlock.gif
            DBAccess.CommitCooperation(aryDBAccess);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 回滚事务。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void RollbackCooperation()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Rollback.
InBlock.gif
            DBAccess.RollbackCooperation(aryDBAccess);
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IDisposable 成员#region IDisposable 成员
InBlock.gif
InBlock.gif        
public virtual void Dispose()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// TODO:  添加 FacadeBase.Dispose 实现
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/richardhu/archive/2006/07/25/459636.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值