Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserAdapter.cs @ 1166

Last change on this file since 1166 was 1166, checked in by svonolfe, 15 years ago

Improved memory consumption, fixed bug that already calculated jobs where reset (#372)

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