Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/HiveStatistics/DimTimeDao.cs @ 14875

Last change on this file since 14875 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Data.Linq;
24using System.Linq;
25
26namespace HeuristicLab.Services.Hive.DataAccess.Daos.HiveStatistics {
27  public class DimTimeDao : GenericDao<DateTime, DimTime> {
28    public DimTimeDao(DataContext dataContext) : base(dataContext) { }
29
30    public override DimTime GetById(DateTime id) {
31      return GetByIdQuery(DataContext, id);
32    }
33
34    public DimTime GetLastEntry() {
35      return GetLastEntryQuery(DataContext);
36    }
37
38    public int DeleteUnusedTimes() {
39      return DataContext.ExecuteCommand(DeleteUnusedTimeEntriesStringQuery);
40    }
41
42    #region Compiled queries
43    private static readonly Func<DataContext, DateTime, DimTime> GetByIdQuery =
44      CompiledQuery.Compile((DataContext db, DateTime id) =>
45        (from dimTime in db.GetTable<DimTime>()
46         where dimTime.Time == id
47         select dimTime).SingleOrDefault());
48
49    private static readonly Func<DataContext, DimTime> GetLastEntryQuery =
50      CompiledQuery.Compile((DataContext db) =>
51        (from dimTime in db.GetTable<DimTime>()
52         orderby dimTime.Time descending
53         select dimTime).FirstOrDefault());
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
63  }
64}
Note: See TracBrowser for help on using the repository browser.