Changeset 9434 for branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/OptimizedHiveDao.cs
- Timestamp:
- 05/03/13 13:47:27 (11 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources/HeuristicLab.Services.Hive/3.3/OptimizedHiveDao.cs
r9399 r9434 27 27 28 28 namespace HeuristicLab.Services.Hive.DataAccess { 29 public class HiveDao : IHiveDao {30 private HiveDataContext Db { get { return HiveOperationContext.Current.DataContext; } }29 public class OptimizedHiveDao : IOptimizedHiveDao { 30 private static HiveDataContext Db { get { return HiveOperationContext.Current.DataContext; } } 31 31 32 32 #region Task Methods … … 35 35 } 36 36 37 private static Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>37 private static readonly Func<HiveDataContext, Guid, IQueryable<Task>> GetTaskByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 38 38 from t in db.Tasks 39 39 where t.TaskId == taskId … … 51 51 } 52 52 53 private static Func<HiveDataContext, Guid, IQueryable<Tuple<Task, Guid?>>> GetTaskByIdAndLastStateLogSlaveIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) =>53 private static readonly Func<HiveDataContext, Guid, IQueryable<Tuple<Task, Guid?>>> GetTaskByIdAndLastStateLogSlaveIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 54 54 from t in db.Tasks 55 55 join sl in db.StateLogs on t.TaskId equals sl.TaskId … … 89 89 } 90 90 91 private static Func<HiveDataContext, Guid, IQueryable<DT.LightweightTask>> GetLightweightTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid jobId) =>91 private static readonly Func<HiveDataContext, Guid, IQueryable<DT.LightweightTask>> GetLightweightTasksQuery = CompiledQuery.Compile((HiveDataContext db, Guid jobId) => 92 92 from task in db.Tasks 93 93 where task.JobId == jobId … … 103 103 ); 104 104 105 staticFunc<StateLog, DT.StateLog> ConvertStateLog = sl => DT.Convert.ToDto(sl);106 staticFunc<TaskState, DT.TaskState> ConvertTaskState = ts => DT.Convert.ToDto(ts);107 staticFunc<Command?, DT.Command?> ConvertCommand = c => DT.Convert.ToDto(c);105 private static readonly Func<StateLog, DT.StateLog> ConvertStateLog = sl => DT.Convert.ToDto(sl); 106 private static readonly Func<TaskState, DT.TaskState> ConvertTaskState = ts => DT.Convert.ToDto(ts); 107 private static readonly Func<Command?, DT.Command?> ConvertCommand = c => DT.Convert.ToDto(c); 108 108 109 109 public void UpdateTask(Task task) { … … 127 127 128 128 return task; 129 } 130 131 public Guid AddTask(Task task) { 132 Db.Tasks.InsertOnSubmit(task); 133 Db.SubmitChanges(); 134 return task.TaskId; 135 } 136 137 public void AssignJobToResource(Guid taskId, IEnumerable<Guid> resourceIds) { 138 Db.AssignedResources.InsertAllOnSubmit(resourceIds.Select(resourceId => new AssignedResource { TaskId = taskId, ResourceId = resourceId })); 139 Db.SubmitChanges(); 129 140 } 130 141 … … 153 164 } 154 165 155 private static Func<HiveDataContext, Guid, IQueryable<TaskData>> GetTaskDataByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) =>166 private static readonly Func<HiveDataContext, Guid, IQueryable<TaskData>> GetTaskDataByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid id) => 156 167 from t in db.TaskDatas 157 168 where t.TaskId == id … … 187 198 } 188 199 189 private static Func<HiveDataContext, Guid, IQueryable<Plugin>> GetPluginByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid pluginId) =>200 private static readonly Func<HiveDataContext, Guid, IQueryable<Plugin>> GetPluginByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid pluginId) => 190 201 from p in db.Plugins 191 202 where p.PluginId == pluginId … … 204 215 } 205 216 206 private static Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) =>217 private static readonly Func<HiveDataContext, Guid, IQueryable<Slave>> GetSlaveByIdQuery = CompiledQuery.Compile((HiveDataContext db, Guid slaveId) => 207 218 from s in db.Resources.OfType<Slave>() 208 219 where s.ResourceId == slaveId … … 243 254 244 255 #region Resource Methods 256 public IEnumerable<Guid> GetAssignedResourceIds(Guid taskId) { 257 return GetAssignedResourceIdsQuery(Db, taskId); 258 } 259 260 private static readonly Func<HiveDataContext, Guid, IQueryable<Guid>> GetAssignedResourceIdsQuery = CompiledQuery.Compile((HiveDataContext db, Guid taskId) => 261 from ar in db.AssignedResources 262 where ar.TaskId == taskId 263 select ar.ResourceId 264 ); 245 265 #endregion 246 266
Note: See TracChangeset
for help on using the changeset viewer.