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); }
/// <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); }
/// <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); }
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; } }
/// <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); }