Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/UserAdapter.cs @ 4501

Last change on this file since 4501 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 4.5 KB
Line 
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;
29
30namespace HeuristicLab.Hive.Server.ADODataAccess {
31  class UserAdapter :
32    DataAdapterBase<
33      dsHiveServerTableAdapters.HiveUserTableAdapter,
34      User,
35      dsHiveServer.HiveUserRow>,
36    IUserAdapter {
37    #region Fields
38    private IPermissionOwnerAdapter permOwnerAdapter = null;
39
40    private IPermissionOwnerAdapter PermOwnerAdapter {
41      get {
42        if (permOwnerAdapter == null)
43          permOwnerAdapter = ServiceLocator.GetPermissionOwnerAdapter();
44
45        return permOwnerAdapter;
46      }
47    }
48
49    private IUserGroupAdapter userGroupAdapter = null;
50
51    private IUserGroupAdapter UserGroupAdapter {
52      get {
53        if (userGroupAdapter == null)
54          userGroupAdapter = ServiceLocator.GetUserGroupAdapter();
55
56        return userGroupAdapter;
57      }
58    }
59
60    private IJobAdapter jobAdapter = null;
61
62    private IJobAdapter JobAdapter {
63      get {
64        if (jobAdapter == null)
65          jobAdapter = ServiceLocator.GetJobAdapter();
66
67        return jobAdapter;
68      }
69    }
70    #endregion
71
72    #region Overrides
73    protected override User ConvertRow(dsHiveServer.HiveUserRow row,
74      User user) {
75      if (row != null && user != null) {
76        /*Parent - PermissionOwner*/
77        user.Id = row.PermissionOwnerId;
78        PermOwnerAdapter.GetById(user);
79
80        /*User*/
81        if (!row.IsPasswordNull())
82          user.Password = row.Password;
83        else
84          user.Password = String.Empty;
85
86        return user;
87      } else
88        return null;
89    }
90
91    protected override dsHiveServer.HiveUserRow ConvertObj(User user,
92      dsHiveServer.HiveUserRow row) {
93      if (user != null && row != null) {
94        if (user.Password == null)
95          row.SetPasswordNull();
96        else
97          row.Password = user.Password;
98
99        return row;
100      } else
101        return null;
102    }
103
104    protected override dsHiveServer.HiveUserRow
105      InsertNewRow(User user) {
106      dsHiveServer.HiveUserDataTable data =
107        new dsHiveServer.HiveUserDataTable();
108
109      dsHiveServer.HiveUserRow row =
110        data.NewHiveUserRow();
111
112      row.PermissionOwnerId = user.Id;
113
114      data.AddHiveUserRow(row);
115
116      return row;
117    }
118
119    protected override void
120      UpdateRow(dsHiveServer.HiveUserRow row) {
121      Adapter.Update(row);
122    }
123
124    protected override IEnumerable<dsHiveServer.HiveUserRow>
125      FindById(long id) {
126      return Adapter.GetDataById(id);
127    }
128
129    protected override IEnumerable<dsHiveServer.HiveUserRow>
130      FindAll() {
131      return Adapter.GetData();
132    }
133    #endregion
134
135    #region IUserAdapter Members
136
137    public override void Update(User user) {
138      if (user != null) {
139        PermOwnerAdapter.Update(user);
140
141        base.Update(user);
142      }
143    }
144
145    public User GetByName(String name) {
146      if (name != null) {
147        return base.FindSingle(
148          delegate() {
149            return Adapter.GetDataByName(name);
150          });
151      }
152
153      return null;
154    }
155
156    public override bool Delete(User user) {
157      if (user != null) {
158        //Referential integrity with jobs - they are cached
159        ICollection<Job> jobs =
160          JobAdapter.GetJobsOf(user);
161        foreach (Job job in jobs) {
162          JobAdapter.Delete(job);
163        }
164
165        return base.Delete(user) &&
166            PermOwnerAdapter.Delete(user);
167      }
168
169      return false;
170    }
171
172    #endregion
173  }
174}
Note: See TracBrowser for help on using the repository browser.