Ejemplo n.º 1
0
 /// <summary>
 /// Called when a new level 0 transaction starts.
 /// </summary>
 /// <param name="transaction">The transaction that is starting.</param>
 private void OnBeginLevel0Transaction(EsentTransaction transaction)
 {
     Debug.Assert(null == this.level0Transaction, "Already in a transaction");
     transaction.Committed  += this.CloseLevel0Transaction;
     transaction.RolledBack += this.CloseLevel0Transaction;
     this.level0Transaction  = transaction;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Begin a new transaction.
        /// </summary>
        /// <returns>A new transaction object.</returns>
        public Transaction BeginTransaction()
        {
            string transactionName = String.Format("{0}-{1}", this.Name, DateTime.Now);
            var    transaction     = new EsentTransaction(this.session, transactionName, this.GetNewestTransaction());

            if (null == this.level0Transaction)
            {
                this.OnBeginLevel0Transaction(transaction);
            }

            return(transaction);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the EsentTransaction class. This automatically
        /// begins a transaction. The transaction will be rolled back if
        /// not explicitly committed.
        /// </summary>
        /// <param name="session">The session to start the transaction for.</param>
        /// <param name="name">The name of the transaction.</param>
        /// <param name="outerTransaction">The previous active transaction.</param>
        internal EsentTransaction(Session session, string name, EsentTransaction outerTransaction)
        {
            this.name             = name;
            this.session          = session;
            this.outerTransaction = outerTransaction;
            this.Begin();
            if (null != this.outerTransaction)
            {
                this.outerTransaction.RegisterSubtransaction(this);
            }

            this.Tracer.TraceVerbose("created");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the EsentTransaction class. This automatically
        /// begins a transaction. The transaction will be rolled back if
        /// not explicitly committed.
        /// </summary>
        /// <param name="session">The session to start the transaction for.</param>
        /// <param name="name">The name of the transaction.</param>
        /// <param name="outerTransaction">The previous active transaction.</param>
        internal EsentTransaction(Session session, string name, EsentTransaction outerTransaction)
        {
            this.name = name;
            this.session = session;
            this.outerTransaction = outerTransaction;
            this.Begin();
            if (null != this.outerTransaction)
            {
                this.outerTransaction.RegisterSubtransaction(this);
            }

            this.Tracer.TraceVerbose("created");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Open a new Cursor.
        /// </summary>
        /// <param name="tablename">The name of the table to open the cursor on.</param>
        /// <returns>A new cursor opened on the table.</returns>
        public Cursor OpenCursor(string tablename)
        {
            var cursor = new Cursor(this.session, this.dbid, tablename);

            if (this.InTransaction)
            {
                EsentTransaction currentTransaction = this.level0Transaction.GetNewestTransaction();
                currentTransaction.RolledBack += cursor.Dispose;
            }

            this.Tracer.TraceVerbose("opened cursor on table '{0}'", tablename);
            return(cursor);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Open a table.
        /// </summary>
        /// <param name="tablename">The table to open.</param>
        /// <returns>A new Table object for the table.</returns>
        public Table OpenTable(string tablename)
        {
            this.CheckNotDisposed();

            TableBase table = this.OpenTableImpl(tablename);

            this.openedTables.Add(table);
            table.Disposed += this.OnTableClose;

            if (this.InTransaction)
            {
                EsentTransaction currentTransaction = this.level0Transaction.GetNewestTransaction();
                currentTransaction.RolledBack += table.Dispose;
            }

            this.Tracer.TraceVerbose("opened table '{0}'", tablename);
            return(table);
        }
Ejemplo n.º 7
0
        public void VerifyCommitPersistsChanges()
        {
            Transaction transaction = new EsentTransaction(this.session, "test", null);
            this.InsertRecord(1);
            transaction.Commit();

            Assert.IsTrue(this.ContainsRecord(1));
        }
Ejemplo n.º 8
0
        public void VerifyGetNewestTransactionReturnsNewestTransaction()
        {
            var level0transaction = new EsentTransaction(this.session, "test", null);
            var innerTransaction = new EsentTransaction(this.session, "test", level0transaction);
            var innermostTransaction = new EsentTransaction(this.session, "test", innerTransaction);

            Assert.AreEqual(innermostTransaction, level0transaction.GetNewestTransaction());
        }
Ejemplo n.º 9
0
 public void VerifyGetNewestTransactionReturnsCurrentTransactionIfNoSubtransactions()
 {
     var transaction = new EsentTransaction(this.session, "test", null);
     Assert.AreEqual(transaction, transaction.GetNewestTransaction());
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Called when the level 0 transaction commits or rolls back. Clears the
 /// level0Transaction member.
 /// </summary>
 private void CloseLevel0Transaction()
 {
     this.level0Transaction = null;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Register a transaction as a subtransaction. A subtransaction has to
 /// commit or rollback before this transaction.
 /// </summary>
 /// <param name="transaction">The new subtransaction.</param>
 internal void RegisterSubtransaction(EsentTransaction transaction)
 {
     this.subTransaction             = transaction;
     this.subTransaction.Committed  += this.UnregisterSubtransaction;
     this.subTransaction.RolledBack += this.UnregisterSubtransaction;
 }
Ejemplo n.º 12
0
        public void VerifyCommittedEventIsCalledOnCommit()
        {
            bool eventCalled = false;

            Transaction transaction = new EsentTransaction(this.session, "test", null);
            transaction.Committed += () => eventCalled = true;
            transaction.Commit();

            Assert.IsTrue(eventCalled);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Unregister the subtransaction. This should be called when the subtransaction
 /// either commits or rolls back.
 /// </summary>
 private void UnregisterSubtransaction()
 {
     this.subTransaction = null;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Register a transaction as a subtransaction. A subtransaction has to
 /// commit or rollback before this transaction.
 /// </summary>
 /// <param name="transaction">The new subtransaction.</param>
 internal void RegisterSubtransaction(EsentTransaction transaction)
 {
     this.subTransaction = transaction;
     this.subTransaction.Committed += this.UnregisterSubtransaction;
     this.subTransaction.RolledBack += this.UnregisterSubtransaction;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Called when the level 0 transaction commits or rolls back. Clears the
 /// level0Transaction member.
 /// </summary>
 private void CloseLevel0Transaction()
 {
     this.level0Transaction = null;
 }
Ejemplo n.º 16
0
        public void VerifyRollbackUndoesChanges()
        {
            Transaction transaction = new EsentTransaction(this.session, "test", null);
            this.InsertRecord(1);
            transaction.Rollback();

            Assert.IsFalse(this.ContainsRecord(1));
        }
Ejemplo n.º 17
0
        public void VerifyCommitThenRollbackUndoesChanges()
        {
            var outerTransaction = new EsentTransaction(this.session, "test", null);
            Transaction innerTransaction = new EsentTransaction(this.session, "test", outerTransaction);

            this.InsertRecord(1);
            innerTransaction.Commit();
            Assert.IsTrue(this.ContainsRecord(1));

            outerTransaction.Rollback();
            Assert.IsFalse(this.ContainsRecord(1));
        }
Ejemplo n.º 18
0
        public void VerifyRolledBackEventIsCalledOnRollback()
        {
            bool eventCalled = false;

            Transaction transaction = new EsentTransaction(this.session, "test", null);
            transaction.RolledBack += () => eventCalled = true;
            transaction.Rollback();

            Assert.IsTrue(eventCalled);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Unregister the subtransaction. This should be called when the subtransaction
 /// either commits or rolls back.
 /// </summary>
 private void UnregisterSubtransaction()
 {
     this.subTransaction = null;
 }
Ejemplo n.º 20
0
        public void VerifyCommitOfOuterTransactionCommitsInnerTransaction()
        {
            bool eventCalled = false;

            var outerTransaction = new EsentTransaction(this.session, "test", null);
            Transaction innerTransaction = new EsentTransaction(this.session, "test", outerTransaction);

            innerTransaction.Committed += () => eventCalled = true;
            outerTransaction.Commit();

            Assert.IsTrue(eventCalled);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Begin a new transaction.
        /// </summary>
        /// <returns>A new transaction object.</returns>
        public Transaction BeginTransaction()
        {
            string transactionName = String.Format("{0}-{1}", this.Name, DateTime.Now);
            var transaction = new EsentTransaction(this.session, transactionName, this.GetNewestTransaction());
            if (null == this.level0Transaction)
            {
                this.OnBeginLevel0Transaction(transaction);
            }

            return transaction;
        }
Ejemplo n.º 22
0
        public void VerifyRollbackOfOuterTransactionRollsbackInnerTransaction()
        {
            bool eventCalled = false;

            var outerTransaction = new EsentTransaction(this.session, "test", null);
            Transaction innerTransaction = new EsentTransaction(this.session, "test", outerTransaction);

            innerTransaction.RolledBack += () => eventCalled = true;
            outerTransaction.Rollback();

            Assert.IsTrue(eventCalled);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Called when a new level 0 transaction starts.
 /// </summary>
 /// <param name="transaction">The transaction that is starting.</param>
 private void OnBeginLevel0Transaction(EsentTransaction transaction)
 {
     Debug.Assert(null == this.level0Transaction, "Already in a transaction");
     transaction.Committed += this.CloseLevel0Transaction;
     transaction.RolledBack += this.CloseLevel0Transaction;
     this.level0Transaction = transaction;
 }
Ejemplo n.º 24
0
        public void VerifyRolledBackEventMigratesToOuterTransactionOnCommit()
        {
            bool eventCalled = false;

            var outerTransaction = new EsentTransaction(this.session, "test", null);
            Transaction innerTransaction = new EsentTransaction(this.session, "test", outerTransaction);

            innerTransaction.RolledBack += () => eventCalled = true;
            innerTransaction.Commit();
            outerTransaction.Rollback();

            Assert.IsTrue(eventCalled);
        }