ibatis 1.6.2 for .Net查询超时

时间:2011-10-20 08:34:58

标签: .net ado.net timeout ibatis

有没有办法在.net平台上设置ibatis 1.6的查询超时?

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

干杯 沙恩

1 个答案:

答案 0 :(得分:2)

我使用装饰器模式来完成此操作,该模式装饰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;