- Timestamp:
- 07/08/15 15:51:32 (9 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedResourceDao.cs
r12584 r12691 35 35 return Table.Where(x => x.TaskId == taskId); 36 36 } 37 38 public bool TaskIsAllowedToBeCalculatedBySlave(Guid taskId, Guid slaveId) { 39 return DataContext.ExecuteQuery<int>(TaskIsAllowedToBeCalculatedBySlaveQueryString, slaveId, taskId).First() > 0; 40 } 41 42 #region String queries 43 private const string TaskIsAllowedToBeCalculatedBySlaveQueryString = @" 44 WITH pr AS ( 45 SELECT ResourceId, ParentResourceId 46 FROM [Resource] 47 WHERE ResourceId = {0} 48 UNION ALL 49 SELECT r.ResourceId, r.ParentResourceId 50 FROM [Resource] r JOIN pr ON r.ResourceId = pr.ParentResourceId 51 ) 52 SELECT COUNT(ar.TaskId) 53 FROM pr JOIN AssignedResources ar ON pr.ResourceId = ar.ResourceId 54 WHERE ar.TaskId = {1} 55 "; 56 #endregion 37 57 } 38 58 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/DowntimeDao.cs
r12468 r12691 29 29 30 30 public override Downtime GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.DowntimeId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 public IQueryable<Downtime> GetByResourceId(Guid id) { 35 return Table.Where(x => x.ResourceId == id); 36 } 37 38 #region Compiled queries 39 private static readonly Func<DataContext, Guid, Downtime> GetByIdQuery = 40 CompiledQuery.Compile((DataContext db, Guid downtimeId) => 41 (from downtime in db.GetTable<Downtime>() 42 where downtime.DowntimeId == downtimeId 43 select downtime).SingleOrDefault()); 44 #endregion 33 45 } 34 46 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/GenericDao.cs
r12484 r12691 109 109 110 110 public bool Exists(T entity) { 111 return Table.Contains(entity);111 return ExistsQuery(DataContext, entity); 112 112 } 113 113 … … 116 116 } 117 117 #endregion 118 119 #region Compiled queries 120 private static readonly Func<DataContext, T, bool> ExistsQuery = 121 CompiledQuery.Compile((DataContext db, T entity) => 122 db.GetTable<T>().Contains(entity)); 123 #endregion 118 124 } 119 125 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimClientDao.cs
r12516 r12691 27 27 namespace HeuristicLab.Services.Hive.DataAccess.Daos.HiveStatistics { 28 28 public class DimClientDao : GenericDao<Guid, DimClient> { 29 private const string UpdateExpirationTimeQuery =30 @"UPDATE [statistics].[DimClient]31 SET ExpirationTime = {0}32 WHERE Id IN ({1});";33 34 29 public DimClientDao(DataContext dataContext) : base(dataContext) { } 35 30 36 31 public override DimClient GetById(Guid id) { 37 return Table.SingleOrDefault(x => x.Id ==id);32 return GetByIdQuery(DataContext, id); 38 33 } 34 39 35 public IQueryable<DimClient> GetActiveClients() { 40 36 return Table.Where(x => x.ExpirationTime == null); … … 53 49 return 0; 54 50 } 51 52 #region Compiled queries 53 private static readonly Func<DataContext, Guid, DimClient> GetByIdQuery = 54 CompiledQuery.Compile((DataContext db, Guid id) => 55 (from dimClient in db.GetTable<DimClient>() 56 where dimClient.Id == id 57 select dimClient).SingleOrDefault()); 58 #endregion 59 60 #region String queries 61 private const string UpdateExpirationTimeQuery = 62 @"UPDATE [statistics].[DimClient] 63 SET ExpirationTime = {0} 64 WHERE Id IN ({1});"; 65 #endregion 55 66 } 56 67 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimJobDao.cs
r12516 r12691 29 29 30 30 public override DimJob GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.JobId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 33 … … 43 43 return Table.Where(x => x.DateCompleted != null); 44 44 } 45 46 #region Compiled queries 47 private static readonly Func<DataContext, Guid, DimJob> GetByIdQuery = 48 CompiledQuery.Compile((DataContext db, Guid id) => 49 (from dimJob in db.GetTable<DimJob>() 50 where dimJob.JobId == id 51 select dimJob).SingleOrDefault()); 52 #endregion 45 53 } 46 54 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimTimeDao.cs
r12468 r12691 29 29 30 30 public override DimTime GetById(DateTime id) { 31 return Table.SingleOrDefault(x => x.Time ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 33 public DimTime GetLastEntry() { 34 return Table.OrderByDescending(x => x.Time).FirstOrDefault();34 return GetLastEntryQuery(DataContext); 35 35 } 36 37 #region Compiled queries 38 private static readonly Func<DataContext, DateTime, DimTime> GetByIdQuery = 39 CompiledQuery.Compile((DataContext db, DateTime id) => 40 (from dimTime in db.GetTable<DimTime>() 41 where dimTime.Time == id 42 select dimTime).SingleOrDefault()); 43 44 private static readonly Func<DataContext, DimTime> GetLastEntryQuery = 45 CompiledQuery.Compile((DataContext db) => 46 (from dimTime in db.GetTable<DimTime>() 47 orderby dimTime.Time descending 48 select dimTime).FirstOrDefault()); 49 #endregion 36 50 } 37 51 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimUserDao.cs
r12468 r12691 29 29 30 30 public override DimUser GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.UserId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, DimUser> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid id) => 37 (from dimUser in db.GetTable<DimUser>() 38 where dimUser.UserId == id 39 select dimUser).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/FactClientInfoDao.cs
r12516 r12691 53 53 return from cf in Table 54 54 join r in DimClientTable on cf.ClientId equals r.Id 55 group cf by r.ResourceId into grpFacts 56 select new LastUpdateTimestamp { 57 ResourceId = grpFacts.Key, 58 Timestamp = grpFacts.Max(x => x.Time), 59 }; 55 group cf by r.ResourceId 56 into grpFacts 57 select new LastUpdateTimestamp { 58 ResourceId = grpFacts.Key, 59 Timestamp = grpFacts.Max(x => x.Time), 60 }; 60 61 } 61 62 -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/FactTaskDao.cs
r12551 r12691 37 37 } 38 38 39 private const string BatchDeleteQuery =40 @"DELETE FROM [statistics].[FactTask]41 WHERE TaskId IN ({0});";42 39 public FactTaskDao(DataContext dataContext) : base(dataContext) { } 43 40 44 41 public override FactTask GetById(Guid id) { 45 return Table.SingleOrDefault(x => x.TaskId ==id);42 return GetByIdQuery(DataContext, id); 46 43 } 47 44 … … 55 52 56 53 public DateTime? GetLastCompletedTaskFromJob(Guid id) { 57 return Table.Where(x => x.JobId == id && x.EndTime != null).Max(x => x.EndTime);54 return GetLastCompletedTaskFromJobQuery(DataContext, id); 58 55 } 59 56 … … 92 89 } 93 90 91 #region Compiled queries 92 private static readonly Func<DataContext, Guid, FactTask> GetByIdQuery = 93 CompiledQuery.Compile((DataContext db, Guid id) => 94 (from factTask in db.GetTable<FactTask>() 95 where factTask.TaskId == id 96 select factTask).SingleOrDefault()); 97 98 99 private static readonly Func<DataContext, Guid, DateTime?> GetLastCompletedTaskFromJobQuery = 100 CompiledQuery.Compile((DataContext db, Guid id) => 101 (from factTask in db.GetTable<FactTask>() 102 where factTask.JobId == id && factTask.EndTime != null 103 select factTask.EndTime).Max()); 104 #endregion 105 106 #region String queries 107 private const string BatchDeleteQuery = 108 @"DELETE FROM [statistics].[FactTask] 109 WHERE TaskId IN ({0});"; 110 #endregion 94 111 } 95 112 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobDao.cs
r12468 r12691 29 29 30 30 public override Job GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.JobId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, Job> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid jobId) => 37 (from job in db.GetTable<Job>() 38 where job.JobId == jobId 39 select job).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobPermissionDao.cs
r12584 r12691 33 33 34 34 public JobPermission GetByJobAndUserId(Guid jobId, Guid userId) { 35 return Table.SingleOrDefault(x => x.JobId == jobId && x.GrantedUserId ==userId);35 return GetByJobAndUserIdQuery(DataContext, jobId, userId); 36 36 } 37 38 public IQueryable<JobPermission> GetByJobId(Guid jobId) { 39 return Table.Where(x => x.JobId == jobId); 40 } 41 42 public void SetJobPermission(Guid jobId, Guid grantedByUserId, Guid grantedUserId, Permission permission) { 43 var jobPermission = GetByJobAndUserId(jobId, grantedUserId); 44 if (jobPermission != null) { 45 if (permission == Permission.NotAllowed) { 46 Delete(jobPermission); 47 } else { 48 jobPermission.Permission = permission; 49 jobPermission.GrantedByUserId = grantedByUserId; 50 } 51 } else { 52 if (permission != Permission.NotAllowed) { 53 Save(new JobPermission { 54 JobId = jobId, 55 GrantedByUserId = grantedByUserId, 56 GrantedUserId = grantedUserId, 57 Permission = permission 58 }); 59 } 60 } 61 } 62 63 #region Compiled queries 64 private static readonly Func<DataContext, Guid, Guid, JobPermission> GetByJobAndUserIdQuery = 65 CompiledQuery.Compile((DataContext db, Guid jobId, Guid userId) => 66 (from jobPermission in db.GetTable<JobPermission>() 67 where jobPermission.JobId == jobId && jobPermission.GrantedUserId == userId 68 select jobPermission).SingleOrDefault()); 69 #endregion 37 70 } 38 71 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/LifecycleDao.cs
r12468 r12691 20 20 #endregion 21 21 22 using System; 22 23 using System.Data.Linq; 23 24 using System.Linq; … … 28 29 29 30 public override Lifecycle GetById(int id) { 30 return Table.SingleOrDefault(x => x.LifecycleId ==id);31 return GetByIdQuery(DataContext, id); 31 32 } 33 34 public Lifecycle GetLastLifecycle() { 35 return GetLastLifecycleQuery(DataContext); 36 } 37 38 public void UpdateLifecycle() { 39 var entity = GetLastLifecycle(); 40 if (entity != null) { 41 entity.LastCleanup = DateTime.Now; 42 } else { 43 Save(new Lifecycle { 44 LifecycleId = 0, 45 LastCleanup = DateTime.Now 46 }); 47 } 48 } 49 50 #region Compiled queries 51 private static readonly Func<DataContext, int, Lifecycle> GetByIdQuery = 52 CompiledQuery.Compile((DataContext db, int lifecycleId) => 53 (from lifecycle in db.GetTable<Lifecycle>() 54 where lifecycle.LifecycleId == lifecycleId 55 select lifecycle).SingleOrDefault()); 56 57 private static readonly Func<DataContext, Lifecycle> GetLastLifecycleQuery = 58 CompiledQuery.Compile((DataContext db) => 59 (from lifecycle in db.GetTable<Lifecycle>() 60 select lifecycle).SingleOrDefault()); 61 #endregion 32 62 } 33 63 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/PluginDao.cs
r12468 r12691 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Data.Linq; 24 25 using System.Linq; … … 29 30 30 31 public override Plugin GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.PluginId ==id);32 return GetByIdQuery(DataContext, id); 32 33 } 34 35 public IEnumerable<Plugin> GetByHash(byte[] hash) { 36 return GetByHashQuery(DataContext).Where(x => x.Hash.SequenceEqual(hash)); 37 } 38 39 #region Compiled queries 40 private static readonly Func<DataContext, Guid, Plugin> GetByIdQuery = 41 CompiledQuery.Compile((DataContext db, Guid pluginId) => 42 (from plugin in db.GetTable<Plugin>() 43 where plugin.PluginId == pluginId 44 select plugin).SingleOrDefault()); 45 46 private static readonly Func<DataContext, IEnumerable<Plugin>> GetByHashQuery = 47 CompiledQuery.Compile((DataContext db) => 48 (from plugin in db.GetTable<Plugin>() 49 where plugin.Hash != null 50 select plugin)); 51 #endregion 33 52 } 34 53 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/PluginDataDao.cs
r12468 r12691 29 29 30 30 public override PluginData GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.PluginDataId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, PluginData> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid pluginDataId) => 37 (from pluginData in db.GetTable<PluginData>() 38 where pluginData.PluginDataId == pluginDataId 39 select pluginData).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/RequiredPluginDao.cs
r12468 r12691 29 29 30 30 public override RequiredPlugin GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.RequiredPluginId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, RequiredPlugin> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid requiredPluginId) => 37 (from requiredPlugin in db.GetTable<RequiredPlugin>() 38 where requiredPlugin.RequiredPluginId == requiredPluginId 39 select requiredPlugin).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourceDao.cs
r12468 r12691 29 29 30 30 public override Resource GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.ResourceId == id); 31 return GetByIdQuery(DataContext, id); 32 } 33 34 public Resource GetByName(string name) { 35 return GetByNameQuery(DataContext, name); 32 36 } 33 37 … … 35 39 return Table.Where(x => x.OwnerUserId != null); 36 40 } 41 42 #region Compiled queries 43 private static readonly Func<DataContext, Guid, Resource> GetByIdQuery = 44 CompiledQuery.Compile((DataContext db, Guid resourceId) => 45 (from resource in db.GetTable<Resource>() 46 where resource.ResourceId == resourceId 47 select resource).SingleOrDefault()); 48 49 private static readonly Func<DataContext, string, Resource> GetByNameQuery = 50 CompiledQuery.Compile((DataContext db, string name) => 51 (from resource in db.GetTable<Resource>() 52 where resource.Name == name 53 select resource).FirstOrDefault()); 54 #endregion 37 55 } 38 56 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourcePermissionDao.cs
r12468 r12691 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Data.Linq; 25 using System.Linq; 24 26 25 27 namespace HeuristicLab.Services.Hive.DataAccess.Daos { … … 30 32 throw new NotImplementedException(); 31 33 } 34 35 public IEnumerable<ResourcePermission> GetByResourceId(Guid id) { 36 return GetByResourceIdGetByIdQuery(DataContext, id); 37 } 38 39 public void DeleteByResourceAndGrantedUserId(Guid resourceId, IEnumerable<Guid> grantedUserId) { 40 string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x))); 41 if (!string.IsNullOrWhiteSpace(paramIds)) { 42 string query = string.Format(DeleteByGrantedUserQuery, resourceId, paramIds); 43 DataContext.ExecuteCommand(query); 44 } 45 } 46 47 #region Compiled queries 48 private static readonly Func<DataContext, Guid, IEnumerable<ResourcePermission>> GetByResourceIdGetByIdQuery = 49 CompiledQuery.Compile((DataContext db, Guid resourceId) => 50 from resourcePermission in db.GetTable<ResourcePermission>() 51 where resourcePermission.ResourceId == resourceId 52 select resourcePermission); 53 #endregion 54 55 #region String queries 56 private const string DeleteByGrantedUserQuery = 57 @"DELETE FROM [ResourcePermission] 58 WHERE ResourceId = '{0}' 59 AND GrantedUserId IN ({1});"; 60 #endregion 32 61 } 33 62 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/SlaveDao.cs
r12551 r12691 46 46 #region IGenericDao<Guid,Slave> Members 47 47 public Slave GetById(Guid id) { 48 return Entities.SingleOrDefault(x => x.ResourceId ==id);48 return GetByIdQuery(dataContext, id); 49 49 } 50 50 … … 117 117 118 118 public bool Exists(Slave entity) { 119 return Table.Contains(entity);119 return ExistsQuery(dataContext, entity); 120 120 } 121 121 … … 124 124 } 125 125 #endregion 126 127 public bool SlaveHasToShutdownComputer(Guid slaveId) { 128 return dataContext.ExecuteQuery<int>(DowntimeQueryString, slaveId, DateTime.Now, DowntimeType.Shutdown.ToString()).FirstOrDefault() > 0; 129 } 130 131 public bool SlaveIsAllowedToCalculate(Guid slaveId) { 132 return dataContext.ExecuteQuery<int>(DowntimeQueryString, slaveId, DateTime.Now, DowntimeType.Offline.ToString()).FirstOrDefault() == 0; 133 } 134 135 #region Compiled queries 136 private static readonly Func<DataContext, Guid, Slave> GetByIdQuery = 137 CompiledQuery.Compile((DataContext db, Guid slaveId) => 138 (from slave in db.GetTable<Resource>().OfType<Slave>() 139 where slave.ResourceId == slaveId 140 select slave).SingleOrDefault()); 141 142 private static readonly Func<DataContext, Slave, bool> ExistsQuery = 143 CompiledQuery.Compile((DataContext db, Slave entity) => 144 db.GetTable<Resource>().OfType<Slave>().Contains(entity)); 145 #endregion 146 147 #region String queries 148 private const string DowntimeQueryString = @" 149 WITH pr AS ( 150 SELECT ResourceId, ParentResourceId 151 FROM [Resource] 152 WHERE ResourceId = {0} 153 UNION ALL 154 SELECT r.ResourceId, r.ParentResourceId 155 FROM [Resource] r JOIN pr ON r.ResourceId = pr.ParentResourceId 156 ) 157 SELECT COUNT(dt.DowntimeId) 158 FROM pr JOIN [Downtime] dt ON pr.ResourceId = dt.ResourceId 159 WHERE {1} BETWEEN dt.StartDate AND dt.EndDate 160 AND dt.DowntimeType = {2} 161 "; 162 #endregion 126 163 } 127 164 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/SlaveGroupDao.cs
r12484 r12691 45 45 #region IGenericDao<Guid,SlaveGroup> Members 46 46 public SlaveGroup GetById(Guid id) { 47 return Entities.SingleOrDefault(x => x.ResourceId ==id);47 return GetByIdQuery(dataContext, id); 48 48 } 49 49 … … 112 112 113 113 public bool Exists(SlaveGroup entity) { 114 return Table.Contains(entity);114 return ExistsQuery(dataContext, entity); 115 115 } 116 116 … … 119 119 } 120 120 #endregion 121 122 #region Compiled queries 123 private static readonly Func<DataContext, Guid, SlaveGroup> GetByIdQuery = 124 CompiledQuery.Compile((DataContext db, Guid slaveGroupId) => 125 (from slaveGroup in db.GetTable<Resource>().OfType<SlaveGroup>() 126 where slaveGroup.ResourceId == slaveGroupId 127 select slaveGroup).SingleOrDefault()); 128 129 private static readonly Func<DataContext, SlaveGroup, bool> ExistsQuery = 130 CompiledQuery.Compile((DataContext db, SlaveGroup slaveGroup) => 131 db.GetTable<Resource>().OfType<SlaveGroup>().Contains(slaveGroup)); 132 #endregion 121 133 } 122 134 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/StateLogDao.cs
r12584 r12691 26 26 namespace HeuristicLab.Services.Hive.DataAccess.Daos { 27 27 public class StateLogDao : GenericDao<Guid, StateLog> { 28 29 28 private Table<Task> TaskTable { 30 29 get { return DataContext.GetTable<Task>(); } … … 34 33 35 34 public override StateLog GetById(Guid id) { 36 return Table.SingleOrDefault(x => x.StateLogId ==id);35 return GetByIdQuery(DataContext, id); 37 36 } 38 37 39 38 public StateLog GetLastStateLogFromTask(Task task) { 40 return Table 41 .Where(x => x.TaskId == task.TaskId) 42 .OrderByDescending(x => x.DateTime) 43 .First(x => x.SlaveId != null); 39 return GetLastStateLogFromTaskQuery(DataContext, task); 44 40 } 41 42 #region Compiled queries 43 private static readonly Func<DataContext, Guid, StateLog> GetByIdQuery = 44 CompiledQuery.Compile((DataContext db, Guid stateLogId) => 45 (from stateLog in db.GetTable<StateLog>() 46 where stateLog.StateLogId == stateLogId 47 select stateLog).SingleOrDefault()); 48 49 private static readonly Func<DataContext, Task, StateLog> GetLastStateLogFromTaskQuery = 50 CompiledQuery.Compile((DataContext db, Task task) => 51 (from stateLog in db.GetTable<StateLog>() 52 where stateLog.TaskId == task.TaskId 53 orderby stateLog.DateTime descending 54 select stateLog).First(x => x.SlaveId != null)); 55 #endregion 45 56 } 46 57 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
r12584 r12691 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Data.Linq; 24 25 using System.Linq; … … 29 30 30 31 public override Task GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.TaskId ==id);32 return GetByIdQuery(DataContext, id); 32 33 } 33 34 … … 39 40 return Table.Where(x => x.JobId == id); 40 41 } 42 public class TaskPriorityInfo { 43 public Guid JobId { get; set; } 44 public Guid TaskId { get; set; } 45 public int Priority { get; set; } 46 } 47 48 public IEnumerable<TaskPriorityInfo> GetWaitingTasks(Slave slave) { 49 //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);). 50 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated), 51 //we skip this step because it's wasted runtime 52 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, slave.ResourceId, Enum.GetName(typeof(TaskState), TaskState.Waiting), slave.FreeCores, slave.FreeMemory).ToList(); 53 } 54 55 public void UpdateExecutionTime(Guid taskId, double executionTime) { 56 DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId); 57 } 58 59 #region Compiled queries 60 private static readonly Func<DataContext, Guid, Task> GetByIdQuery = 61 CompiledQuery.Compile((DataContext db, Guid taskId) => 62 (from task in db.GetTable<Task>() 63 where task.TaskId == taskId 64 select task).SingleOrDefault()); 65 #endregion 66 67 #region String queries 68 private const string GetWaitingTasksQueryString = @" 69 WITH pr AS ( 70 SELECT ResourceId, ParentResourceId 71 FROM [Resource] 72 WHERE ResourceId = {0} 73 UNION ALL 74 SELECT r.ResourceId, r.ParentResourceId 75 FROM [Resource] r JOIN pr ON r.ResourceId = pr.ParentResourceId 76 ) 77 SELECT DISTINCT t.TaskId, t.JobId, t.Priority 78 FROM pr JOIN AssignedResources ar ON ar.ResourceId = pr.ResourceId 79 JOIN Task t ON t.TaskId = ar.TaskId 80 WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1) 81 AND t.TaskState = {1} 82 AND t.CoresNeeded <= {2} 83 AND t.MemoryNeeded <= {3} 84 "; 85 86 private const string UpdateExecutionTimeQuery = @" 87 UPDATE [Task] 88 SET ExecutionTimeMs = {0}, 89 LastHeartbeat = {1} 90 WHERE TaskId = {2} 91 "; 92 #endregion 41 93 } 42 94 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDataDao.cs
r12468 r12691 29 29 30 30 public override TaskData GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.TaskId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, TaskData> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid taskId) => 37 (from taskData in db.GetTable<TaskData>() 38 where taskData.TaskId == taskId 39 select taskData).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/UserPriorityDao.cs
r12468 r12691 29 29 30 30 public override UserPriority GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.UserId ==id);31 return GetByIdQuery(DataContext, id); 32 32 } 33 34 #region Compiled queries 35 private static readonly Func<DataContext, Guid, UserPriority> GetByIdQuery = 36 CompiledQuery.Compile((DataContext db, Guid userId) => 37 (from userPriority in db.GetTable<UserPriority>() 38 where userPriority.UserId == userId 39 select userPriority).SingleOrDefault()); 40 #endregion 33 41 } 34 42 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs
r12468 r12691 35 35 36 36 #region Hive daos 37 38 private AssignedResourceDao assignedResourceDao; 37 39 public AssignedResourceDao AssignedResourceDao { 38 get { return new AssignedResourceDao(dataContext); } 39 } 40 40 get { return assignedResourceDao ?? (assignedResourceDao = new AssignedResourceDao(dataContext)); } 41 } 42 43 private DowntimeDao downtimeDao; 41 44 public DowntimeDao DowntimeDao { 42 get { return new DowntimeDao(dataContext); } 43 } 44 45 get { return downtimeDao ?? (downtimeDao = new DowntimeDao(dataContext)); } 46 } 47 48 private JobDao jobDao; 45 49 public JobDao JobDao { 46 get { return new JobDao(dataContext); } 47 } 48 50 get { return jobDao ?? (jobDao = new JobDao(dataContext)); } 51 } 52 53 private JobPermissionDao jobPermissionDao; 49 54 public JobPermissionDao JobPermissionDao { 50 get { return new JobPermissionDao(dataContext); } 51 } 52 55 get { return jobPermissionDao ?? (jobPermissionDao = new JobPermissionDao(dataContext)); } 56 } 57 58 private LifecycleDao lifecycleDao; 53 59 public LifecycleDao LifecycleDao { 54 get { return new LifecycleDao(dataContext); } 55 } 56 60 get { return lifecycleDao ?? (lifecycleDao = new LifecycleDao(dataContext)); } 61 } 62 63 private PluginDao pluginDao; 57 64 public PluginDao PluginDao { 58 get { return new PluginDao(dataContext); } 59 } 60 65 get { return pluginDao ?? (pluginDao = new PluginDao(dataContext)); } 66 } 67 68 private PluginDataDao pluginDataDao; 61 69 public PluginDataDao PluginDataDao { 62 get { return new PluginDataDao(dataContext); } 63 } 64 70 get { return pluginDataDao ?? (pluginDataDao = new PluginDataDao(dataContext)); } 71 } 72 73 private RequiredPluginDao requiredPluginDao; 65 74 public RequiredPluginDao RequiredPluginDao { 66 get { return new RequiredPluginDao(dataContext); } 67 } 68 75 get { return requiredPluginDao ?? (requiredPluginDao = new RequiredPluginDao(dataContext)); } 76 } 77 78 private ResourceDao resourceDao; 69 79 public ResourceDao ResourceDao { 70 get { return new ResourceDao(dataContext); } 71 } 72 80 get { return resourceDao ?? (resourceDao = new ResourceDao(dataContext)); } 81 } 82 83 private ResourcePermissionDao resourcePermissionDao; 73 84 public ResourcePermissionDao ResourcePermissionDao { 74 get { return new ResourcePermissionDao(dataContext); } 75 } 76 85 get { return resourcePermissionDao ?? (resourcePermissionDao = new ResourcePermissionDao(dataContext)); } 86 } 87 88 private SlaveDao slaveDao; 77 89 public SlaveDao SlaveDao { 78 get { return new SlaveDao(dataContext); } 79 } 80 90 get { return slaveDao ?? (slaveDao = new SlaveDao(dataContext)); } 91 } 92 93 private SlaveGroupDao slaveGroupDao; 81 94 public SlaveGroupDao SlaveGroupDao { 82 get { return new SlaveGroupDao(dataContext); } 83 } 84 95 get { return slaveGroupDao ?? (slaveGroupDao = new SlaveGroupDao(dataContext)); } 96 } 97 98 private StateLogDao stateLogDao; 85 99 public StateLogDao StateLogDao { 86 get { return new StateLogDao(dataContext); } 87 } 88 100 get { return stateLogDao ?? (stateLogDao = new StateLogDao(dataContext)); } 101 } 102 103 private TaskDao taskDao; 89 104 public TaskDao TaskDao { 90 get { return new TaskDao(dataContext); } 91 } 92 105 get { return taskDao ?? (taskDao = new TaskDao(dataContext)); } 106 } 107 108 private TaskDataDao taskDataDao; 93 109 public TaskDataDao TaskDataDao { 94 get { return new TaskDataDao(dataContext); } 95 } 96 110 get { return taskDataDao ?? (taskDataDao = new TaskDataDao(dataContext)); } 111 } 112 113 private UserPriorityDao userPriorityDao; 97 114 public UserPriorityDao UserPriorityDao { 98 get { return new UserPriorityDao(dataContext); }115 get { return userPriorityDao ?? (userPriorityDao = new UserPriorityDao(dataContext)); } 99 116 } 100 117 #endregion 101 118 102 119 #region HiveStatistics daos 120 121 private DimClientDao dimClientDao; 103 122 public DimClientDao DimClientDao { 104 get { return new DimClientDao(dataContext); } 105 } 106 123 get { return dimClientDao ?? (dimClientDao = new DimClientDao(dataContext)); } 124 } 125 126 private DimJobDao dimJobDao; 107 127 public DimJobDao DimJobDao { 108 get { return new DimJobDao(dataContext); } 109 } 110 128 get { return dimJobDao ?? (dimJobDao = new DimJobDao(dataContext)); } 129 } 130 131 private DimTimeDao dimTimeDao; 111 132 public DimTimeDao DimTimeDao { 112 get { return new DimTimeDao(dataContext); } 113 } 114 133 get { return dimTimeDao ?? (dimTimeDao = new DimTimeDao(dataContext)); } 134 } 135 136 private DimUserDao dimUserDao; 115 137 public DimUserDao DimUserDao { 116 get { return new DimUserDao(dataContext); } 117 } 118 138 get { return dimUserDao ?? (dimUserDao = new DimUserDao(dataContext)); } 139 } 140 141 private FactClientInfoDao factClientInfoDao; 119 142 public FactClientInfoDao FactClientInfoDao { 120 get { return new FactClientInfoDao(dataContext); } 121 } 122 143 get { return factClientInfoDao ?? (factClientInfoDao = new FactClientInfoDao(dataContext)); } 144 } 145 146 private FactTaskDao factTaskDao; 123 147 public FactTaskDao FactTaskDao { 124 get { return new FactTaskDao(dataContext); }148 get { return factTaskDao ?? (factTaskDao = new FactTaskDao(dataContext)); } 125 149 } 126 150 #endregion … … 130 154 if (longRunning) context.CommandTimeout = (int)Settings.Default.LongRunningDatabaseCommandTimeout.TotalSeconds; 131 155 dataContext = context; 156 } 157 158 public PersistenceManager(DataContext dataContext) { 159 this.dataContext = dataContext; 132 160 } 133 161 … … 179 207 180 208 public void Dispose() { 181 if (dataContext != null) {182 dataContext.Dispose();183 }209 //if (dataContext != null) { 210 // dataContext.Dispose(); 211 //} 184 212 } 185 213 }
Note: See TracChangeset
for help on using the changeset viewer.