示例#1
0
        public bool IsOpened(IPhysicalConnectionFactory fact)
        {
            string key = fact.GetConnectionKey();

            lock (m_connCache)
            {
                var item = m_connCache[key];
                return(item.Connection != null && item.Connection.IsOpened);
            }
        }
示例#2
0
        public void Close(IPhysicalConnectionFactory fact)
        {
            string key = fact.GetConnectionKey();

            lock (m_connCache)
            {
                if (!m_connCache.ContainsKey(key))
                {
                    throw new InternalError("DAE-00029 Connection key not found");
                }
                m_connCache[key].RefCount--;
                if (m_connCache[key].RefCount <= 0 && !m_connCache[key].KeepAlive)
                {
                    Async.SafeClose(m_connCache[key].Connection);
                }
            }
        }
示例#3
0
        private IPhysicalConnection _OpenCore(IPhysicalConnectionFactory fact, bool keepAlive, bool incref, bool open)
        {
            if (fact == null)
            {
                return(null);
            }
            string key = fact.GetConnectionKey();
            IPhysicalConnection res;

            lock (m_connCache)
            {
                if (!m_connCache.ContainsKey(key))
                {
                    var item = new CacheItem();
                    item.Connection = fact.CreateConnection();
                    if (Cache != null)
                    {
                        // use shared cache
                        item.Connection.Cache = Cache.Connection(key);
                    }
                    item.Connection.Owner = this;
                    m_connCache[key]      = item;
                }
                if (incref)
                {
                    m_connCache[key].RefCount++;
                }
                if (keepAlive)
                {
                    m_connCache[key].KeepAlive = true;
                }
                res = m_connCache[key].Connection;
            }
            if (open)
            {
                Async.SafeOpen(res);
            }
            return(res);
        }