【问题标题】:ibatis 1.6.2 for .Net query timeout.Net 查询超时的 ibatis 1.6.2
【发布时间】:2011-10-20 08:34:58
【问题描述】:

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

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

干杯 谢恩

【问题讨论】:

    标签: .net ado.net timeout ibatis


    【解决方案1】:

    我已经使用装饰器模式完成了这项工作,该模式装饰了 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;
    

    【讨论】:

    • 谢谢,我会调查的。在我的情况下,我的 ibatis 是由另一个第三方 api 包装的,所以我可能会也可能不会像这样插入自定义代码。干杯,肖恩
    猜你喜欢
    • 2011-04-21
    • 1970-01-01
    • 2011-03-15
    • 2011-12-02
    • 2011-03-08
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多