Changeset 16311 for branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobDao.cs
- Timestamp:
- 11/20/18 15:26:57 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/JobDao.cs
r16308 r16311 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Data.Linq; 24 25 using System.Linq; … … 32 33 } 33 34 35 public void DeleteByState(JobState state) { 36 DataContext.ExecuteCommand(DeleteByStateQueryString, Enum.GetName(typeof(JobState), state)); 37 } 38 39 public IEnumerable<Job> GetByProjectId(Guid id) { 40 return GetByProjectIdQuery(DataContext, id); 41 } 42 43 public IEnumerable<Job> GetByProjectIds(IEnumerable<Guid> projectIds) { 44 string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x))); 45 if(!string.IsNullOrWhiteSpace(paramProjectIds)) { 46 string queryString = string.Format(GetByProjectIdsQueryString, paramProjectIds); 47 return DataContext.ExecuteQuery<Job>(queryString); 48 } 49 return Enumerable.Empty<Job>(); 50 } 51 52 public IEnumerable<Job> GetByState(JobState state) { 53 return GetByStateQuery(DataContext, state); 54 } 55 56 public IEnumerable<Guid> GetJobIdsByState(JobState state) { 57 return GetJobIdsByStateQuery(DataContext, state); 58 } 59 60 public IEnumerable<Job> GetJobsReadyForDeletion() { 61 return GetJobsReadyForDeletionQuery(DataContext); 62 } 63 64 34 65 #region Compiled queries 35 66 private static readonly Func<DataContext, Guid, Job> GetByIdQuery = … … 38 69 where job.JobId == jobId 39 70 select job).SingleOrDefault()); 71 private static readonly Func<DataContext, Guid, IEnumerable<Job>> GetByProjectIdQuery = 72 CompiledQuery.Compile((DataContext db, Guid projectId) => 73 (from job in db.GetTable<Job>() 74 where job.ProjectId == projectId 75 select job)); 76 private static readonly Func<DataContext, JobState, IEnumerable<Job>> GetByStateQuery = 77 CompiledQuery.Compile((DataContext db, JobState jobState) => 78 (from job in db.GetTable<Job>() 79 where job.State == jobState 80 select job)); 81 private static readonly Func<DataContext, JobState, IEnumerable<Guid>> GetJobIdsByStateQuery = 82 CompiledQuery.Compile((DataContext db, JobState jobState) => 83 (from job in db.GetTable<Job>() 84 where job.State == jobState 85 select job.JobId)); 86 private static readonly Func<DataContext, IEnumerable<Job>> GetJobsReadyForDeletionQuery = 87 CompiledQuery.Compile((DataContext db) => 88 (from job in db.GetTable<Job>() 89 where job.State == JobState.StatisticsPending 90 && (from task in db.GetTable<Task>() 91 where task.JobId == job.JobId 92 select task.State == TaskState.Finished 93 || task.State == TaskState.Aborted 94 || task.State == TaskState.Failed).All(x => x) 95 select job)); 96 #endregion 97 98 #region String queries 99 private const string DeleteByStateQueryString = @" 100 DELETE FROM [Job] 101 WHERE JobState = {0} 102 "; 103 private const string GetStatisticsPendingJobs = @" 104 SELECT DISTINCT j.* 105 FROM [Job] j 106 WHERE j.JobState = 'StatisticsPending' 107 AND 'Calculating' NOT IN ( 108 SELECT t.TaskState 109 FROM [Task] t 110 WHERE t.JobId = j.JobId) 111 "; 112 private const string GetByProjectIdsQueryString = @" 113 SELECT DISTINCT j.* 114 FROM [Job] j 115 WHERE j.ProjectId IN ({0}) 116 "; 40 117 #endregion 41 118 }
Note: See TracChangeset
for help on using the changeset viewer.