[12468] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12468] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Data.Linq;
|
---|
| 24 | using System.Linq;
|
---|
| 25 |
|
---|
| 26 | namespace 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) {
|
---|
[12691] | 31 | return GetByIdQuery(DataContext, id);
|
---|
[12468] | 32 | }
|
---|
[12761] | 33 |
|
---|
[12468] | 34 | public DimTime GetLastEntry() {
|
---|
[12691] | 35 | return GetLastEntryQuery(DataContext);
|
---|
[12468] | 36 | }
|
---|
[12691] | 37 |
|
---|
[12761] | 38 | public int DeleteUnusedTimes() {
|
---|
| 39 | return DataContext.ExecuteCommand(DeleteUnusedTimeEntriesStringQuery);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[12691] | 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
|
---|
[12761] | 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
|
---|
[12468] | 63 | }
|
---|
| 64 | }
|
---|