Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/PluginInfoDao.cs @ 3114

Last change on this file since 3114 was 3011, checked in by kgrading, 15 years ago

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

File size: 3.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Contracts.BusinessObjects;
6using HeuristicLab.Hive.Server.DataAccess;
7
8namespace HeuristicLab.Hive.Server.LINQDataAccess {
9  public class PluginInfoDao: BaseDao<HivePluginInfoDto, PluginInfo>, IPluginInfoDao {
10    #region IGenericDao<HivePluginInfoDto,PluginInfo> Members
11
12    public HivePluginInfoDto FindById(Guid id) {
13      return (from pi in Context.PluginInfos
14              where pi.PluginId.Equals(id)
15              select EntityToDto(pi, null)
16             ).SingleOrDefault(); 
17    }
18
19    public IEnumerable<HivePluginInfoDto> FindAll() {
20      return (from pi in Context.PluginInfos             
21              select EntityToDto(pi, null)
22       ).ToList(); 
23    }
24
25    public HivePluginInfoDto Insert(HivePluginInfoDto bObj) {
26      PluginInfo pi = DtoToEntity(bObj, null);
27      Context.PluginInfos.InsertOnSubmit(pi);
28      Context.SubmitChanges();
29      bObj.Id = pi.PluginId;
30      return bObj;
31    }
32
33    public void Delete(HivePluginInfoDto bObj) {
34      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
35      Context.PluginInfos.DeleteOnSubmit(pi);     
36    }
37
38    public void Update(HivePluginInfoDto bObj) {
39      PluginInfo pi = Context.PluginInfos.SingleOrDefault(p => p.PluginId.Equals(bObj.Id));
40      DtoToEntity(bObj, pi);
41      Context.SubmitChanges();
42    }
43
44    public void InsertPluginDependenciesForJob(JobDto jobDto) {
45      foreach (HivePluginInfoDto info in jobDto.PluginsNeeded) {       
46        PluginInfo dbpi =
47          Context.PluginInfos.Where(pi => pi.Name.Equals(info.Name) && pi.Version == info.Version).SingleOrDefault();
48        if (dbpi == null) {
49          dbpi = new PluginInfo {
50                                  BuildDate = info.BuildDate.ToString(),
51                                  Name = info.Name,
52                                  Version = info.Version
53                                };
54          Context.PluginInfos.InsertOnSubmit(dbpi);
55          Context.SubmitChanges();
56        }
57
58        RequiredPlugin rq = new RequiredPlugin();
59        rq.JobId = jobDto.Id;
60        rq.PluginInfo = dbpi;
61        Context.RequiredPlugins.InsertOnSubmit(rq);
62        Context.SubmitChanges();
63      }
64    }
65
66    #endregion
67
68    // Build Date not mapped - won't matter anyway, it's a obsolete field.
69    public override PluginInfo DtoToEntity(HivePluginInfoDto source, PluginInfo target) {
70      if (source == null)
71        return null;
72      if (target == null)
73        target = new PluginInfo();
74
75      target.Name = source.Name;
76      target.PluginId = source.Id;
77      target.Version = source.Version;     
78
79      return target;
80
81    }
82
83    public override HivePluginInfoDto EntityToDto(PluginInfo source, HivePluginInfoDto target) {
84      if (source == null)
85        return null;
86      if (target == null)
87        target = new HivePluginInfoDto();
88
89      target.Name = source.Name;
90      target.Id = source.PluginId;
91      target.Version = source.Version;
92
93      return target;
94    }
95  }
96}
Note: See TracBrowser for help on using the repository browser.