[845] | 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;
|
---|
[925] | 29 | using System.Runtime.CompilerServices;
|
---|
[845] | 30 |
|
---|
| 31 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[925] | 32 | class PermissionOwnerAdapter: DataAdapterBase, IPermissionOwnerAdapter {
|
---|
[845] | 33 | private dsHiveServerTableAdapters.PermissionOwnerTableAdapter adapter =
|
---|
| 34 | new dsHiveServerTableAdapters.PermissionOwnerTableAdapter();
|
---|
| 35 |
|
---|
[925] | 36 | private dsHiveServer.PermissionOwnerDataTable data =
|
---|
| 37 | new dsHiveServer.PermissionOwnerDataTable();
|
---|
| 38 |
|
---|
| 39 | public PermissionOwnerAdapter() {
|
---|
| 40 | adapter.Fill(data);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | protected override void Update() {
|
---|
| 44 | this.adapter.Update(this.data);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | private PermissionOwner Convert(dsHiveServer.PermissionOwnerRow row,
|
---|
[905] | 48 | PermissionOwner permOwner) {
|
---|
| 49 | if (row != null && permOwner != null) {
|
---|
| 50 | permOwner.PermissionOwnerId = row.PermissionOwnerId;
|
---|
| 51 |
|
---|
| 52 | if (!row.IsNameNull())
|
---|
| 53 | permOwner.Name = row.Name;
|
---|
| 54 | else
|
---|
| 55 | permOwner.Name = String.Empty;
|
---|
| 56 |
|
---|
| 57 | return permOwner;
|
---|
| 58 | } else
|
---|
| 59 | return null;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private dsHiveServer.PermissionOwnerRow Convert(PermissionOwner permOwner,
|
---|
| 63 | dsHiveServer.PermissionOwnerRow row) {
|
---|
| 64 | if (row != null && permOwner != null) {
|
---|
| 65 | row.Name = permOwner.Name;
|
---|
| 66 |
|
---|
| 67 | return row;
|
---|
| 68 | } else
|
---|
| 69 | return null;
|
---|
| 70 | }
|
---|
[925] | 71 |
|
---|
| 72 | #region IPermissionOwner Members
|
---|
| 73 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 74 | public void UpdatePermissionOwner(PermissionOwner permOwner) {
|
---|
| 75 | if (permOwner != null) {
|
---|
[925] | 76 | dsHiveServer.PermissionOwnerRow row =
|
---|
| 77 | data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
|
---|
| 78 |
|
---|
| 79 | if (row == null) {
|
---|
[845] | 80 | row = data.NewPermissionOwnerRow();
|
---|
| 81 | data.AddPermissionOwnerRow(row);
|
---|
[925] | 82 |
|
---|
| 83 | //write row to db to get primary key
|
---|
| 84 | adapter.Update(row);
|
---|
[845] | 85 | }
|
---|
| 86 |
|
---|
[925] | 87 | Convert(permOwner, row);
|
---|
[845] | 88 | permOwner.PermissionOwnerId = row.PermissionOwnerId;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[925] | 92 | public bool GetPermissionOwnerById(PermissionOwner permOwner) {
|
---|
[899] | 93 | if (permOwner != null) {
|
---|
[905] | 94 | dsHiveServer.PermissionOwnerRow row =
|
---|
[925] | 95 | data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
|
---|
| 96 |
|
---|
| 97 | if(row != null) {
|
---|
[905] | 98 | Convert(row, permOwner);
|
---|
| 99 |
|
---|
[899] | 100 | return true;
|
---|
[905] | 101 | }
|
---|
[899] | 102 | }
|
---|
| 103 |
|
---|
| 104 | return false;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[905] | 107 | public PermissionOwner GetPermissionOwnerById(long permOwnerId) {
|
---|
| 108 | PermissionOwner permOwner = new PermissionOwner();
|
---|
| 109 | permOwner.PermissionOwnerId = permOwnerId;
|
---|
| 110 |
|
---|
[925] | 111 | if (GetPermissionOwnerById(permOwner))
|
---|
[905] | 112 | return permOwner;
|
---|
| 113 | else
|
---|
| 114 | return null;
|
---|
[845] | 115 | }
|
---|
| 116 |
|
---|
[925] | 117 | public PermissionOwner GetPermissionOwnerByName(String name) {
|
---|
| 118 | PermissionOwner permOwner = new PermissionOwner();
|
---|
| 119 |
|
---|
| 120 | dsHiveServer.PermissionOwnerRow row =
|
---|
| 121 | data.Single<dsHiveServer.PermissionOwnerRow>(
|
---|
| 122 | r => !r.IsNameNull() && r.Name == name);
|
---|
| 123 |
|
---|
| 124 | if (row != null) {
|
---|
| 125 | Convert(row, permOwner);
|
---|
| 126 |
|
---|
| 127 | return permOwner;
|
---|
| 128 | } else {
|
---|
| 129 | return null;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[845] | 133 | public ICollection<PermissionOwner> GetAllPermissionOwners() {
|
---|
[905] | 134 | ICollection<PermissionOwner> allPermissionOwners =
|
---|
| 135 | new List<PermissionOwner>();
|
---|
| 136 |
|
---|
| 137 | foreach (dsHiveServer.PermissionOwnerRow row in data) {
|
---|
| 138 | PermissionOwner permOwner = new PermissionOwner();
|
---|
| 139 | Convert(row, permOwner);
|
---|
| 140 | allPermissionOwners.Add(permOwner);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | return allPermissionOwners;
|
---|
[845] | 144 | }
|
---|
| 145 |
|
---|
[925] | 146 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
[845] | 147 | public bool DeletePermissionOwner(PermissionOwner permOwner) {
|
---|
| 148 | if (permOwner != null) {
|
---|
[925] | 149 | dsHiveServer.PermissionOwnerRow row =
|
---|
| 150 | data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
|
---|
[845] | 151 |
|
---|
[925] | 152 | if(row != null) {
|
---|
| 153 | data.RemovePermissionOwnerRow(row);
|
---|
[845] | 154 |
|
---|
[925] | 155 | return true;
|
---|
| 156 | }
|
---|
[845] | 157 | }
|
---|
| 158 |
|
---|
| 159 | return false;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | #endregion
|
---|
| 163 | }
|
---|
| 164 | }
|
---|