예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <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;
     }
 }
예제 #4
0
 /// <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;
     }
 }
예제 #5
0
 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;
     }
 }
예제 #6
0
 /// <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));
 }
예제 #7
0
파일: TransScope.cs 프로젝트: ywscr/Vulcan
        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;
            }
        }
예제 #8
0
파일: TransScope.cs 프로젝트: ywscr/Vulcan
 /// <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;
 }
예제 #9
0
 public TransScope GetTransScope(TransScopeOption option = TransScopeOption.Required)
 {
     return(new TransScope(_constr, option));
 }
예제 #10
0
 /// <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));
 }