Changeset 408
- Timestamp:
- 07/29/08 20:44:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r399 r408 36 36 public class Database : IDatabase { 37 37 private string connectionString; 38 private ReaderWriterLockSlim agentLock; 39 private ReaderWriterLockSlim resultLock; 38 private ReaderWriterLockSlim rwLock; 40 39 public Database(string connectionString) { 41 40 this.connectionString = connectionString; 42 agentLock = new ReaderWriterLockSlim(); 43 resultLock = new ReaderWriterLockSlim(); 41 rwLock = new ReaderWriterLockSlim(); 44 42 } 45 43 46 44 #region create empty database 47 45 public void CreateNew() { 48 agentLock.EnterWriteLock();46 rwLock.EnterWriteLock(); 49 47 try { 50 48 using(DbConnection cnn = new SQLiteConnection(connectionString)) { … … 70 68 } 71 69 } finally { 72 agentLock.ExitWriteLock();70 rwLock.ExitWriteLock(); 73 71 } 74 72 } … … 77 75 #region insert agent/result/sub-result 78 76 public long InsertAgent(long? parentAgentId, string name, byte[] rawData) { 79 agentLock.EnterWriteLock();77 rwLock.EnterWriteLock(); 80 78 try { 81 79 using(DbConnection cnn = new SQLiteConnection(connectionString)) { … … 109 107 } 110 108 } finally { 111 agentLock.ExitWriteLock();109 rwLock.ExitWriteLock(); 112 110 } 113 111 } 114 112 115 113 public long InsertResult(long agentId, string summary, string description, byte[] rawData) { 116 r esultLock.EnterWriteLock();114 rwLock.EnterWriteLock(); 117 115 try { 118 116 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { … … 151 149 } 152 150 } finally { 153 r esultLock.ExitWriteLock();151 rwLock.ExitWriteLock(); 154 152 } 155 153 } 156 154 157 155 public long InsertSubResult(long resultId, string summary, string description, byte[] rawData) { 158 r esultLock.EnterWriteLock();156 rwLock.EnterWriteLock(); 159 157 try { 160 158 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { … … 193 191 } 194 192 } finally { 195 r esultLock.ExitWriteLock();193 rwLock.ExitWriteLock(); 196 194 } 197 195 } … … 200 198 #region update agent/run 201 199 public void UpdateAgent(long id, string name) { 202 agentLock.EnterWriteLock();200 rwLock.EnterWriteLock(); 203 201 try { 204 202 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { … … 222 220 } 223 221 } finally { 224 agentLock.ExitWriteLock();222 rwLock.ExitWriteLock(); 225 223 } 226 224 } 227 225 228 226 public void UpdateAgent(long id, ProcessStatus status) { 229 agentLock.EnterWriteLock();227 rwLock.EnterWriteLock(); 230 228 try { 231 229 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { … … 249 247 } 250 248 } finally { 251 agentLock.ExitWriteLock();249 rwLock.ExitWriteLock(); 252 250 } 253 251 } 254 252 255 253 public void UpdateAgent(long id, byte[] rawData) { 256 agentLock.EnterWriteLock();254 rwLock.EnterWriteLock(); 257 255 try { 258 256 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { … … 276 274 } 277 275 } finally { 278 agentLock.ExitWriteLock();276 rwLock.ExitWriteLock(); 279 277 } 280 278 } … … 285 283 286 284 public ICollection<AgentEntry> GetAgents(ProcessStatus status) { 287 agentLock.EnterReadLock();285 rwLock.EnterReadLock(); 288 286 List<AgentEntry> agents = new List<AgentEntry>(); 289 287 try { … … 308 306 } 309 307 } finally { 310 agentLock.ExitReadLock();308 rwLock.ExitReadLock(); 311 309 } 312 310 return agents; … … 314 312 315 313 public ICollection<AgentEntry> GetAgents() { 316 agentLock.EnterReadLock();314 rwLock.EnterReadLock(); 317 315 List<AgentEntry> agents = new List<AgentEntry>(); 318 316 try { … … 335 333 } 336 334 } finally { 337 agentLock.ExitReadLock();335 rwLock.ExitReadLock(); 338 336 } 339 337 return agents; … … 341 339 342 340 public ICollection<AgentEntry> GetSubAgents(long parentAgentId) { 343 agentLock.EnterReadLock();341 rwLock.EnterReadLock(); 344 342 List<AgentEntry> agents = new List<AgentEntry>(); 345 343 try { … … 367 365 } 368 366 } finally { 369 agentLock.ExitReadLock();367 rwLock.ExitReadLock(); 370 368 } 371 369 return agents; … … 374 372 public ICollection<ResultEntry> GetResults(long agentId) { 375 373 List<ResultEntry> results = new List<ResultEntry>(); 376 r esultLock.EnterReadLock();374 rwLock.EnterReadLock(); 377 375 try { 378 376 using(DbConnection cnn = new SQLiteConnection(connectionString)) { … … 399 397 } 400 398 } finally { 401 r esultLock.ExitReadLock();399 rwLock.ExitReadLock(); 402 400 } 403 401 return results; … … 406 404 public ICollection<ResultEntry> GetSubResults(long resultId) { 407 405 List<ResultEntry> results = new List<ResultEntry>(); 408 r esultLock.EnterReadLock();406 rwLock.EnterReadLock(); 409 407 try { 410 408 using(DbConnection cnn = new SQLiteConnection(connectionString)) { … … 431 429 } 432 430 } finally { 433 r esultLock.ExitReadLock();431 rwLock.ExitReadLock(); 434 432 } 435 433 return results;
Note: See TracChangeset
for help on using the changeset viewer.