Changeset 507
- Timestamp:
- 08/12/08 18:58:57 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Grid/Database.cs
r505 r507 106 106 using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) { 107 107 cnn.Open(); 108 using(DbTransaction t = cnn.BeginTransaction()) { 109 DbCommand c = cnn.CreateCommand(); 110 c.Transaction = t; 111 c.CommandText = "select guid,creationtime,starttime,rawdata from job, (select id from job where status=@Status order by creationtime limit 1) as next where job.id=next.id"; 112 DbParameter statusParameter = c.CreateParameter(); 113 statusParameter.ParameterName = "@Status"; 114 statusParameter.Value = JobState.Waiting.ToString(); 115 c.Parameters.Add(statusParameter); 116 DbDataReader r = c.ExecuteReader(); 117 if(!r.HasRows) { 108 JobEntry job = new JobEntry(); 109 using(DbTransaction t = cnn.BeginTransaction()) { 110 using(DbCommand c = cnn.CreateCommand()) { 111 c.Transaction = t; 112 c.CommandText = "select guid,creationtime,starttime,rawdata from job, (select id from job where status=@Status order by creationtime limit 1) as next where job.id=next.id"; 113 DbParameter statusParameter = c.CreateParameter(); 114 statusParameter.ParameterName = "@Status"; 115 statusParameter.Value = JobState.Waiting.ToString(); 116 c.Parameters.Add(statusParameter); 117 DbDataReader r = c.ExecuteReader(); 118 if(!r.HasRows) { 119 r.Close(); 120 t.Commit(); 121 return null; 122 } 123 r.Read(); 124 job.Status = JobState.Busy; 125 job.Guid = r.GetGuid(0); 126 job.CreationTime = r.GetDateTime(1); 127 job.StartTime = r.IsDBNull(2) ? null : new Nullable<DateTime>(r.GetDateTime(2)); 128 job.RawData = (byte[])r.GetValue(3); 118 129 r.Close(); 119 t.Commit(); 120 return null; 121 } 122 r.Read(); 123 JobEntry job = new JobEntry(); 124 job.Status = JobState.Busy; 125 job.Guid = r.GetGuid(0); 126 job.CreationTime = r.GetDateTime(1); 127 job.StartTime = r.IsDBNull(2) ? null : new Nullable<DateTime>(r.GetDateTime(2)); 128 job.RawData = (byte[])r.GetValue(3); 129 r.Close(); 130 } 130 131 rwLock.EnterWriteLock(); 131 132 try { 132 DbCommand updateCmd = cnn.CreateCommand(); 133 updateCmd.Transaction = t; 134 updateCmd.CommandText = "Update job set Status=@Status where Guid=@Guid"; 135 statusParameter = updateCmd.CreateParameter(); 136 statusParameter.ParameterName = "@Status"; 137 statusParameter.Value = JobState.Busy.ToString(); 138 DbParameter guidParam = updateCmd.CreateParameter(); 139 guidParam.ParameterName = "@Guid"; 140 guidParam.Value = job.Guid.ToString(); 141 updateCmd.Parameters.Add(statusParameter); 142 updateCmd.Parameters.Add(guidParam); 143 updateCmd.ExecuteNonQuery(); 133 using(DbCommand updateCmd = cnn.CreateCommand()) { 134 updateCmd.Transaction = t; 135 updateCmd.CommandText = "Update job set Status=@Status where Guid=@Guid"; 136 DbParameter statusParam = updateCmd.CreateParameter(); 137 statusParam.ParameterName = "@Status"; 138 statusParam.Value = JobState.Busy.ToString(); 139 DbParameter guidParam = updateCmd.CreateParameter(); 140 guidParam.ParameterName = "@Guid"; 141 guidParam.Value = job.Guid.ToString(); 142 updateCmd.Parameters.Add(statusParam); 143 updateCmd.Parameters.Add(guidParam); 144 updateCmd.ExecuteNonQuery(); 145 } 146 t.Commit(); 144 147 } finally { 145 148 rwLock.ExitWriteLock(); 146 149 } 147 t.Commit();148 150 return job; 149 151 }
Note: See TracChangeset
for help on using the changeset viewer.