adoibatis 1.6.2用于.net查询超时



是否有办法为。net平台上的ibatis 1.6设置查询超时?

不幸的是,在这种情况下,升级不是我的选择。

干杯Shane

我使用装饰器模式来装饰IDbProvider以公开所需的方法:

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;
        }
    }
    // ...
}

然后实现抽象类:

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

最后,当你构建映射器时:

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

相关内容

  • 没有找到相关文章

最新更新