2011-10-20 1 views

답변

2

나는이 필요한 방법을 노출하는 IDbProvider를 장식 데코레이터 패턴을 사용하여 수행했습니다

public class LongQueries : LongQueriesDecorator 
{ 
    public override void setCommandTimeout(IDbCommand cmd) 
    { 
     cmd.CommandTimeout = 1000; // here you can configure a value in the App.config 
    } 
} 

:

public abstract class LongQueriesDecorator : IDbProvider 
{ 
    protected IDbProvider _iDbProvider; 

    public void setDbProvider(IDbProvider iDbProvider) 
    { 
     this._iDbProvider = iDbProvider; 
    } 


    public abstract void setCommandTimeout(IDbCommand cmd); 

    // implement all IDbProvider methods calling _iDbProvider.METHOD 
    // ... 
    // except for 

    public IDbCommand CreateCommand() 
    { 
     if (_iDbProvider != null) 
     { 
      IDbCommand cmd = _iDbProvider.CreateCommand(); 
      // here you can call the delegate 
      setCommandTimeout(cmd); 
      return cmd; 
     } 
     else 
     { 
      return null; 
     } 
    } 
    // ... 
} 

그런 다음 추상 클래스를 실현을 마침내 매퍼를 만들 때 :

 _mapper = builder.Configure(sqlMapConfig); 
     LongQueries lq = new LongQueries(); 
     lq.setDbProvider(_mapper.DataSource.DbProvider); 
     _mapper.DataSource.DbProvider = lq; 
+0

감사합니다. 제 경우에는 제 ibatis가 다른 제 3의 api로 싸여 있으므로 이와 같이 사용자 정의 코드를 플러그인 할 수도 그렇지 않을 수도 있습니다. 건배, 셰인 – Shane