[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 {
|
---|
[995] | 32 | class UserAdapter :
|
---|
| 33 | DataAdapterBase<
|
---|
| 34 | dsHiveServerTableAdapters.HiveUserTableAdapter,
|
---|
| 35 | User,
|
---|
| 36 | dsHiveServer.HiveUserRow>,
|
---|
| 37 | IUserAdapter {
|
---|
| 38 | #region Fields
|
---|
| 39 | dsHiveServer.HiveUserDataTable data =
|
---|
[925] | 40 | new dsHiveServer.HiveUserDataTable();
|
---|
[845] | 41 |
|
---|
[948] | 42 | private IPermissionOwnerAdapter permOwnerAdapter = null;
|
---|
[925] | 43 |
|
---|
[948] | 44 | private IPermissionOwnerAdapter PermOwnerAdapter {
|
---|
| 45 | get {
|
---|
| 46 | if (permOwnerAdapter == null)
|
---|
| 47 | permOwnerAdapter = ServiceLocator.GetPermissionOwnerAdapter();
|
---|
| 48 |
|
---|
| 49 | return permOwnerAdapter;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[939] | 53 | private IUserGroupAdapter userGroupAdapter = null;
|
---|
| 54 |
|
---|
[948] | 55 | private IUserGroupAdapter UserGroupAdapter {
|
---|
| 56 | get {
|
---|
[995] | 57 | if (userGroupAdapter == null)
|
---|
[948] | 58 | userGroupAdapter = ServiceLocator.GetUserGroupAdapter();
|
---|
| 59 |
|
---|
| 60 | return userGroupAdapter;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[971] | 64 | private IJobAdapter jobAdapter = null;
|
---|
| 65 |
|
---|
| 66 | private IJobAdapter JobAdapter {
|
---|
| 67 | get {
|
---|
[995] | 68 | if (jobAdapter == null)
|
---|
[971] | 69 | jobAdapter = ServiceLocator.GetJobAdapter();
|
---|
| 70 |
|
---|
| 71 | return jobAdapter;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
[995] | 74 | #endregion
|
---|
[971] | 75 |
|
---|
[995] | 76 | #region Overrides
|
---|
[1131] | 77 | protected override User ConvertRow(dsHiveServer.HiveUserRow row,
|
---|
[899] | 78 | User user) {
|
---|
| 79 | if (row != null && user != null) {
|
---|
| 80 | /*Parent - PermissionOwner*/
|
---|
[995] | 81 | user.Id = row.PermissionOwnerId;
|
---|
| 82 | PermOwnerAdapter.GetById(user);
|
---|
[845] | 83 |
|
---|
| 84 | /*User*/
|
---|
[899] | 85 | if (!row.IsPasswordNull())
|
---|
| 86 | user.Password = row.Password;
|
---|
| 87 | else
|
---|
| 88 | user.Password = String.Empty;
|
---|
[845] | 89 |
|
---|
| 90 | return user;
|
---|
| 91 | } else
|
---|
| 92 | return null;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[1131] | 95 | protected override dsHiveServer.HiveUserRow ConvertObj(User user,
|
---|
[845] | 96 | dsHiveServer.HiveUserRow row) {
|
---|
| 97 | if (user != null && row != null) {
|
---|
[995] | 98 | if (user.Password == null)
|
---|
| 99 | row.SetPasswordNull();
|
---|
| 100 | else
|
---|
| 101 | row.Password = user.Password;
|
---|
[845] | 102 |
|
---|
[899] | 103 | return row;
|
---|
| 104 | } else
|
---|
[995] | 105 | return null;
|
---|
[845] | 106 | }
|
---|
| 107 |
|
---|
[995] | 108 | protected override dsHiveServer.HiveUserRow
|
---|
| 109 | InsertNewRow(User user) {
|
---|
| 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 | }
|
---|