[910] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 |
|
---|
[1377] | 27 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[910] | 28 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[965] | 29 | using System.Data;
|
---|
[1377] | 30 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
[1468] | 31 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
| 32 | using System.Data.Common;
|
---|
| 33 | using System.Data.SqlClient;
|
---|
[910] | 34 |
|
---|
| 35 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[1468] | 36 | class ClientGroupAdapterWrapper :
|
---|
| 37 | DataAdapterWrapperBase<dsHiveServerTableAdapters.ClientGroupTableAdapter,
|
---|
| 38 | ClientGroup,
|
---|
| 39 | dsHiveServer.ClientGroupRow> {
|
---|
| 40 | public override dsHiveServer.ClientGroupRow
|
---|
| 41 | InsertNewRow(ClientGroup group) {
|
---|
| 42 | dsHiveServer.ClientGroupDataTable data =
|
---|
| 43 | new dsHiveServer.ClientGroupDataTable();
|
---|
| 44 |
|
---|
| 45 | dsHiveServer.ClientGroupRow row =
|
---|
| 46 | data.NewClientGroupRow();
|
---|
| 47 |
|
---|
| 48 | row.ResourceId = group.Id;
|
---|
| 49 |
|
---|
| 50 | data.AddClientGroupRow(row);
|
---|
| 51 | TransactionalAdapter.Update(row);
|
---|
| 52 |
|
---|
| 53 | return row;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public override void
|
---|
| 57 | UpdateRow(dsHiveServer.ClientGroupRow row) {
|
---|
| 58 | TransactionalAdapter.Update(row);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public override IEnumerable<dsHiveServer.ClientGroupRow>
|
---|
| 62 | FindById(Guid id) {
|
---|
| 63 | return TransactionalAdapter.GetDataById(id);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public override IEnumerable<dsHiveServer.ClientGroupRow>
|
---|
| 67 | FindAll() {
|
---|
| 68 | return TransactionalAdapter.GetData();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected override void SetConnection(DbConnection connection) {
|
---|
| 72 | adapter.Connection = connection as SqlConnection;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void SetTransaction(DbTransaction transaction) {
|
---|
| 76 | adapter.Transaction = transaction as SqlTransaction;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
[1515] | 79 |
|
---|
| 80 | class ClientGroup_ResourceAdapterWrapper :
|
---|
| 81 | DataAdapterWrapperBase<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
| 82 | BinaryRelation,
|
---|
| 83 | dsHiveServer.ClientGroup_ResourceRow> {
|
---|
| 84 | public override dsHiveServer.ClientGroup_ResourceRow
|
---|
| 85 | InsertNewRow(BinaryRelation relation) {
|
---|
| 86 | dsHiveServer.ClientGroup_ResourceDataTable data =
|
---|
| 87 | new dsHiveServer.ClientGroup_ResourceDataTable();
|
---|
| 88 |
|
---|
| 89 | dsHiveServer.ClientGroup_ResourceRow row =
|
---|
| 90 | data.NewClientGroup_ResourceRow();
|
---|
| 91 |
|
---|
| 92 | row.ClientGroupId = relation.Id;
|
---|
| 93 | row.ResourceId = relation.Id2;
|
---|
| 94 |
|
---|
| 95 | data.AddClientGroup_ResourceRow(row);
|
---|
| 96 | TransactionalAdapter.Update(row);
|
---|
| 97 |
|
---|
| 98 | return row;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public override void
|
---|
| 102 | UpdateRow(dsHiveServer.ClientGroup_ResourceRow row) {
|
---|
| 103 | TransactionalAdapter.Update(row);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public override IEnumerable<dsHiveServer.ClientGroup_ResourceRow>
|
---|
| 107 | FindById(Guid id) {
|
---|
| 108 | return TransactionalAdapter.GetDataByClientGroupId(id);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | public override IEnumerable<dsHiveServer.ClientGroup_ResourceRow>
|
---|
| 112 | FindAll() {
|
---|
| 113 | return TransactionalAdapter.GetData();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | protected override void SetConnection(DbConnection connection) {
|
---|
| 117 | adapter.Connection = connection as SqlConnection;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | protected override void SetTransaction(DbTransaction transaction) {
|
---|
| 121 | adapter.Transaction = transaction as SqlTransaction;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
[1468] | 124 |
|
---|
[995] | 125 | class ClientGroupAdapter :
|
---|
| 126 | DataAdapterBase<dsHiveServerTableAdapters.ClientGroupTableAdapter,
|
---|
| 127 | ClientGroup,
|
---|
| 128 | dsHiveServer.ClientGroupRow>,
|
---|
| 129 | IClientGroupAdapter {
|
---|
| 130 | #region Fields
|
---|
[1515] | 131 | private BinaryRelationHelper<
|
---|
| 132 | dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
| 133 | dsHiveServer.ClientGroup_ResourceRow> binaryRelationHelper = null;
|
---|
[965] | 134 |
|
---|
[1515] | 135 | private BinaryRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
| 136 | dsHiveServer.ClientGroup_ResourceRow> BinaryRelationHelper {
|
---|
| 137 | get {
|
---|
| 138 | if (binaryRelationHelper == null) {
|
---|
| 139 | binaryRelationHelper =
|
---|
| 140 | new BinaryRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
| 141 | dsHiveServer.ClientGroup_ResourceRow>(new ClientGroup_ResourceAdapterWrapper());
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | binaryRelationHelper.Session = Session as Session;
|
---|
| 145 |
|
---|
| 146 | return binaryRelationHelper;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[965] | 150 | private IResourceAdapter resourceAdapter = null;
|
---|
| 151 |
|
---|
[971] | 152 | private IResourceAdapter ResAdapter {
|
---|
[965] | 153 | get {
|
---|
| 154 | if (resourceAdapter == null)
|
---|
[1468] | 155 | resourceAdapter =
|
---|
| 156 | this.Session.GetDataAdapter<Resource, IResourceAdapter>();
|
---|
[965] | 157 |
|
---|
| 158 | return resourceAdapter;
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | private IClientAdapter clientAdapter = null;
|
---|
| 163 |
|
---|
| 164 | private IClientAdapter ClientAdapter {
|
---|
| 165 | get {
|
---|
| 166 | if (clientAdapter == null)
|
---|
[1468] | 167 | clientAdapter =
|
---|
| 168 | this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[965] | 169 |
|
---|
| 170 | return clientAdapter;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
[995] | 173 | #endregion
|
---|
[965] | 174 |
|
---|
[1468] | 175 | public ClientGroupAdapter():
|
---|
| 176 | base(new ClientGroupAdapterWrapper()) {
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[995] | 179 | #region Overrides
|
---|
[1131] | 180 | protected override ClientGroup ConvertRow(dsHiveServer.ClientGroupRow row,
|
---|
[965] | 181 | ClientGroup clientGroup) {
|
---|
| 182 | if (row != null && clientGroup != null) {
|
---|
| 183 | /*Parent - Permission Owner*/
|
---|
[995] | 184 | clientGroup.Id = row.ResourceId;
|
---|
[1515] | 185 | ResAdapter.GetById(clientGroup.Id);
|
---|
[965] | 186 |
|
---|
[1515] | 187 | ICollection<Guid> resources =
|
---|
| 188 | BinaryRelationHelper.GetRelationships(clientGroup.Id);
|
---|
[965] | 189 |
|
---|
[1515] | 190 | clientGroup.Resources.Clear();
|
---|
| 191 | foreach(Guid resource in resources) {
|
---|
| 192 | ClientInfo client =
|
---|
| 193 | ClientAdapter.GetById(resource);
|
---|
[965] | 194 |
|
---|
[1515] | 195 | if (client == null) {
|
---|
| 196 | //client group
|
---|
| 197 | ClientGroup group =
|
---|
| 198 | GetById(resource);
|
---|
[965] | 199 |
|
---|
[1515] | 200 | clientGroup.Resources.Add(group);
|
---|
| 201 | } else {
|
---|
| 202 | clientGroup.Resources.Add(client);
|
---|
| 203 | }
|
---|
[965] | 204 | }
|
---|
| 205 |
|
---|
| 206 | return clientGroup;
|
---|
| 207 | } else
|
---|
| 208 | return null;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[1131] | 211 | protected override dsHiveServer.ClientGroupRow ConvertObj(ClientGroup clientGroup,
|
---|
[965] | 212 | dsHiveServer.ClientGroupRow row) {
|
---|
| 213 | if (clientGroup != null && row != null) {
|
---|
[995] | 214 | row.ResourceId = clientGroup.Id;
|
---|
[965] | 215 | }
|
---|
| 216 |
|
---|
| 217 | return row;
|
---|
| 218 | }
|
---|
[995] | 219 | #endregion
|
---|
[965] | 220 |
|
---|
[995] | 221 | #region IClientGroupAdapter Members
|
---|
[1468] | 222 | protected override void doUpdate(ClientGroup group) {
|
---|
[995] | 223 | if (group != null) {
|
---|
| 224 | ResAdapter.Update(group);
|
---|
| 225 |
|
---|
[1468] | 226 | base.doUpdate(group);
|
---|
[1515] | 227 |
|
---|
| 228 | List<Guid> relationships =
|
---|
| 229 | new List<Guid>();
|
---|
| 230 | foreach(Resource res in group.Resources) {
|
---|
| 231 | if (res is ClientInfo) {
|
---|
| 232 | ClientAdapter.Update(res as ClientInfo);
|
---|
| 233 | } else if (res is ClientGroup) {
|
---|
| 234 | Update(res as ClientGroup);
|
---|
| 235 | } else {
|
---|
| 236 | ResAdapter.Update(res);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | relationships.Add(res.Id);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | BinaryRelationHelper.UpdateRelationships(group.Id,
|
---|
| 243 | relationships);
|
---|
[965] | 244 | }
|
---|
[910] | 245 | }
|
---|
| 246 |
|
---|
[995] | 247 | public ClientGroup GetByName(string name) {
|
---|
[971] | 248 | ClientGroup group = new ClientGroup();
|
---|
| 249 | Resource res =
|
---|
[995] | 250 | ResAdapter.GetByName(name);
|
---|
[971] | 251 |
|
---|
| 252 | if (res != null) {
|
---|
[995] | 253 | return GetById(res.Id);
|
---|
[971] | 254 | }
|
---|
| 255 |
|
---|
| 256 | return null;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[965] | 259 | public ICollection<ClientGroup> MemberOf(Resource resource) {
|
---|
[1515] | 260 | throw new NotImplementedException();
|
---|
[965] | 261 | }
|
---|
| 262 |
|
---|
[1468] | 263 | protected override bool doDelete(ClientGroup group) {
|
---|
[965] | 264 | if (group != null) {
|
---|
[1515] | 265 | //delete all relationships
|
---|
| 266 | BinaryRelationHelper.UpdateRelationships(group.Id,
|
---|
| 267 | new List<Guid>());
|
---|
| 268 |
|
---|
[1468] | 269 | return base.doDelete(group) &&
|
---|
[995] | 270 | ResAdapter.Delete(group);
|
---|
[965] | 271 | }
|
---|
| 272 |
|
---|
| 273 | return false;
|
---|
[910] | 274 | }
|
---|
| 275 |
|
---|
| 276 | #endregion
|
---|
| 277 | }
|
---|
| 278 | }
|
---|