Index: trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/DataAdapterBase.cs
===================================================================
--- trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/DataAdapterBase.cs	(revision 2061)
+++ trunk/sources/HeuristicLab.DataAccess.ADOHelper/3.2/DataAdapterBase.cs	(revision 2082)
@@ -82,4 +82,5 @@
 
     protected delegate IEnumerable<RowT> Selector();
+    protected delegate object TransactionalAction();
 
     protected ObjT Convert(RowT row, ObjT obj) {
@@ -109,66 +110,45 @@
 
     protected ObjT FindSingle(Selector selector) {
-      ITransaction trans =
-       session.GetCurrentTransaction();
-      bool transactionExists = trans != null;
-      if (!transactionExists) {
-        trans = session.BeginTransaction();
-      }
-
-      try {
-        RowT row = FindSingleRow(selector);
-
-        ObjT result;
-        if (row != null) {
-          ObjT obj = new ObjT();
-          obj = Convert(row, obj);
-
-          result = obj;
-        } else {
-          result = default(ObjT);
-        }
-
-        return result;
-      }
-      finally {
-        if (!transactionExists && trans != null) {
-          trans.Commit();
-        }
-      }
+      return 
+        (ObjT)doInTransaction(
+         delegate() {
+          RowT row = FindSingleRow(selector);
+
+          ObjT result;
+          if (row != null) {
+            ObjT obj = new ObjT();
+            obj = Convert(row, obj);
+
+            result = obj;
+          } else {
+            result = default(ObjT);
+          }
+
+          return result;
+        });
     }
 
     private ICollection<ObjT> FindMultiple(Selector selector, 
       int from, int size) {
-      ITransaction trans =
-       session.GetCurrentTransaction();
-      bool transactionExists = trans != null;
-      if (!transactionExists) {
-        trans = session.BeginTransaction();
-      }
-
-      try {
-        IEnumerable<RowT> found =
-          selector();
-
-        if (from > 0 && size > 0)
-          found = found.Skip<RowT>(from).Take<RowT>(size);
-
-        IList<ObjT> result =
-          new List<ObjT>();
-
-        foreach (RowT row in found) {
-          ObjT obj = new ObjT();
-          obj = Convert(row, obj);
-          if (obj != null)
-            result.Add(obj);
-        }
-
-        return result;
-      }
-      finally {
-        if (!transactionExists && trans != null) {
-          trans.Commit();
-        }
-      }     
+      return (ICollection<ObjT>)doInTransaction(
+        delegate() {
+          IEnumerable<RowT> found =
+            selector();
+
+          if (from > 0 && size > 0)
+            found = found.Skip<RowT>(from).Take<RowT>(size);
+
+          IList<ObjT> result =
+            new List<ObjT>();
+
+          foreach (RowT row in found) {
+            ObjT obj = new ObjT();
+            obj = Convert(row, obj);
+            if (obj != null)
+              result.Add(obj);
+          }
+
+          return result;
+        });   
     }
 
@@ -185,24 +165,5 @@
     }
 
-    protected virtual void doUpdate(ObjT obj) {
-      if (obj != null) {
-        RowT row = null;
-
-        if (obj.Id != Guid.Empty) {
-          row = GetRowById(obj.Id);
-        } else {
-          obj.Id = Guid.NewGuid();
-        }
-
-        if (row == null) {
-          row = dataAdapter.InsertNewRow(obj);
-        }
-
-        ConvertObj(obj, row);
-        dataAdapter.UpdateRow(row);
-      }
-    }
-
-    public void Update(ObjT obj) {
+    protected object doInTransaction(TransactionalAction action) {
       ITransaction trans =
         session.GetCurrentTransaction();
@@ -213,5 +174,47 @@
 
       try {
-        doUpdate(obj);
+        bool result = (bool)action();
+
+        if (!transactionExists && trans != null) {
+            trans.Commit();
+        }
+
+        return result;
+      }
+      catch (Exception e) {
+        if (!transactionExists && trans != null) {
+          trans.Rollback();
+        }
+
+        throw e;
+      }
+    }
+
+    protected virtual void doUpdate(ObjT obj) {
+      if (obj != null) {
+        RowT row = null;
+
+        if (obj.Id != Guid.Empty) {
+          row = GetRowById(obj.Id);
+        } else {
+          obj.Id = Guid.NewGuid();
+        }
+
+        if (row == null) {
+          row = dataAdapter.InsertNewRow(obj);
+        }
+
+        ConvertObj(obj, row);
+        dataAdapter.UpdateRow(row);
+      }
+    }
+
+    public void Update(ObjT obj) {
+      try {
+        doInTransaction(
+          delegate() {
+            doUpdate(obj);
+            return true;
+          });        
       }
       catch (DBConcurrencyException ex) {
@@ -234,9 +237,4 @@
         //otherwise: row was deleted in the meantime - nothing to do
       }
-      finally {
-        if (!transactionExists && trans != null) {
-          trans.Commit();
-        }
-      }
     }
 
@@ -282,13 +280,9 @@
 
     public bool Delete(ObjT obj) {
-      ITransaction trans =
-        session.GetCurrentTransaction();
-      bool transactionExists = trans != null;
-      if (!transactionExists) {
-        trans = session.BeginTransaction();
-      }
-
       try {
-        return doDelete(obj);
+        return (bool)doInTransaction(
+          delegate() {
+            return doDelete(obj);
+          });
       }
       catch (DBConcurrencyException) {
@@ -303,9 +297,4 @@
         }
       }
-      finally {
-        if (!transactionExists && trans != null) {
-          trans.Commit();
-        }
-      }  
     }
   }
