Ejemplo n.º 1
0
 public static bool TryBeginTransaction(this WrappedConnection wrappedConnection)
 {
     if (wrappedConnection.CurrentTx is null && Transaction.Current is null)
     { // No current tx, no ambient tx
         wrappedConnection.BeginTransaction();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
 public static bool TryBeginTransaction(this WrappedConnection wrappedConnection)
 {
     if (wrappedConnection.CurrentTx == null)
     {
         wrappedConnection.BeginTransaction();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public void When_commit_transaction_is_cleared()
        {
            using (var wrappedConnection = new WrappedConnection(new SqliteConnection("Data Source=:memory:")))
            {
                var tx = wrappedConnection.BeginTransaction();
                wrappedConnection.Commit();

                Assert.Null(wrappedConnection.CurrentTx);
            }
        }
Ejemplo n.º 4
0
        public void BeginTransaction_opens_a_connection_and_returns_a_transaction()
        {
            var cnn = new SqliteConnection("Data Source=:memory:");

            using (var wrappedConnection = new WrappedConnection(cnn))
            {
                var tx = wrappedConnection.BeginTransaction();

                Assert.NotNull(wrappedConnection.CurrentTx);
                Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open);
            }

            Assert.True(cnn.State == ConnectionState.Closed);
        }
Ejemplo n.º 5
0
        public void BeginTransaction_opens_a_connection_and_returns_a_transaction()
        {
            var cnn = _pgContainer.CreateDbConnection();

            using (var wrappedConnection = new WrappedConnection(cnn))
            {
                var tx = wrappedConnection.BeginTransaction();

                Assert.NotNull(wrappedConnection.CurrentTx);
                Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open);
            }

            Assert.True(cnn.State == ConnectionState.Closed);
        }
Ejemplo n.º 6
0
        /// <inheritdoc cref="DbConnection.BeginDbTransaction(IsolationLevel)" />
        protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            if (Profiler == null || !Profiler.IsEnabled)
            {
                return(WrappedConnection.BeginTransaction(isolationLevel));
            }

            Profiler.OnStartingTransaction(this);

            var transaction = WrappedConnection.BeginTransaction(isolationLevel);

            Profiler.OnStartedTransaction(transaction);

            return(new AdoNetProfilerDbTransaction(transaction, WrappedConnection, Profiler));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Starts a database transaction.
        /// </summary>
        /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param>
        /// <returns>
        /// An object representing the new transaction.
        /// </returns>
        protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            switch (isolationLevel)
            {
            case IsolationLevel.Serializable:
                return(new JetTransaction(WrappedConnection.BeginTransaction(IsolationLevel.ReadCommitted), this));

            case IsolationLevel.Chaos:
            case IsolationLevel.ReadCommitted:
            case IsolationLevel.ReadUncommitted:
            case IsolationLevel.RepeatableRead:
            case IsolationLevel.Snapshot:
            case IsolationLevel.Unspecified:
            default:
                return(new JetTransaction(WrappedConnection.BeginTransaction(isolationLevel), this));
            }
        }
Ejemplo n.º 8
0
        ///// <summary>
        ///// Gets the <see cref="T:System.Data.Common.DbProviderFactory"/> for this <see cref="T:System.Data.Common.DbConnection"/>.
        ///// </summary>
        ///// <value></value>
        ///// <returns>
        ///// A <see cref="T:System.Data.Common.DbProviderFactory"/>.
        ///// </returns>
        //protected override DbProviderFactory DbProviderFactory
        //{
        //    get { return EFCachingProviderFactory.Instance; }
        //}

        /// <summary>
        /// Starts a database transaction.
        /// </summary>
        /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param>
        /// <returns>
        /// An object representing the new transaction.
        /// </returns>
        protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            return(new EFCachingTransaction(WrappedConnection.BeginTransaction(isolationLevel), this));
        }
Ejemplo n.º 9
0
 protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
 {
     return(WrappedConnection.BeginTransaction(isolationLevel));
 }