/// <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; }
/// <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); }
/// <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"); }
/// <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); }
/// <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); }
public void VerifyCommitPersistsChanges() { Transaction transaction = new EsentTransaction(this.session, "test", null); this.InsertRecord(1); transaction.Commit(); Assert.IsTrue(this.ContainsRecord(1)); }
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()); }
public void VerifyGetNewestTransactionReturnsCurrentTransactionIfNoSubtransactions() { var transaction = new EsentTransaction(this.session, "test", null); Assert.AreEqual(transaction, transaction.GetNewestTransaction()); }
/// <summary> /// Called when the level 0 transaction commits or rolls back. Clears the /// level0Transaction member. /// </summary> private void CloseLevel0Transaction() { this.level0Transaction = null; }
/// <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; }
public void VerifyCommittedEventIsCalledOnCommit() { bool eventCalled = false; Transaction transaction = new EsentTransaction(this.session, "test", null); transaction.Committed += () => eventCalled = true; transaction.Commit(); Assert.IsTrue(eventCalled); }
/// <summary> /// Unregister the subtransaction. This should be called when the subtransaction /// either commits or rolls back. /// </summary> private void UnregisterSubtransaction() { this.subTransaction = null; }
public void VerifyRollbackUndoesChanges() { Transaction transaction = new EsentTransaction(this.session, "test", null); this.InsertRecord(1); transaction.Rollback(); Assert.IsFalse(this.ContainsRecord(1)); }
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)); }
public void VerifyRolledBackEventIsCalledOnRollback() { bool eventCalled = false; Transaction transaction = new EsentTransaction(this.session, "test", null); transaction.RolledBack += () => eventCalled = true; transaction.Rollback(); Assert.IsTrue(eventCalled); }
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); }
/// <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; }
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); }
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); }