Example #1
0
        private static DalBase CreateDalBase(string connNameOrString)
        {
            //ABCConn
            DalBase db = GetDalBaseBy(ConnObject.Create(connNameOrString));

            if (!string.IsNullOrEmpty(connNameOrString) && db.ConnObj.Master.ConnName.ToLower() != connNameOrString.ToLower() && connNameOrString.EndsWith("Conn"))//需要切换配置。
            {
                //Conn  A库
                //BConn  xxx 找不到时,找默认库。
                DBResetResult result = db.ChangeDatabase(connNameOrString.Substring(0, connNameOrString.Length - 4));
                if (result == DBResetResult.Yes) // 写入缓存
                {
                    db.ConnObj.SaveToCache(connNameOrString);
                }
            }
            return(db);
        }
Example #2
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>
        public static DalBase CreateDal(string connNameOrString)
        {
            //ABCConn
            DalBase db = GetDalBaseBy(ConnObject.Create(connNameOrString));

            if (db.ConnObj.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.ConnObj.SaveToCache(connNameOrString);
                }
            }
            return(db);
        }
Example #3
0
 /// <summary>
 /// Dispose
 /// <para>释放资源</para>
 /// </summary>
 public void Dispose()
 {
     hasDisposed = true;
     if (dalHelper != null)
     {
         if (!dalHelper.IsOnExceptionEventNull)
         {
             dalHelper.OnExceptionEvent -= new DalBase.OnException(helper_OnExceptionEvent);
         }
         _debugInfo = dalHelper.DebugInfo.ToString();
         dalHelper.Dispose();
         dalHelper = null;
     }
     if (_noSqlCommand != null)
     {
         _noSqlCommand.Dispose();
     }
 }
Example #4
0
        /// <summary>
        /// 简单工厂(Factory Method)
        /// </summary>
        public static DalBase CreateDal(string connNameOrString)
        {
            string key = StaticTool.GetTransationKey(connNameOrString);
            //检测是否开启了全局事务;
            bool isTrans = DBFast.HasTransation(key);

            if (isTrans)
            {
                if (dalBaseDic.ContainsKey(key))
                {
                    return(dalBaseDic[key]);
                }
            }
            DalBase dal = CreateDalBase(connNameOrString);

            if (isTrans)
            {
                dal.TranLevel   = DBFast.GetTransationLevel(key);
                dal.IsOpenTrans = true;
                dalBaseDic.Add(key, dal);
            }
            return(dal);
        }
Example #5
0
 private void Init(object procNameOrSql, string conn, bool isClearPara)
 {
     #region 分析是Sql或者存储过程
     if (procNameOrSql != null)
     {
         if (string.IsNullOrEmpty(conn))
         {
             if (procNameOrSql is Enum)
             {
                 conn = CrossDB.GetConnByEnum(procNameOrSql as Enum);
             }
             if (string.IsNullOrEmpty(conn) && !string.IsNullOrEmpty(ConnName))
             {
                 conn = ConnName;
             }
         }
         if (procNameOrSql is String)
         {
             string fixName;
             conn = CrossDB.GetConn(procNameOrSql.ToString(), out fixName, conn);
         }
         _procName = procNameOrSql.ToString().Trim();
         _isProc   = _procName.IndexOf(' ') == -1;//不包含空格
         if (string.IsNullOrEmpty(conn) && dalHelper == null)
         {
             conn = AppConfig.DB.DefaultConn;
         }
     }
     #endregion
     DalBase dalBase = null;
     if (conn != null && dalHelper == null)
     {
         dalBase = DalCreate.CreateDal(conn);
     }
     SetDalBase(dalBase, isClearPara);
 }
Example #6
0
 internal MProc(DalBase dalBase)
 {
     _procName = string.Empty;
     SetDalBase(dalBase, false);
 }