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 |
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Data.Linq;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Linq.Expressions;
|
---|
28 | using HeuristicLab.Services.Hive.DataAccess.Interfaces;
|
---|
29 |
|
---|
30 | namespace 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 | }
|
---|