예제 #1
0
        public void ExternalTransactionTimeout()
        {
            TestDatabase database = new TestDatabase();

            CommittableTransaction external = new CommittableTransaction(TimeSpan.FromMilliseconds(50));

            NMemory.Transactions.Transaction transaction = NMemory.Transactions.Transaction.Create(external);

            database.Groups.Insert(new Group {
                Name = "Group1"
            }, transaction);
            Thread.Sleep(1000);
            database.Groups.Insert(new Group {
                Name = "Group2"
            }, transaction);
        }
예제 #2
0
        public void ExternalTransactionRollback()
        {
            TestDatabase database = new TestDatabase();

            CommittableTransaction external = new CommittableTransaction();

            NMemory.Transactions.Transaction transaction = NMemory.Transactions.Transaction.Create(external);

            database.Members.Insert(new Member {
                Id = "A"
            }, transaction);
            external.Rollback();

            Assert.AreEqual(database.Members.Count, 0);
            Assert.IsFalse(database.Members.Any(m => m.Id == "A"));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="EffortTransaction" /> class.
        /// </summary>
        /// <param name="connection">
        ///     The <see cref="EffortTransaction" /> object.
        /// </param>
        /// <param name="isolationLevel">
        ///     The isolation level.
        /// </param>
        /// <exception cref="System.InvalidOperationException">
        ///     Ambient transaction is already set.
        /// </exception>
        public EffortTransaction(
            EffortConnection connection,
            System.Data.IsolationLevel isolationLevel)
        {
            if (System.Transactions.Transaction.Current != null)
            {
                throw new InvalidOperationException("Ambient transaction is already set.");
            }

            this.connection     = connection;
            this.isolationLevel = isolationLevel;

            // Initialize new ambient transaction
            System.Transactions.TransactionOptions options =
                new System.Transactions.TransactionOptions();

            options.IsolationLevel = TranslateIsolationLevel(isolationLevel);
            options.Timeout        = new TimeSpan(0, 0, connection.ConnectionTimeout);

            this.systemTransaction = new System.Transactions.CommittableTransaction(options);

            this.transaction = NMemory.Transactions.Transaction.Create(this.systemTransaction);
        }
예제 #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EffortTransaction" /> class.
        /// </summary>
        /// <param name="connection">
        ///     The <see cref="EffortTransaction" /> object.
        /// </param>
        /// <param name="isolationLevel">
        ///     The isolation level.
        /// </param>
        /// <exception cref="System.InvalidOperationException">
        ///     Ambient transaction is already set.
        /// </exception>
        public EffortTransaction(
            EffortConnection connection,
            System.Data.IsolationLevel isolationLevel)
        {
            if (System.Transactions.Transaction.Current != null)
            {
                throw new InvalidOperationException("Ambient transaction is already set.");
            }

            this.connection = connection;
            this.isolationLevel = isolationLevel;

            // Initialize new ambient transaction
            System.Transactions.TransactionOptions options =
                new System.Transactions.TransactionOptions();

            options.IsolationLevel = TranslateIsolationLevel(isolationLevel);
            options.Timeout = new TimeSpan(0, 0, connection.ConnectionTimeout);

            this.systemTransaction = new System.Transactions.CommittableTransaction(options);

            this.transaction = NMemory.Transactions.Transaction.Create(this.systemTransaction);
        }