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 |
|
---|
27 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
28 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
31 | class PermissionOwnerAdapter: IPermissionOwner {
|
---|
32 | #region IPermissionOwner Members
|
---|
33 | private dsHiveServerTableAdapters.PermissionOwnerTableAdapter adapter =
|
---|
34 | new dsHiveServerTableAdapters.PermissionOwnerTableAdapter();
|
---|
35 |
|
---|
36 | private PermissionOwner Convert(dsHiveServer.PermissionOwnerRow row,
|
---|
37 | PermissionOwner permOwner) {
|
---|
38 | if (row != null && permOwner != null) {
|
---|
39 | permOwner.PermissionOwnerId = row.PermissionOwnerId;
|
---|
40 |
|
---|
41 | if (!row.IsNameNull())
|
---|
42 | permOwner.Name = row.Name;
|
---|
43 | else
|
---|
44 | permOwner.Name = String.Empty;
|
---|
45 |
|
---|
46 | return permOwner;
|
---|
47 | } else
|
---|
48 | return null;
|
---|
49 | }
|
---|
50 |
|
---|
51 | private dsHiveServer.PermissionOwnerRow Convert(PermissionOwner permOwner,
|
---|
52 | dsHiveServer.PermissionOwnerRow row) {
|
---|
53 | if (row != null && permOwner != null) {
|
---|
54 | row.PermissionOwnerId = permOwner.PermissionOwnerId;
|
---|
55 | row.Name = permOwner.Name;
|
---|
56 |
|
---|
57 | return row;
|
---|
58 | } else
|
---|
59 | return null;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public void UpdatePermissionOwner(PermissionOwner permOwner) {
|
---|
63 | if (permOwner != null) {
|
---|
64 | dsHiveServer.PermissionOwnerDataTable data =
|
---|
65 | adapter.GetDataById(permOwner.PermissionOwnerId);
|
---|
66 |
|
---|
67 | dsHiveServer.PermissionOwnerRow row;
|
---|
68 | if (data.Count == 0) {
|
---|
69 | row = data.NewPermissionOwnerRow();
|
---|
70 | data.AddPermissionOwnerRow(row);
|
---|
71 | } else {
|
---|
72 | row = data[0];
|
---|
73 | }
|
---|
74 |
|
---|
75 | row.Name = permOwner.Name;
|
---|
76 |
|
---|
77 | adapter.Update(data);
|
---|
78 |
|
---|
79 | permOwner.PermissionOwnerId = row.PermissionOwnerId;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | internal bool FillPermissionOwner(PermissionOwner permOwner) {
|
---|
84 | if (permOwner != null) {
|
---|
85 | dsHiveServer.PermissionOwnerDataTable data =
|
---|
86 | adapter.GetDataById(permOwner.PermissionOwnerId);
|
---|
87 | if (data.Count == 1) {
|
---|
88 | dsHiveServer.PermissionOwnerRow row =
|
---|
89 | data[0];
|
---|
90 | Convert(row, permOwner);
|
---|
91 |
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public PermissionOwner GetPermissionOwnerById(long permOwnerId) {
|
---|
100 | PermissionOwner permOwner = new PermissionOwner();
|
---|
101 | permOwner.PermissionOwnerId = permOwnerId;
|
---|
102 |
|
---|
103 | if (FillPermissionOwner(permOwner))
|
---|
104 | return permOwner;
|
---|
105 | else
|
---|
106 | return null;
|
---|
107 | }
|
---|
108 |
|
---|
109 | public ICollection<PermissionOwner> GetAllPermissionOwners() {
|
---|
110 | ICollection<PermissionOwner> allPermissionOwners =
|
---|
111 | new List<PermissionOwner>();
|
---|
112 |
|
---|
113 | dsHiveServer.PermissionOwnerDataTable data =
|
---|
114 | adapter.GetData();
|
---|
115 |
|
---|
116 | foreach (dsHiveServer.PermissionOwnerRow row in data) {
|
---|
117 | PermissionOwner permOwner = new PermissionOwner();
|
---|
118 | Convert(row, permOwner);
|
---|
119 | allPermissionOwners.Add(permOwner);
|
---|
120 | }
|
---|
121 |
|
---|
122 | return allPermissionOwners;
|
---|
123 | }
|
---|
124 |
|
---|
125 | public bool DeletePermissionOwner(PermissionOwner permOwner) {
|
---|
126 | if (permOwner != null) {
|
---|
127 | dsHiveServer.PermissionOwnerDataTable data =
|
---|
128 | adapter.GetDataById(permOwner.PermissionOwnerId);
|
---|
129 |
|
---|
130 | if (data.Count == 1) {
|
---|
131 | dsHiveServer.PermissionOwnerRow row = data[0];
|
---|
132 |
|
---|
133 | row.Delete();
|
---|
134 | return adapter.Update(data) > 0;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | return false;
|
---|
139 | }
|
---|
140 |
|
---|
141 | #endregion
|
---|
142 | }
|
---|
143 | }
|
---|