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