Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs @ 5787

Last change on this file since 5787 was 5708, checked in by cneumuel, 14 years ago

#1233

  • changed the way transactions are handled
File size: 933 bytes
Line 
1using System;
2using System.Transactions;
3using HeuristicLab.Services.Hive.Common;
4
5namespace HeuristicLab.Services.Hive.DataAccess {
6  public class TransactionManager {
7    public void UseTransaction(Action call) {
8      TransactionScope transaction = CreateTransaction();
9      try {
10        call();
11        transaction.Complete();
12      }
13      finally {
14        transaction.Dispose();
15      }
16    }
17
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 });
32    }
33  }
34}
Note: See TracBrowser for help on using the repository browser.