Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3044_variableScaling/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/SlaveGroupDao.cs @ 18242

Last change on this file since 18242 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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
22
23using System;
24using System.Collections.Generic;
25using System.Data.Linq;
26using System.Linq;
27using System.Linq.Expressions;
28using HeuristicLab.Services.Hive.DataAccess.Interfaces;
29
30namespace HeuristicLab.Services.Hive.DataAccess.Daos {
31  public class SlaveGroupDao : IGenericDao<Guid, SlaveGroup> {
32    private readonly DataContext dataContext;
33    private Table<Resource> Table {
34      get { return dataContext.GetTable<Resource>(); }
35    }
36
37    private IQueryable<SlaveGroup> Entities {
38      get { return Table.OfType<SlaveGroup>(); }
39    }
40
41    public SlaveGroupDao(DataContext dataContext) {
42      this.dataContext = dataContext;
43    }
44
45    #region IGenericDao<Guid,SlaveGroup> Members
46    public SlaveGroup GetById(Guid id) {
47      return GetByIdQuery(dataContext, id);
48    }
49
50    public IQueryable<SlaveGroup> Get(Expression<Func<SlaveGroup, bool>> predicate) {
51      return Entities.Where(predicate);
52    }
53
54    public IQueryable<SlaveGroup> GetAll() {
55      return Entities;
56    }
57
58    public SlaveGroup Save(SlaveGroup entity) {
59      Table.InsertOnSubmit(entity);
60      return entity;
61    }
62
63    public IEnumerable<SlaveGroup> Save(params SlaveGroup[] entities) {
64      return entities.Select(Save).ToList();
65    }
66
67    public IEnumerable<SlaveGroup> Save(IEnumerable<SlaveGroup> entities) {
68      return entities.Select(Save).ToList();
69    }
70
71    public SlaveGroup SaveOrAttach(SlaveGroup entity) {
72      if (Table.Contains(entity)) {
73        if (Table.GetOriginalEntityState(entity) == null) {
74          Table.Attach(entity);
75        }
76      } else {
77        Table.InsertOnSubmit(entity);
78      }
79      return entity;
80    }
81
82    public IEnumerable<SlaveGroup> SaveOrAttach(params SlaveGroup[] entities) {
83      return entities.Select(SaveOrAttach).ToList();
84    }
85
86    public IEnumerable<SlaveGroup> SaveOrAttach(IEnumerable<SlaveGroup> entities) {
87      return entities.Select(SaveOrAttach).ToList();
88    }
89
90    public void Delete(Guid id) {
91      SlaveGroup entity = GetById(id);
92      if (entity != null) {
93        Table.DeleteOnSubmit(entity);
94      }
95    }
96
97    public void Delete(IEnumerable<Guid> ids) {
98      foreach (var id in ids) {
99        Delete(id);
100      }
101    }
102
103    public void Delete(SlaveGroup entity) {
104      Table.DeleteOnSubmit(entity);
105    }
106
107    public void Delete(IEnumerable<SlaveGroup> entities) {
108      foreach (var entity in entities) {
109        Delete(entity);
110      }
111    }
112
113    public bool Exists(SlaveGroup entity) {
114      return ExistsQuery(dataContext, entity);
115    }
116
117    public bool Exists(Guid id) {
118      return GetById(id) != null;
119    }
120    #endregion
121
122    #region Compiled queries
123    private static readonly Func<DataContext, Guid, SlaveGroup> GetByIdQuery =
124      CompiledQuery.Compile((DataContext db, Guid slaveGroupId) =>
125        (from slaveGroup in db.GetTable<Resource>().OfType<SlaveGroup>()
126         where slaveGroup.ResourceId == slaveGroupId
127         select slaveGroup).SingleOrDefault());
128
129    private static readonly Func<DataContext, SlaveGroup, bool> ExistsQuery =
130      CompiledQuery.Compile((DataContext db, SlaveGroup slaveGroup) =>
131        db.GetTable<Resource>().OfType<SlaveGroup>().Contains(slaveGroup));
132    #endregion
133  }
134}
Note: See TracBrowser for help on using the repository browser.