[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;
|
---|
[1580] | 34 | using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
|
---|
[910] | 35 |
|
---|
| 36 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[995] | 37 | class ClientGroupAdapter :
|
---|
| 38 | DataAdapterBase<dsHiveServerTableAdapters.ClientGroupTableAdapter,
|
---|
| 39 | ClientGroup,
|
---|
| 40 | dsHiveServer.ClientGroupRow>,
|
---|
| 41 | IClientGroupAdapter {
|
---|
| 42 | #region Fields
|
---|
[1580] | 43 | private ManyToManyRelationHelper<
|
---|
[1515] | 44 | dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
[1580] | 45 | dsHiveServer.ClientGroup_ResourceRow> manyToManyRelationHelper = null;
|
---|
[965] | 46 |
|
---|
[1580] | 47 | private ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
| 48 | dsHiveServer.ClientGroup_ResourceRow> ManyToManyRelationHelper {
|
---|
[1515] | 49 | get {
|
---|
[1580] | 50 | if (manyToManyRelationHelper == null) {
|
---|
| 51 | manyToManyRelationHelper =
|
---|
| 52 | new ManyToManyRelationHelper<dsHiveServerTableAdapters.ClientGroup_ResourceTableAdapter,
|
---|
[1758] | 53 | dsHiveServer.ClientGroup_ResourceRow>(new ClientGroup_ResourceAdapterWrapper(), 1);
|
---|
[1515] | 54 | }
|
---|
| 55 |
|
---|
[1580] | 56 | manyToManyRelationHelper.Session = Session as Session;
|
---|
[1515] | 57 |
|
---|
[1580] | 58 | return manyToManyRelationHelper;
|
---|
[1515] | 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[965] | 62 | private IResourceAdapter resourceAdapter = null;
|
---|
| 63 |
|
---|
[971] | 64 | private IResourceAdapter ResAdapter {
|
---|
[965] | 65 | get {
|
---|
| 66 | if (resourceAdapter == null)
|
---|
[1468] | 67 | resourceAdapter =
|
---|
| 68 | this.Session.GetDataAdapter<Resource, IResourceAdapter>();
|
---|
[965] | 69 |
|
---|
| 70 | return resourceAdapter;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
[995] | 73 | #endregion
|
---|
[965] | 74 |
|
---|
[1468] | 75 | public ClientGroupAdapter():
|
---|
| 76 | base(new ClientGroupAdapterWrapper()) {
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[995] | 79 | #region Overrides
|
---|
[1131] | 80 | protected override ClientGroup ConvertRow(dsHiveServer.ClientGroupRow row,
|
---|
[965] | 81 | ClientGroup clientGroup) {
|
---|
| 82 | if (row != null && clientGroup != null) {
|
---|
| 83 | /*Parent - Permission Owner*/
|
---|
[995] | 84 | clientGroup.Id = row.ResourceId;
|
---|
[1647] | 85 | ResAdapter.GetById(clientGroup);
|
---|
[965] | 86 |
|
---|
[1515] | 87 | ICollection<Guid> resources =
|
---|
[1758] | 88 | ManyToManyRelationHelper.GetRelationships(clientGroup.Id);
|
---|
[965] | 89 |
|
---|
[1656] | 90 | clientGroup.Resources.Clear();
|
---|
[1515] | 91 | foreach(Guid resource in resources) {
|
---|
[1597] | 92 | Resource res =
|
---|
| 93 | ResAdapter.GetByIdPolymorphic(resource);
|
---|
[965] | 94 |
|
---|
[1597] | 95 | clientGroup.Resources.Add(res);
|
---|
[965] | 96 | }
|
---|
| 97 |
|
---|
| 98 | return clientGroup;
|
---|
| 99 | } else
|
---|
| 100 | return null;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[1131] | 103 | protected override dsHiveServer.ClientGroupRow ConvertObj(ClientGroup clientGroup,
|
---|
[965] | 104 | dsHiveServer.ClientGroupRow row) {
|
---|
| 105 | if (clientGroup != null && row != null) {
|
---|
[995] | 106 | row.ResourceId = clientGroup.Id;
|
---|
[965] | 107 | }
|
---|
| 108 |
|
---|
| 109 | return row;
|
---|
| 110 | }
|
---|
[995] | 111 | #endregion
|
---|
[965] | 112 |
|
---|
[995] | 113 | #region IClientGroupAdapter Members
|
---|
[1468] | 114 | protected override void doUpdate(ClientGroup group) {
|
---|
[995] | 115 | if (group != null) {
|
---|
| 116 | ResAdapter.Update(group);
|
---|
| 117 |
|
---|
[1468] | 118 | base.doUpdate(group);
|
---|
[1515] | 119 |
|
---|
| 120 | List<Guid> relationships =
|
---|
| 121 | new List<Guid>();
|
---|
| 122 | foreach(Resource res in group.Resources) {
|
---|
[1597] | 123 | ResAdapter.UpdatePolymorphic(res);
|
---|
[1515] | 124 |
|
---|
| 125 | relationships.Add(res.Id);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[1580] | 128 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
[1759] | 129 | relationships);
|
---|
[965] | 130 | }
|
---|
[910] | 131 | }
|
---|
| 132 |
|
---|
[995] | 133 | public ClientGroup GetByName(string name) {
|
---|
[971] | 134 | ClientGroup group = new ClientGroup();
|
---|
| 135 | Resource res =
|
---|
[995] | 136 | ResAdapter.GetByName(name);
|
---|
[971] | 137 |
|
---|
| 138 | if (res != null) {
|
---|
[995] | 139 | return GetById(res.Id);
|
---|
[971] | 140 | }
|
---|
| 141 |
|
---|
| 142 | return null;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[965] | 145 | public ICollection<ClientGroup> MemberOf(Resource resource) {
|
---|
[1756] | 146 | if (resource != null) {
|
---|
| 147 | return base.FindMultiple(
|
---|
| 148 | delegate() {
|
---|
| 149 | return Adapter.GetDataByParentsOf(resource.Id);
|
---|
| 150 | }
|
---|
| 151 | );
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | return null;
|
---|
[965] | 155 | }
|
---|
| 156 |
|
---|
[1468] | 157 | protected override bool doDelete(ClientGroup group) {
|
---|
[965] | 158 | if (group != null) {
|
---|
[1515] | 159 | //delete all relationships
|
---|
[1580] | 160 | ManyToManyRelationHelper.UpdateRelationships(group.Id,
|
---|
[1759] | 161 | new List<Guid>());
|
---|
[1515] | 162 |
|
---|
[1468] | 163 | return base.doDelete(group) &&
|
---|
[995] | 164 | ResAdapter.Delete(group);
|
---|
[965] | 165 | }
|
---|
| 166 |
|
---|
| 167 | return false;
|
---|
[910] | 168 | }
|
---|
| 169 |
|
---|
| 170 | #endregion
|
---|
| 171 | }
|
---|
| 172 | }
|
---|