Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2388:

HeuristicLab.Services.Hive.DataAccess-3.3:

  • updated database schema
  • updated sql scripts
  • updated HiveStatisticsGenerator

HeuristicLab.Services.WebApp-3.3:

  • merged from trunk

HeuristicLab.Services.WebApp.Status-3.3:

  • updated data api controller

HeuristicLab.Services.WebApp.Statistics-3.3:

  • added exception page
  • improved jobs, clients, users and groups page
File size: 3.5 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 IQueryable<Slave> GetOnlineSlaves() {
60      return Entities.Where(x => x.SlaveState != SlaveState.Offline);
61    }
62
63    public Slave Save(Slave entity) {
64      Table.InsertOnSubmit(entity);
65      return entity;
66    }
67
68    public IEnumerable<Slave> Save(params Slave[] entities) {
69      return entities.Select(Save).ToList();
70    }
71
72    public IEnumerable<Slave> Save(IEnumerable<Slave> entities) {
73      return entities.Select(Save).ToList();
74    }
75
76    public Slave SaveOrAttach(Slave entity) {
77      if (Table.Contains(entity)) {
78        if (Table.GetOriginalEntityState(entity) == null) {
79          Table.Attach(entity);
80        }
81      } else {
82        Table.InsertOnSubmit(entity);
83      }
84      return entity;
85    }
86
87    public IEnumerable<Slave> SaveOrAttach(params Slave[] entities) {
88      return entities.Select(SaveOrAttach).ToList();
89    }
90
91    public IEnumerable<Slave> SaveOrAttach(IEnumerable<Slave> entities) {
92      return entities.Select(SaveOrAttach).ToList();
93    }
94
95    public void Delete(Guid id) {
96      Slave entity = GetById(id);
97      if (entity != null) {
98        Table.DeleteOnSubmit(entity);
99      }
100    }
101
102    public void Delete(IEnumerable<Guid> ids) {
103      foreach (var id in ids) {
104        Delete(id);
105      }
106    }
107
108    public void Delete(Slave entity) {
109      Table.DeleteOnSubmit(entity);
110    }
111
112    public void Delete(IEnumerable<Slave> entities) {
113      foreach (var entity in entities) {
114        Delete(entity);
115      }
116    }
117
118    public bool Exists(Slave entity) {
119      return Table.Contains(entity);
120    }
121
122    public bool Exists(Guid id) {
123      return GetById(id) != null;
124    }
125    #endregion
126  }
127}
Note: See TracBrowser for help on using the repository browser.