Esempio n. 1
0
        //private const string SqlClient = "System.Data.SqlClient";
        //private const string OleDb = "System.Data.OleDb";
        //private const string OracleClient = "System.Data.OracleClient";
        //private const string SQLiteClient = "System.Data.SQLite";
        //private const string MySqlClient = "MySql.Data.MySqlClient";
        //private const string SybaseClient = "Sybase.Data.AseClient";
        //private const string PostgreClient = "System.Data.NpgSqlClient";
        //private const string TxtClient = "CYQ.Data.TxtClient";
        //private const string XmlClient = "CYQ.Data.XmlClient";
        //private const string XHtmlClient = "CYQ.Data.XHtmlClient";

        /// <summary>
        /// ¼òµ¥¹¤³§£¨Factory Method£©
        /// </summary>
        /// <param name="dbConn"></param>
        /// <returns></returns>
        public static DbBase CreateDal(string connNameOrString)
        {
            //ABCConn
            DbBase db = GetDbBaseBy(ConnObject.Create(connNameOrString));

            if (db.connObject.Master.ConnName != connNameOrString && connNameOrString.EndsWith("Conn"))//ÐèÒªÇл»ÅäÖá£
            {
                //Conn  A¿â
                //BConn  xxx ÕÒ²»µ½Ê±£¬ÕÒĬÈÏ¿â¡£
                DbResetResult result = db.ChangeDatabase(connNameOrString.Substring(0, connNameOrString.Length - 4));
                if (result == DbResetResult.Yes) // дÈ뻺´æ
                {
                    db.connObject.SaveToCache(connNameOrString);
                }
            }
            return(db);
        }
Esempio n. 2
0
        /// <summary>
        /// 简单工厂(Factory Method)
        /// </summary>
        /// <param name="dbConn"></param>
        /// <returns></returns>
        public static DbBase CreateDal(string dbConn)
        {
            DbBase db = GetDbBaseBy(GetConnObject(dbConn));

            if (db.connObject.Master.ConfigName != dbConn && dbConn.EndsWith("Conn"))//需要切换配置。
            {
                DbResetResult result = db.ChangeDatabase(dbConn.Substring(0, dbConn.Length - 4));
                if (result == DbResetResult.Yes) // 写入缓存
                {
                    if (!connDicCache.ContainsKey(dbConn))
                    {
                        connDicCache.Set(dbConn, db.connObject);
                    }
                }
            }
            return(db);
            //ConnEntity cEntity = GetConnString(dbConn);
            //DbBase db = GetDbBaseBy(cEntity.Conn, cEntity.ProviderName);
            //db.connObject = cEntity;
            //return db;
        }