Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs @ 15508

Last change on this file since 15508 was 15508, checked in by jzenisek, 5 years ago

#2839 finalized permission checks in AddTask and revised implementation of ResourcePermission methods

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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.Collections.Generic;
24using System.Data.Linq;
25using System.Linq;
26
27namespace HeuristicLab.Services.Hive.DataAccess.Daos {
28  public class ProjectDao : GenericDao<Guid, Project> {
29    public ProjectDao(DataContext dataContext) : base(dataContext) { }
30
31    public override Project GetById(Guid id) {
32      return GetByIdQuery(DataContext, id);
33    }
34
35    public IEnumerable<Project> GetProjectsByChildId(Guid id) {
36      return DataContext.ExecuteQuery<Project>(GetProjectsByChildIdQuery, id);
37    }
38
39    public IEnumerable<Guid> GetProjectIdsByChildId(Guid id) {
40      return DataContext.ExecuteQuery<Guid>(GetProjectIdsByChildIdQuery, id);
41    }
42
43    #region Compiled queries
44    private static readonly Func<DataContext, Guid, Project> GetByIdQuery =
45      CompiledQuery.Compile((DataContext db, Guid projectId) =>
46        (from project in db.GetTable<Project>()
47         where project.ProjectId == projectId
48         select project).SingleOrDefault());
49    #endregion
50
51    #region String queries
52    private const string GetProjectsByChildIdQuery = @"
53      WITH ptree AS
54      (
55        SELECT ProjectId, ParentProjectId
56        FROM [Project]
57        UNION ALL
58        SELECT pt.ProjectId, p.ParentProjectId
59        FROM [Project] p
60        JOIN ptree pt ON pt.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pt.ParentProjectId <> pt.ProjectId
61      )
62      SELECT DISTINCT pro.*
63      FROM ptree, [Project] pro
64      WHERE ptree.ProjectId = {0}
65      AND ptree.ParentProjectId = pro.ProjectId
66    ";
67    private const string GetProjectIdsByChildIdQuery = @"
68      WITH ptree AS
69      (
70        SELECT ProjectId, ParentProjectId
71        FROM [Project]
72        UNION ALL
73        SELECT pt.ProjectId, p.ParentProjectId
74        FROM [Project] p
75        JOIN ptree pt ON pt.ParentProjectId = p.ProjectId AND p.ParentProjectId <> p.ProjectId AND pt.ParentProjectId <> pt.ProjectId
76      )
77      SELECT DISTINCT ptree.ParentProjectId
78      FROM ptree
79      WHERE ptree.ProjectId = {0}
80    ";
81    #endregion
82  }
83}
Note: See TracBrowser for help on using the repository browser.