示例#1
0
文件: DBFast.cs 项目: jiszen/cyqdata
        public static bool BeginTransation(string conn, IsolationLevel level)
        {
            string key = StaticTool.GetTransationKey(conn);

            if (!TransationKeys.ContainsKey(key))
            {
                TransationKeys.Add(key, level);
                return(true);
            }
            return(false);
        }
示例#2
0
文件: DBFast.cs 项目: jiszen/cyqdata
        /// <summary>
        /// 事务回滚
        /// </summary>
        public static bool RollBack(string conn)
        {
            string key = StaticTool.GetTransationKey(conn);

            TransationKeys.Remove(key);
            DalBase dal = DalCreate.Get(key);

            if (dal != null && dal.RollBack())
            {
                dal.Dispose();
                return(DalCreate.Remove(key));
            }
            return(false);
        }
示例#3
0
文件: DBFast.cs 项目: jiszen/cyqdata
        /// <summary>
        /// 提交事务
        /// </summary>
        public static bool EndTransation(string conn)
        {
            string key = StaticTool.GetTransationKey(conn);

            TransationKeys.Remove(key);
            DalBase dal = DalCreate.Get(key);

            if (dal != null && dal.EndTransaction())//如果事务回滚了,
            {
                dal.Dispose();
                return(DalCreate.Remove(key));
            }
            return(false);
        }
示例#4
0
        public void Dispose()
        {
            string key = StaticTool.GetTransationKey(UsingConnBean.ConnName);

            if (DBFast.HasTransation(key))
            {
                return;//全局事务由全局控制(全局事务会在移除key后重新调用)。
            }
            if (_con != null)
            {
                CloseCon();
                _con = null;
            }
            if (_com != null)
            {
                _com.Dispose();
                _com = null;
            }
            if (_watch != null)
            {
                _watch = null;
            }
        }
示例#5
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);
        }