Changeset 1516 for trunk/sources
- Timestamp:
- 04/05/09 13:52:10 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAccess.ADOHelper/DataAdapterBase.cs
r1515 r1516 38 38 private IDataAdapterWrapper<AdapterT, ObjT, RowT> dataAdapter; 39 39 40 private static Mutex lockersMutex =41 new Mutex();42 43 private static IDictionary<object, Mutex> lockers =44 new Dictionary<object, Mutex>();45 46 private static IDictionary<object, int> lockCount =47 new Dictionary<object, int>();48 49 40 protected DataAdapterBase( 50 41 IDataAdapterWrapper<AdapterT, ObjT, RowT> dataAdapter) { … … 52 43 } 53 44 54 protected void LockRow(object id) {55 Mutex rowLock = null;56 57 /////begin critical section////58 lockersMutex.WaitOne();59 60 if (!lockers.ContainsKey(id)) {61 lockers[id] = new Mutex();62 lockCount[id] = 0;63 }64 rowLock = lockers[id];65 lockCount[id]++;66 67 lockersMutex.ReleaseMutex();68 /////end critical section////69 70 rowLock.WaitOne();71 }72 73 protected void UnlockRow(object id) {74 Mutex rowLock = lockers[id];75 rowLock.ReleaseMutex();76 77 /////begin critical section////78 lockersMutex.WaitOne();79 80 lockCount[id]--;81 if (lockCount[id] == 0)82 lockers.Remove(id);83 84 lockersMutex.ReleaseMutex();85 /////end critical section////86 }87 88 45 protected AdapterT Adapter { 89 46 get { … … 222 179 if (obj != null) { 223 180 RowT row = null; 224 Guid locked = Guid.Empty;225 181 226 182 if (obj.Id != Guid.Empty) { 227 LockRow(obj.Id);228 locked = obj.Id;229 230 183 row = GetRowById(obj.Id); 231 184 } else { … … 237 190 } 238 191 239 if (locked == Guid.Empty) {240 LockRow(obj.Id);241 locked = obj.Id;242 }243 244 192 ConvertObj(obj, row); 245 193 dataAdapter.UpdateRow(row); 246 247 UnlockRow(locked);248 194 } 249 195 } … … 259 205 try { 260 206 doUpdate(obj); 207 } 208 catch (DBConcurrencyException ex) { 209 DataRow row = ex.Row; 210 211 RowT current = GetRowById(obj.Id); 212 if (current != null) { 213 //find out changes 214 for (int i = 0; i < row.ItemArray.Length; i++) { 215 if (!row[i, DataRowVersion.Current].Equals( 216 row[i, DataRowVersion.Original])) { 217 current[i] = row[i]; 218 } 219 } 220 221 ConvertRow(current, obj); 222 //try updating again 223 Update(obj); 224 } 225 //otherwise: row was deleted in the meantime - nothing to do 261 226 } 262 227 finally { … … 283 248 284 249 if (obj != null) { 285 LockRow(obj.Id);286 287 250 RowT row = 288 251 GetRowById(obj.Id); … … 294 257 success = true; 295 258 } 296 297 UnlockRow(obj.Id);298 259 } 299 260 … … 311 272 try { 312 273 return doDelete(obj); 274 } 275 catch (DBConcurrencyException) { 276 RowT current = GetRowById(obj.Id); 277 if (current != null) { 278 ConvertRow(current, obj); 279 //try deleting again 280 return Delete(obj); 281 } else { 282 //row has already been deleted 283 return false; 284 } 313 285 } 314 286 finally { -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/Transaction.cs
r1496 r1516 47 47 value.Open(); 48 48 49 transaction = value.BeginTransaction(IsolationLevel.Re peatableRead);49 transaction = value.BeginTransaction(IsolationLevel.ReadCommitted); 50 50 } 51 51 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs
r1515 r1516 221 221 protected override bool doDelete(ClientInfo client) { 222 222 bool success = false; 223 Guid locked = Guid.Empty;224 223 225 224 if (client != null) { 226 if (client.Id != Guid.Empty) {227 LockRow(client.Id);228 locked = client.Id;229 }230 231 225 dsHiveServer.ClientRow row = 232 226 GetRowById(client.Id); … … 238 232 } 239 233 240 if (locked != Guid.Empty) {241 UnlockRow(locked);242 }243 244 234 return success; 245 235 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/dsHiveServer.cs
r1377 r1516 3 3 4 4 public partial class dsHiveServer { 5 partial class JobDataTable { 6 } 7 5 8 partial class ClientGroup_ResourceDataTable { 6 9 }
Note: See TracChangeset
for help on using the changeset viewer.