Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ClientGroupAdapter.cs @ 3080

Last change on this file since 3080 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: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Text;
26
27using HeuristicLab.Hive.Server.DataAccess;
28using HeuristicLab.Hive.Contracts.BusinessObjects;
29using System.Data;
30using HeuristicLab.DataAccess.ADOHelper;
31using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
32using System.Data.Common;
33using System.Data.SqlClient;
34using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
35
36namespace HeuristicLab.Hive.Server.ADODataAccess {
37  class ClientGroupAdapter :
38    DataAdapterBase<dsHiveServerTableAdapters.ClientGroupTableAdapter,
39    ClientGroupDto,
40    dsHiveServer.ClientGroupRow>,
41    IClientGroupAdapter {
42    #region Fields
43    private ManyToManyRelationHelper<
44      dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
45      dsHiveServer.ClientGroup_ResourceRow> manyToManyRelationHelper = null;
46
47    private ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
48      dsHiveServer.ClientGroup_ResourceRow> ManyToManyRelationHelper {
49      get {
50        if (manyToManyRelationHelper == null) {
51          manyToManyRelationHelper =
52            new ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
53              dsHiveServer.ClientGroup_ResourceRow>(new ClientGroup_ResourceAdapterWrapper(), 1);
54        }
55
56        manyToManyRelationHelper.Session = Session as Session;
57
58        return manyToManyRelationHelper;
59      }
60    }
61
62    private IResourceAdapter resourceAdapter = null;
63
64    private IResourceAdapter ResAdapter {
65      get {
66        if (resourceAdapter == null)
67          resourceAdapter =
68            this.Session.GetDataAdapter<ResourceDto, IResourceAdapter>();
69
70        return resourceAdapter;
71      }
72    }
73    #endregion
74
75    public ClientGroupAdapter():
76      base(new ClientGroupAdapterWrapper()) {
77    }
78
79    #region Overrides
80    protected override ClientGroupDto ConvertRow(dsHiveServer.ClientGroupRow row,
81      ClientGroupDto clientGroup) {
82      if (row != null && clientGroup != null) {
83        /*Parent - Permission Owner*/
84        clientGroup.Id = row.ResourceId;
85        ResAdapter.GetById(clientGroup);
86
87        ICollection<Guid> resources =
88          ManyToManyRelationHelper.GetRelationships(clientGroup.Id);
89
90        clientGroup.Resources.Clear();
91        foreach(Guid resource in resources) {
92          ResourceDto res =
93            ResAdapter.GetByIdPolymorphic(resource);
94
95            clientGroup.Resources.Add(res);         
96        }
97
98        return clientGroup;
99      } else
100        return null;
101    }
102
103    protected override dsHiveServer.ClientGroupRow ConvertObj(ClientGroupDto clientGroup,
104      dsHiveServer.ClientGroupRow row) {
105      if (clientGroup != null && row != null) {
106        row.ResourceId = clientGroup.Id;
107      }
108
109      return row;
110    }
111    #endregion
112
113    #region IClientGroupAdapter Members
114    protected override void doUpdate(ClientGroupDto group) {
115      if (group != null) {
116        ResAdapter.Update(group);
117
118        base.doUpdate(group);
119
120        List<Guid> relationships =
121          new List<Guid>();
122        foreach(ResourceDto res in group.Resources) {
123          ResAdapter.UpdatePolymorphic(res);
124
125          relationships.Add(res.Id);
126        }
127
128        ManyToManyRelationHelper.UpdateRelationships(group.Id,
129          relationships);
130      }
131    }
132
133    public ClientGroupDto GetByName(string name) {
134      ClientGroupDto group = new ClientGroupDto();
135      ResourceDto res =
136        ResAdapter.GetByName(name);
137
138      if (res != null) {
139        return GetById(res.Id);
140      }
141
142      return null;
143    }
144
145    public ICollection<ClientGroupDto> MemberOf(ResourceDto resource) {
146      if (resource != null) {
147        return base.FindMultiple(
148           delegate() {
149             return Adapter.GetDataByParentsOf(resource.Id);
150           }
151        );
152      }
153
154      return null;
155    }
156
157    protected override bool doDelete(ClientGroupDto group) {
158      if (group != null) {
159        //recursively delete all subgroups
160        foreach (ResourceDto res in group.Resources) {
161          if (res is ClientGroupDto) {
162            Delete(res as ClientGroupDto);
163          }
164        }
165
166        //delete all relationships
167        ManyToManyRelationHelper.UpdateRelationships(group.Id,
168          new List<Guid>());
169
170        return base.doDelete(group) &&
171          ResAdapter.Delete(group);
172      }
173
174      return false;
175    }
176
177    #endregion
178  }
179}
Note: See TracBrowser for help on using the repository browser.