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; + } + } + } + + } + +}