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