/// <summary> /// 构造函数 /// </summary> /// <param name="conn"></param> /// <param name="parent"></param> /// <param name="il"></param> /// <param name="option"></param> /// <param name="loggerFactory"></param> /// <param name="connectionId"></param> public TransScope(IDbConnection conn, TransScope parent, IsolationLevel il = IsolationLevel.ReadCommitted, TransScopeOption option = TransScopeOption.Required, ILoggerFactory loggerFactory = null, string connectionId = null) { if (loggerFactory != null) { _LoggerFactory = loggerFactory; _Logger = loggerFactory.CreateLogger <TransScope>(); } Guid = System.Guid.NewGuid().ToString(); Parent = parent; Option = option; _Conn = conn; _ConnectionId = connectionId; //当前事务为内嵌事务 if (Parent != null && Option == TransScopeOption.Required) { _Trans = Parent.Trans; _State = Parent.State; LogDebug("Create Nest TransScope. DbConnectionWrap.Guid={0}, TransScope.Guid={1}", _ConnectionId, Guid); } else { LogDebug("Create Root TransScope. DbConnectionWrap.Guid={0}, TransScope.Guid={1}", _ConnectionId, Guid); } _IsolationLevel = il; }
/// <summary> /// 开启事务 /// </summary> /// <param name="option"></param> /// <param name="il"></param> /// <returns></returns> public TransScope TransScope(TransScopeOption option = TransScopeOption.Required, IsolationLevel il = IsolationLevel.ReadCommitted) { var conn = CreateConnectionWrap(option == TransScopeOption.RequireNew); RegistTransScopeConnection(conn); var scope = new TransScope(conn, conn.TransScope, il, option, LoggerFactory, conn.Guid); conn.TransScope = scope; scope.OnDisposed += TransScope_OnDisposed; return(scope); }
/// <summary> /// Initializes a new instance of the <see cref="TransScope"/> class. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="option">The option.</param> public TransScope(string connectionString, TransScopeOption option) { _connectionManager = ConnectionManager.GetManager(connectionString); if (!_connectionManager.IsExistDbTransaction() || option == TransScopeOption.RequiresNew) { _tran = _connectionManager.BeginTransaction(); _beginTransactionIsInCurrentTransScope = true; } else { _tran = _connectionManager.Transaction; } }
public DBTransScope(string connectionStrings, ORMDBType dbTyp, TransScopeOption option) { //如果有多数据库,再开放个构造函数 传递数据库连接字符串 _connectionManager = ConnectionManager.GetManager(connectionStrings, dbTyp); if (!_connectionManager.IsExistDbTransaction() || option == TransScopeOption.RequiresNew) { _tran = _connectionManager.BeginTransaction(); _beginTransactionIsInCurrentTransScope = true; } else { _tran = _connectionManager.Transaction; } }
/// <summary> /// 开启一个事务 /// </summary> /// <param name="option"></param> /// <returns></returns> public TransScope BeginTransScope(TransScopeOption option = TransScopeOption.Required) { return(new TransScope(this._mgr, this._dbFactory, this._conStr, option)); }
public TransScope(IConnectionManagerFactory mgr, IConnectionFactory factory, string connectionString, TransScopeOption option = TransScopeOption.Required) { _connectionManager = factory == null? mgr.GetConnectionManager(connectionString) : mgr.GetConnectionManager(factory, connectionString); if (!_connectionManager.IsExistDbTransaction() || option == TransScopeOption.RequiresNew) { _tran = _connectionManager.BeginTransaction(); _beginTransactionIsInCurrentTransScope = true; } else { _tran = _connectionManager.Transaction; } }
/// <summary> /// Initializes a new instance of the <see cref="TransScope"/> class. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="option">The option.</param> public TransScope(IConnectionManagerFactory mgr, string connectionString, TransScopeOption option = TransScopeOption.Required) : this(mgr, null, connectionString, option) { _option = option; }
public TransScope GetTransScope(TransScopeOption option = TransScopeOption.Required) { return(new TransScope(_constr, option)); }
/// <summary> /// 开启一个事务, /// using(var transScope=BeginTransScope()) /// {...; /// transScope.Commit(); /// } /// </summary> /// <param name="scopeOption"></param> /// <returns></returns> public IDBTransScope BeginTransScope(TransScopeOption scopeOption = TransScopeOption.Required) { return(new DBTransScope(ConnectionStrings, this.GetORMDBType(), scopeOption)); }