From 7542f5737ddec3fd7a5952d73bd5be0fe3348eef Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 6 Jun 2010 12:50:12 +0000 Subject: [PATCH] Transactions in IDBConnection --- Core/DB/IDBConnection.cs | 10 ++++++---- Core/DB/ITransaction.cs | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Core/DB/ITransaction.cs diff --git a/Core/DB/IDBConnection.cs b/Core/DB/IDBConnection.cs index 9e844a8..b67d80d 100644 --- a/Core/DB/IDBConnection.cs +++ b/Core/DB/IDBConnection.cs @@ -11,13 +11,15 @@ namespace FLocal.Core.DB { int[] LoadIdsByConditions(ITableSpec table, conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts); - ILock lockTable(ITableSpec table); + Transaction beginTransaction(); - ILock lockRow(ITableSpec table, int id); + ILock lockTable(Transaction transaction, ITableSpec table); - void update(ITableSpec table, int id, Dictionary data); + ILock lockRow(Transaction transaction, ITableSpec table, int id); - void delete(ITableSpec table, int id); //do we really need this? + void update(Transaction transaction, ITableSpec table, int id, Dictionary data); + + void delete(Transaction transaction, ITableSpec table, int id); //do we really need this? } diff --git a/Core/DB/ITransaction.cs b/Core/DB/ITransaction.cs new file mode 100644 index 0000000..5a18ff9 --- /dev/null +++ b/Core/DB/ITransaction.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Core.DB { + + abstract class Transaction : IDisposable { + + abstract protected void do_Commit(); + + abstract protected void do_Rollback(); + + private bool finalized = false; + + public void Commit() { + lock(this) { + this.do_Commit(); + this.finalized = true; + } + } + + public void Rollback() { + lock(this) { + this.do_Rollback(); + this.finalized = true; + } + } + + public void Dispose() { + lock(this) { + if(!this.finalized) { + this.do_Rollback(); + this.finalized = true; + } + } + } + + } + +}