Changeset 9257 for trunk/sources/HeuristicLab.Services.Hive.DataAccess
- Timestamp:
- 02/28/13 13:57:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/TransactionManager.cs
r7259 r9257 22 22 using System; 23 23 using System.Transactions; 24 using HeuristicLab.Services.Hive.DataAccess;25 24 26 namespace HeuristicLab.Services.Hive.DataAccess { 27 public class TransactionManager : ITransactionManager { 28 public void UseTransaction(Action call, bool serializable= false, bool longRunning = false) {25 namespace HeuristicLab.Services.Hive.DataAccess { 26 public class TransactionManager : ITransactionManager { 27 public void UseTransaction(Action call, bool repeatableRead = false, bool longRunning = false) { 29 28 int n = 10; 30 29 while (n > 0) { 31 TransactionScope transaction = CreateTransaction( serializable, longRunning);30 TransactionScope transaction = CreateTransaction(repeatableRead, longRunning); 32 31 try { 33 32 call(); … … 37 36 catch (System.Data.SqlClient.SqlException e) { 38 37 n--; // probably deadlock situation, let it roll back and repeat the transaction n times 39 LogFactory.GetLogger(typeof(TransactionManager).Namespace).Log(string.Format("Exception occured, repeating transaction {0} more times. Details: {1}", n, e.ToString())); 38 LogFactory.GetLogger(typeof(TransactionManager).Namespace).Log(string.Format("Exception occured, repeating transaction {0} more times. Details: {1}", n, e.ToString())); 40 39 if (n <= 0) throw; 41 40 } … … 46 45 } 47 46 48 public T UseTransaction<T>(Func<T> call, bool serializable= false, bool longRunning = false) {47 public T UseTransaction<T>(Func<T> call, bool repeatableRead = false, bool longRunning = false) { 49 48 int n = 10; 50 49 while (n > 0) { 51 TransactionScope transaction = CreateTransaction( serializable, longRunning);50 TransactionScope transaction = CreateTransaction(repeatableRead, longRunning); 52 51 try { 53 52 T result = call(); … … 68 67 } 69 68 70 private TransactionScope CreateTransaction(bool serializable, bool longRunning) {69 private TransactionScope CreateTransaction(bool repeatableRead, bool longRunning) { 71 70 var options = new TransactionOptions(); 72 if ( serializable)73 options.IsolationLevel = IsolationLevel. Serializable;71 if (repeatableRead) 72 options.IsolationLevel = IsolationLevel.RepeatableRead; 74 73 else 75 74 options.IsolationLevel = IsolationLevel.ReadUncommitted;
Note: See TracChangeset
for help on using the changeset viewer.