Free cookie consent management tool by TermsFeed Policy Generator

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

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