Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/PermissionOwnerAdapter.cs @ 978

Last change on this file since 978 was 976, checked in by svonolfe, 16 years ago

Fixed selecting by name (#372)

File size: 5.1 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26
27using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
28using HeuristicLab.Hive.Contracts.BusinessObjects;
[925]29using System.Runtime.CompilerServices;
[845]30
31namespace 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) {
[976]118       dsHiveServer.PermissionOwnerRow row = null;
[925]119
[976]120      IEnumerable<dsHiveServer.PermissionOwnerRow> permOwners =
121        from r in
122          data.AsEnumerable<dsHiveServer.PermissionOwnerRow>()
123        where !r.IsNameNull() && r.Name == name
124        select r;
[925]125
[976]126      if (permOwners.Count<dsHiveServer.PermissionOwnerRow>() == 1)
127        row = permOwners.First<dsHiveServer.PermissionOwnerRow>();
128
[925]129      if (row != null) {
[976]130        PermissionOwner permOwner = new PermissionOwner();
[925]131        Convert(row, permOwner);
132
133        return permOwner;
134      } else {
135        return null;
136      }
137    }
138
[845]139    public ICollection<PermissionOwner> GetAllPermissionOwners() {
[905]140      ICollection<PermissionOwner> allPermissionOwners =
141        new List<PermissionOwner>();
142
143      foreach (dsHiveServer.PermissionOwnerRow row in data) {
144        PermissionOwner permOwner = new PermissionOwner();
145        Convert(row, permOwner);
146        allPermissionOwners.Add(permOwner);
147      }
148
149      return allPermissionOwners;
[845]150    }
151
[925]152    [MethodImpl(MethodImplOptions.Synchronized)]
[845]153    public bool DeletePermissionOwner(PermissionOwner permOwner) {
154      if (permOwner != null) {
[925]155          dsHiveServer.PermissionOwnerRow row =
156            data.FindByPermissionOwnerId(permOwner.PermissionOwnerId);
[845]157
[925]158          if(row != null) {
[972]159            row.Delete();
160            adapter.Update(row);
[939]161         
[925]162            return true;
163          }
[845]164        }
165
166      return false;
167    }
168
169    #endregion
170  }
171}
Note: See TracBrowser for help on using the repository browser.