Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/HiveExperimentDao.cs @ 5048

Last change on this file since 5048 was 4424, checked in by cneumuel, 14 years ago
  • Added and updated License Information in every file
  • Sort and remove usings in every file
  • Deleted obsolete DataAccess.ADOHelper
  • Deleted some obsolete files
File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Linq;
25using HeuristicLab.Hive.Contracts.BusinessObjects;
26using HeuristicLab.Hive.Server.DataAccess;
27
28namespace HeuristicLab.Hive.Server.LINQDataAccess {
29  public class HiveExperimentDao : BaseDao<HiveExperimentDto, HiveExperiment>, IHiveExperimentDao {
30    #region IGenericDao<HiveExperimentDto> Members
31
32    HiveExperimentDto IGenericDao<HiveExperimentDto>.FindById(Guid id) {
33      return (from he in Context.HiveExperiments
34              where he.HiveExperimentId.Equals(id)
35              select EntityToDto(he, null)).SingleOrDefault();
36    }
37
38    IEnumerable<HiveExperimentDto> IGenericDao<HiveExperimentDto>.FindAll() {
39      return (from he in Context.HiveExperiments
40              select EntityToDto(he, null)).ToList();
41    }
42
43    public HiveExperimentDto Insert(HiveExperimentDto bObj) {
44      HiveExperiment he = DtoToEntity(bObj, null);
45      Context.HiveExperiments.InsertOnSubmit(he);
46      CommitChanges();
47      bObj.Id = he.HiveExperimentId;
48      return bObj;
49    }
50
51    public void Delete(Guid id) {
52      HiveExperiment he = Context.HiveExperiments.SingleOrDefault(h => h.HiveExperimentId.Equals(id));
53      Context.HiveExperiments.DeleteOnSubmit(he);
54      Context.SubmitChanges();
55    }
56
57    public void Update(HiveExperimentDto bObj) {
58      HiveExperiment he = Context.HiveExperiments.SingleOrDefault(h => h.HiveExperimentId.Equals(bObj.Id));
59      DtoToEntity(bObj, he);
60      CommitChanges();
61    }
62
63    public IEnumerable<HiveExperimentDto> FindAllByUserId(Guid userId) {
64      return (from he in Context.HiveExperiments
65                where he.UserId.Equals(userId)
66                select EntityToDto(he, null)).ToList();
67    }
68
69    #endregion
70
71    public override HiveExperiment DtoToEntity(HiveExperimentDto source, HiveExperiment target) {
72      if (source == null)
73        return null;
74      if (target == null)
75        target = new HiveExperiment();
76
77      target.HiveExperimentId = source.Id;
78      target.Name = source.Name;
79      target.Description = source.Description;
80      target.ResourceIds = source.ResourceIds;
81      target.UserId = source.UserId;
82
83      target.RootJobId = source.RootJobId;
84      //if (source.RootJobId.HasValue) {
85      //  var jobDao = new JobDao();
86      //  target.RootJob = jobDao.DtoToEntity(jobDao.FindById(source.RootJobId.Value), null);
87      //} else {
88      //  target.RootJob = null;
89      //}
90     
91      return target;
92    }
93
94    public override HiveExperimentDto EntityToDto(HiveExperiment source, HiveExperimentDto target) {
95      if (source == null)
96        return null;
97      if (target == null)
98        target = new HiveExperimentDto();
99
100      target.Id = source.HiveExperimentId;
101      target.Name = source.Name;
102      target.Description = source.Description;
103      target.ResourceIds = source.ResourceIds;
104      target.UserId = source.UserId;
105      target.RootJobId = source.RootJobId;
106
107      return target;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.