Line | |
---|
1 | using System;
|
---|
2 | using System.Transactions;
|
---|
3 | using HeuristicLab.Services.Hive.Common;
|
---|
4 |
|
---|
5 | namespace 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.