- Timestamp:
- 07/14/15 15:56:26 (9 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimTimeDao.cs
r12691 r12761 31 31 return GetByIdQuery(DataContext, id); 32 32 } 33 33 34 public DimTime GetLastEntry() { 34 35 return GetLastEntryQuery(DataContext); 36 } 37 38 public int DeleteUnusedTimes() { 39 return DataContext.ExecuteCommand(DeleteUnusedTimeEntriesStringQuery); 35 40 } 36 41 … … 48 53 select dimTime).FirstOrDefault()); 49 54 #endregion 55 56 #region String queries 57 private const string DeleteUnusedTimeEntriesStringQuery = @" 58 DELETE FROM [statistics].[DimTime] 59 WHERE NOT EXISTS (SELECT [Time] FROM [statistics].[FactClientInfo] fci 60 WHERE fci.[Time] = [statistics].[DimTime].[Time]); 61 "; 62 #endregion 50 63 } 51 64 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/FactTaskDao.cs
r12691 r12761 89 89 } 90 90 91 public void DeleteByJobId(Guid jobId) { 92 DataContext.ExecuteCommand(DeleteByJobIdQuery, jobId); 93 } 94 91 95 #region Compiled queries 92 96 private static readonly Func<DataContext, Guid, FactTask> GetByIdQuery = … … 108 112 @"DELETE FROM [statistics].[FactTask] 109 113 WHERE TaskId IN ({0});"; 114 115 private const string DeleteByJobIdQuery = 116 @"DELETE FROM [statistics].[FactTask] 117 WHERE JobId = {0};"; 110 118 #endregion 111 119 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/PluginDao.cs
r12691 r12761 37 37 } 38 38 39 public int DeleteUnusedPlugins() { 40 return DataContext.ExecuteCommand(DeleteUnusedPluginsStringQuery); 41 } 42 39 43 #region Compiled queries 40 44 private static readonly Func<DataContext, Guid, Plugin> GetByIdQuery = … … 50 54 select plugin)); 51 55 #endregion 56 57 #region String queries 58 private const string DeleteUnusedPluginsStringQuery = @" 59 DELETE FROM [Plugin] 60 WHERE [Plugin].[PluginId] NOT IN ( 61 SELECT DISTINCT rp.[PluginId] 62 FROM [RequiredPlugins] rp 63 WHERE EXISTS (SELECT [TaskId] 64 FROM [Task] t 65 WHERE t.[TaskId] = rp.[TaskId]) 66 ); 67 "; 68 #endregion 52 69 } 53 70 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj
r12468 r12761 127 127 <Compile Include="Daos\TaskDataDao.cs" /> 128 128 <Compile Include="Daos\UserPriorityDao.cs" /> 129 <Compile Include="Data\TableInformation.cs" /> 129 130 <Compile Include="Interfaces\IGenericDao.cs" /> 130 131 <Compile Include="Enums\Command.cs" /> -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs
r12468 r12761 24 24 using HeuristicLab.Services.Hive.DataAccess.Daos; 25 25 using HeuristicLab.Services.Hive.DataAccess.Daos.HiveStatistics; 26 using HeuristicLab.Services.Hive.DataAccess.Data; 26 27 27 28 namespace HeuristicLab.Services.Hive.DataAccess.Interfaces { … … 62 63 #endregion 63 64 65 TableInformation GetTableInformation(string table); 64 66 void SubmitChanges(); 65 67 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs
r12691 r12761 22 22 using System; 23 23 using System.Data.Linq; 24 using System.Linq; 24 25 using System.Transactions; 25 26 using HeuristicLab.Services.Hive.DataAccess.Daos; 26 27 using HeuristicLab.Services.Hive.DataAccess.Daos.HiveStatistics; 28 using HeuristicLab.Services.Hive.DataAccess.Data; 27 29 using HeuristicLab.Services.Hive.DataAccess.Interfaces; 28 30 … … 200 202 #endregion 201 203 204 // str.Remove(str.IndexOf(',')); 205 public TableInformation GetTableInformation(string table) { 206 string query = string.Format("sp_spaceused '{0}', @updateusage='true'", table); 207 var result = dataContext.ExecuteQuery<SqlServerTableInformation>(query).FirstOrDefault(); 208 if (result == null) return null; 209 return new TableInformation { 210 Name = result.Name, 211 Rows = int.Parse(result.Rows.Remove(result.Rows.IndexOf(' '))), 212 Reserved = int.Parse(result.Reserved.Remove(result.Reserved.IndexOf(' '))), 213 Data = int.Parse(result.Data.Remove(result.Data.IndexOf(' '))), 214 IndexSize = int.Parse(result.Index_Size.Remove(result.Index_Size.IndexOf(' '))), 215 Unused = int.Parse(result.Unused.Remove(result.Unused.IndexOf(' '))) 216 }; 217 } 218 202 219 public void SubmitChanges() { 203 220 if (dataContext != null) { … … 211 228 //} 212 229 } 230 231 private class SqlServerTableInformation { 232 public string Name { get; set; } 233 public string Rows { get; set; } 234 public string Reserved { get; set; } 235 public string Data { get; set; } 236 public string Index_Size { get; set; } // naming of sp_spaceused... 237 public string Unused { get; set; } 238 } 213 239 } 214 240 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql
r9665 r12761 182 182 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS 183 183 BEGIN 184 185 184 DELETE Task FROM deleted, Task WHERE deleted.JobId = Task.JobId 185 DELETE Job FROM deleted, Job WHERE deleted.JobId = Job.JobId 186 186 END 187 187 GO … … 194 194 CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS 195 195 BEGIN 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 196 -- add statistics 197 INSERT INTO dbo.DeletedJobStatistics (UserId, ExecutionTimeS, ExecutionTimeSFinishedJobs, StartToEndTimeS) 198 SELECT 199 he.OwnerUserId AS UserId, 200 ROUND(SUM(j.ExecutionTimeMs) / 1000, 0) AS ExecutionTimeS, 201 ROUND(ISNULL(SUM(CASE ls.State WHEN 'Finished' THEN j.ExecutionTimeMs END), 0) / 1000, 0) AS ExecutionTimeSFinishedJobs, 202 ISNULL(SUM(CASE ls.State WHEN 'Finished' THEN DATEDIFF(s, fs.DateTime, ls.DateTime) ELSE 0 END), 0) AS StartToEndTimeS 203 FROM 204 deleted j, 205 Job he, 206 view_FirstState fs, 207 view_LastState ls 208 WHERE 209 he.JobId = j.JobId AND 210 fs.TaskId = j.TaskId AND 211 ls.TaskId = j.TaskId 212 GROUP BY he.OwnerUserId 213 214 -- recursively delete jobs 215 CREATE TABLE #Table( 216 TaskId uniqueidentifier 217 ) 218 INSERT INTO #Table (TaskId) 219 SELECT TaskId FROM deleted 220 221 DECLARE @c INT 222 SET @c = 0 223 224 WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN 225 SELECT @c = COUNT(TaskId) FROM #Table 226 227 INSERT INTO #Table (TaskId) 228 SELECT Task.TaskId 229 FROM Task 230 LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId 231 WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table) 232 AND #Table.TaskId IS NULL 233 END 234 235 DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId 236 DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId 237 237 END 238 238 GO … … 241 241 CREATE TRIGGER [dbo].[tr_StatisticsDeleteCascade] ON [dbo].[Statistics] INSTEAD OF DELETE AS 242 242 BEGIN 243 244 245 243 DELETE SlaveStatistics FROM deleted, SlaveStatistics WHERE deleted.StatisticsId = SlaveStatistics.StatisticsId 244 -- should also remove UserStatistics here 245 DELETE [Statistics] FROM deleted, [Statistics] WHERE deleted.StatisticsId = [Statistics].StatisticsId 246 246 END 247 247 GO
Note: See TracChangeset
for help on using the changeset viewer.