熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

數據庫連接池Data Connection Framework

2022-06-13   來源: .NET編程 

  數據庫連接池Data Connection Framework具備Connection pooling機制能管理不同的 Connection並通過池對象工廠去PoolObjectFactory去創建數據連接池(可參考對象工廠創建 Singleton ObjectSingleCall ObjectPool Object )

  連接池企業應用組件圖如下

  
主要文件代碼

  /// <summary>
    /// 連接池上下文
    /// </summary>
    public sealed class ConnectionPoolContext : IDisposable
    {
        /// <summary>
        /// 池對象工廠
        /// </summary>
        private PoolObjectFactory _factory;
        /// <summary>
        /// 默認連接字符
        /// </summary>
        private string _defaultConnectionString;
        /// <summary>
        /// 工廠名稱
        /// </summary>
        private string _factoryName;
        /// <summary>
        /// 類型
        /// </summary>
        private Type _factoryType;
        /// <summary>
        /// SQL狀態倉庫
        /// </summary>
        private SqlStatementRepository _statementRepository;

        /// <summary>
        /// 連接池
        /// </summary>
        private static Dictionary<string ConnectionPoolContext> _instances = new Dictionary<string ConnectionPoolContext>();
        /// <summary>
        /// 默認連接字符屬性
        /// </summary>
        public string DefaultConnectionString
        {
            get
            {
                return _defaultConnectionString;
            }
            set
            {
                _defaultConnectionString = value;
            }
        }
        /// <summary>
        /// 工廠名
        /// </summary>
        public string FactoryName
        {
            get
            {
                return _factoryName;
            }
            set
            {
                _factoryName = value;
            }
        }
        /// <summary>
        /// SQL狀態倉庫屬性
        /// </summary>
        public SqlStatementRepository StatementRepository
        {
            get
            {
                if (_statementRepository == null)
                    _statementRepository = new SqlStatementRepository();
                return _statementRepository;
            }
        }
        /// <summary>
        /// 對象工廠模式
        /// </summary>
        internal PoolObjectFactory Factory
        {
            get
            {
                return _factory;
            }
            set
            {
                _factory = value;
            }
        }
        /// <summary>
        /// 實例化一個連接池
        /// </summary>
        /// <param name=id></param>
        /// <returns></returns>
        public static ConnectionPoolContext Instance(string id)
        {


From:http://tw.wingwit.com/Article/program/net/201311/13457.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.