Rev | Line | |
---|
[4649] | 1 | using System;
|
---|
[5708] | 2 | using System.Transactions;
|
---|
[4649] | 3 | using HeuristicLab.Services.Hive.Common;
|
---|
| 4 |
|
---|
| 5 | namespace HeuristicLab.Services.Hive.DataAccess {
|
---|
| 6 | public class TransactionManager {
|
---|
[5708] | 7 | public void UseTransaction(Action call) {
|
---|
| 8 | TransactionScope transaction = CreateTransaction();
|
---|
| 9 | try {
|
---|
| 10 | call();
|
---|
| 11 | transaction.Complete();
|
---|
| 12 | }
|
---|
| 13 | finally {
|
---|
| 14 | transaction.Dispose();
|
---|
| 15 | }
|
---|
[4649] | 16 | }
|
---|
| 17 |
|
---|
[5708] | 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 | }
|
---|
[4649] | 28 | }
|
---|
[5708] | 29 |
|
---|
| 30 | private static TransactionScope CreateTransaction() {
|
---|
| 31 | return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope });
|
---|
| 32 | }
|
---|
[4649] | 33 | }
|
---|
| 34 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.