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