Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/SlaveDao.cs @ 12484

Last change on this file since 12484 was 12484, checked in by dglaser, 9 years ago

#2388: Updated Hive, DataAccess and WebApp

HeuristicLab.Services.Hive.DataAccess:

  • Updated database statistics schema

HeuristicLab.Services.Hive:

  • Fixed event flag in HiveJanitor Service
  • Improved UpdateTaskFactsTable in the HiveStatisticsGenerator

HeuristicLab.Services.WebApp:

  • Updated Statistics DataController to match the new statistics schema
File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 SlaveDao : IGenericDao<Guid, Slave> {
32
33    private readonly DataContext dataContext;
34    private Table<Resource> Table {
35      get { return dataContext.GetTable<Resource>(); }
36    }
37
38    private IQueryable<Slave> Entities {
39      get { return Table.OfType<Slave>(); }
40    }
41
42    public SlaveDao(DataContext dataContext) {
43      this.dataContext = dataContext;
44    }
45
46    #region IGenericDao<Guid,Slave> Members
47    public Slave GetById(Guid id) {
48      return Entities.SingleOrDefault(x => x.ResourceId == id);
49    }
50
51    public IQueryable<Slave> Get(Expression<Func<Slave, bool>> predicate) {
52      return Entities.Where(predicate);
53    }
54
55    public IQueryable<Slave> GetAll() {
56      return Entities;
57    }
58
59    public Slave Save(Slave entity) {
60      Table.InsertOnSubmit(entity);
61      return entity;
62    }
63
64    public IEnumerable<Slave> Save(params Slave[] entities) {
65      return entities.Select(Save).ToList();
66    }
67
68    public IEnumerable<Slave> Save(IEnumerable<Slave> entities) {
69      return entities.Select(Save).ToList();
70    }
71
72    public Slave SaveOrAttach(Slave entity) {
73      if (Table.Contains(entity)) {
74        if (Table.GetOriginalEntityState(entity) == null) {
75          Table.Attach(entity);
76        }
77      } else {
78        Table.InsertOnSubmit(entity);
79      }
80      return entity;
81    }
82
83    public IEnumerable<Slave> SaveOrAttach(params Slave[] entities) {
84      return entities.Select(SaveOrAttach).ToList();
85    }
86
87    public IEnumerable<Slave> SaveOrAttach(IEnumerable<Slave> entities) {
88      return entities.Select(SaveOrAttach).ToList();
89    }
90
91    public void Delete(Guid id) {
92      Slave entity = GetById(id);
93      if (entity != null) {
94        Table.DeleteOnSubmit(entity);
95      }
96    }
97
98    public void Delete(IEnumerable<Guid> ids) {
99      foreach (var id in ids) {
100        Delete(id);
101      }
102    }
103
104    public void Delete(Slave entity) {
105      Table.DeleteOnSubmit(entity);
106    }
107
108    public void Delete(IEnumerable<Slave> entities) {
109      foreach (var entity in entities) {
110        Delete(entity);
111      }
112    }
113
114    public bool Exists(Slave entity) {
115      return Table.Contains(entity);
116    }
117
118    public bool Exists(Guid id) {
119      return GetById(id) != null;
120    }
121    #endregion
122  }
123}
Note: See TracBrowser for help on using the repository browser.