Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/11 13:32:39 (14 years ago)
Author:
cneumuel
Message:

#1233

  • changed the way transactions are handled
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs

    r5055 r5708  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
     2using System.Transactions;
    53using HeuristicLab.Services.Hive.Common;
    6 using System.Transactions;
    7 using HeuristicLab.Common;
    8 using HeuristicLab.Clients.Common;
    94
    105namespace HeuristicLab.Services.Hive.DataAccess {
    116  public class TransactionManager {
    12     public Disposable<TransactionScope> OpenTransaction() {
    13       TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope });
    14       var disposable = new Disposable<TransactionScope>(transaction);
    15       disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing);
    16       return disposable;
     7    public void UseTransaction(Action call) {
     8      TransactionScope transaction = CreateTransaction();
     9      try {
     10        call();
     11        transaction.Complete();
     12      }
     13      finally {
     14        transaction.Dispose();
     15      }
    1716    }
    1817
    19     void disposable_OnDisposing(object sender, EventArgs<object> e) {
    20       TransactionScope scope = (TransactionScope)e.Value;
    21       scope.Complete();
    22       scope.Dispose();
     18    public T UseTransaction<T>(Func<T> call) {
     19      TransactionScope transaction = CreateTransaction();
     20      try {
     21        T result = call();
     22        transaction.Complete();
     23        return result;
     24      }
     25      finally {
     26        transaction.Dispose();
     27      }
     28    }
     29
     30    private static TransactionScope CreateTransaction() {
     31      return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope });
    2332    }
    2433  }
Note: See TracChangeset for help on using the changeset viewer.