- Timestamp:
- 01/15/09 15:04:50 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/DataAdapterBase.cs
r1131 r1134 26 26 using System.Text; 27 27 using HeuristicLab.Hive.Contracts.BusinessObjects; 28 using System. Runtime.CompilerServices;28 using System.Threading; 29 29 30 30 namespace HeuristicLab.Hive.Server.ADODataAccess { … … 33 33 where RowT : System.Data.DataRow 34 34 where ObjT : IHiveObject, new() { 35 36 private static Mutex lockersMutex = 37 new Mutex(); 38 39 private static IDictionary<long, Mutex> lockers = 40 new Dictionary<long, Mutex>(); 41 42 private static IDictionary<long, int> lockCount = 43 new Dictionary<long, int>(); 44 45 protected void LockRow(long id) { 46 Mutex rowLock = null; 47 48 /////begin critical section//// 49 lockersMutex.WaitOne(); 50 51 if (!lockers.ContainsKey(id)) { 52 lockers[id] = new Mutex(); 53 lockCount[id] = 0; 54 } 55 rowLock = lockers[id]; 56 lockCount[id]++; 57 58 lockersMutex.ReleaseMutex(); 59 /////end critical section//// 60 61 rowLock.WaitOne(); 62 } 63 64 protected void UnlockRow(long id) { 65 Mutex rowLock = lockers[id]; 66 rowLock.ReleaseMutex(); 67 68 /////begin critical section//// 69 lockersMutex.WaitOne(); 70 71 lockCount[id]--; 72 if (lockCount[id] == 0) 73 lockers.Remove(id); 74 75 lockersMutex.ReleaseMutex(); 76 /////end critical section//// 77 } 78 35 79 protected AdapterT Adapter { 36 80 get { … … 44 88 protected abstract ObjT ConvertRow(RowT row, ObjT obj); 45 89 46 [MethodImpl(MethodImplOptions.Synchronized)]47 90 protected abstract RowT InsertNewRow(ObjT obj); 48 91 49 [MethodImpl(MethodImplOptions.Synchronized)]50 92 protected abstract void UpdateRow(RowT row); 51 93 … … 119 161 } 120 162 121 [MethodImpl(MethodImplOptions.Synchronized)]122 163 public virtual void Update(ObjT obj) { 123 164 if (obj != null) { … … 127 168 if (row == null) { 128 169 row = InsertNewRow(obj); 170 UpdateRow(row); 129 171 } 130 172 173 obj.Id = (long)row[row.Table.PrimaryKey[0]]; 174 LockRow(obj.Id); 175 131 176 ConvertObj(obj, row); 132 133 177 UpdateRow(row); 134 178 135 obj.Id = (long)row[row.Table.PrimaryKey[0]];179 UnlockRow(obj.Id); 136 180 } 137 181 } … … 149 193 } 150 194 151 [MethodImpl(MethodImplOptions.Synchronized)]152 195 public virtual bool Delete(ObjT obj) { 196 bool success = false; 197 153 198 if (obj != null) { 199 LockRow(obj.Id); 200 154 201 RowT row = 155 202 GetRowById(obj.Id); … … 159 206 UpdateRow(row); 160 207 161 returntrue;208 success = true; 162 209 } 163 } 164 165 return false; 210 211 UnlockRow(obj.Id); 212 } 213 214 return success; 166 215 } 167 216 }
Note: See TracChangeset
for help on using the changeset viewer.