Exemplo n.º 1
0
        public ConnectionManager GetConnectionManager(IConnectionFactory factory, string constr)
        {
            ConnectionManager mgr = null;

            if (!_ctxStorage.ContainsKey(constr))
            {
                lock (_lock)
                {
                    if (!_ctxStorage.ContainsKey(constr))
                    {
                        // 创建一个新的连接 并缓存起来
                        mgr = new ConnectionManager(factory ?? _defautFactory, constr, _ctxStorage);
                        _ctxStorage.Set(constr, mgr);
                    }
                }
                if (mgr != null)
                {
                    mgr.AddRef();
                    return(mgr);
                }
            }

            mgr = (ConnectionManager)_ctxStorage.Get(constr);
            mgr.AddRef();
            return(mgr);
        }