- Timestamp:
- 12/16/08 17:26:43 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserGroupAdapter.cs
r972 r995 31 31 32 32 namespace HeuristicLab.Hive.Server.ADODataAccess { 33 class UserGroupAdapter: DataAdapterBase, IUserGroupAdapter { 34 private dsHiveServerTableAdapters.UserGroupTableAdapter adapter = 35 new dsHiveServerTableAdapters.UserGroupTableAdapter(); 36 37 private dsHiveServer.UserGroupDataTable data = 38 new dsHiveServer.UserGroupDataTable(); 33 class UserGroupAdapter: 34 DataAdapterBase< 35 dsHiveServerTableAdapters.UserGroupTableAdapter, 36 UserGroup, 37 dsHiveServer.UserGroupRow>, 38 IUserGroupAdapter { 39 40 #region Fields 41 dsHiveServer.UserGroupDataTable data = 42 new dsHiveServer.UserGroupDataTable(); 39 43 40 44 private dsHiveServerTableAdapters.PermissionOwner_UserGroupTableAdapter permOwnerUserGroupAdapter = 41 45 new dsHiveServerTableAdapters.PermissionOwner_UserGroupTableAdapter(); 42 43 private dsHiveServer.PermissionOwner_UserGroupDataTable permOwnerUserGroupData =44 new dsHiveServer.PermissionOwner_UserGroupDataTable();45 46 46 47 private IPermissionOwnerAdapter permOwnerAdapter = null; … … 65 66 } 66 67 } 67 68 public UserGroupAdapter() { 69 adapter.Fill(data); 70 permOwnerUserGroupAdapter.Fill(permOwnerUserGroupData); 71 } 72 73 protected override void Update() { 74 this.adapter.Update(this.data); 75 this.permOwnerUserGroupAdapter.Update(permOwnerUserGroupData); 76 } 77 78 private UserGroup Convert(dsHiveServer.UserGroupRow row, 68 #endregion 69 70 #region Overrides 71 protected override UserGroup Convert(dsHiveServer.UserGroupRow row, 79 72 UserGroup userGroup) { 80 73 if (row != null && userGroup != null) { 81 74 /*Parent - Permission Owner*/ 82 userGroup. PermissionOwnerId = row.PermissionOwnerId;83 PermOwnerAdapter.Get PermissionOwnerById(userGroup);75 userGroup.Id = row.PermissionOwnerId; 76 PermOwnerAdapter.GetById(userGroup); 84 77 85 78 //first check for created references 86 IEnumerable<dsHiveServer.PermissionOwner_UserGroupRow> userGroupRows = 87 from permOwner in 88 permOwnerUserGroupData.AsEnumerable<dsHiveServer.PermissionOwner_UserGroupRow>() 89 where permOwner.UserGroupId == userGroup.PermissionOwnerId 90 select permOwner; 79 dsHiveServer.PermissionOwner_UserGroupDataTable userGroupRows = 80 permOwnerUserGroupAdapter.GetDataByUserGroupId(userGroup.Id); 91 81 92 82 foreach (dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow in … … 97 87 from p in 98 88 userGroup.Members 99 where p. PermissionOwnerId == permOwnerUserGroupRow.PermissionOwnerId89 where p.Id == permOwnerUserGroupRow.PermissionOwnerId 100 90 select p; 101 91 if (permOwners.Count<PermissionOwner>() == 1) … … 104 94 if (permOwner == null) { 105 95 PermissionOwner permissionOwner = 106 UserAdapter.Get UserById(permOwnerUserGroupRow.PermissionOwnerId);96 UserAdapter.GetById(permOwnerUserGroupRow.PermissionOwnerId); 107 97 108 98 if (permissionOwner == null) { 109 99 //is a user group 110 100 permissionOwner = 111 Get UserGroupById(permOwnerUserGroupRow.PermissionOwnerId);101 GetById(permOwnerUserGroupRow.PermissionOwnerId); 112 102 } 113 103 … … 122 112 123 113 foreach (PermissionOwner permOwner in userGroup.Members) { 124 dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow = 125 permOwnerUserGroupData.FindByPermissionOwnerIdUserGroupId( 126 permOwner.PermissionOwnerId, 127 userGroup.PermissionOwnerId); 128 129 if (permOwnerUserGroupRow == null) { 114 dsHiveServer.PermissionOwner_UserGroupDataTable found = 115 permOwnerUserGroupAdapter.GetDataByPermownerUsergroupId( 116 permOwner.Id, 117 userGroup.Id); 118 if (found.Count != 1) { 130 119 deleted.Add(permOwner); 131 120 } … … 141 130 } 142 131 143 pr ivate dsHiveServer.UserGroupRow Convert(UserGroup userGroup,132 protected override dsHiveServer.UserGroupRow Convert(UserGroup userGroup, 144 133 dsHiveServer.UserGroupRow row) { 145 134 if (userGroup != null && row != null) { 146 row.PermissionOwnerId = userGroup. PermissionOwnerId;135 row.PermissionOwnerId = userGroup.Id; 147 136 148 137 //update references … … 150 139 //first update the member to make sure it exists in the DB 151 140 if (permOwner is User) { 152 UserAdapter.Update User(permOwner as User);141 UserAdapter.Update(permOwner as User); 153 142 } else if (permOwner is UserGroup) { 154 Update UserGroup(permOwner as UserGroup);143 Update(permOwner as UserGroup); 155 144 } 156 145 157 146 //secondly check for created references 158 147 dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow = 159 permOwnerUserGroupData.FindByPermissionOwnerIdUserGroupId( 160 permOwner.PermissionOwnerId, 161 userGroup.PermissionOwnerId); 148 null; 149 dsHiveServer.PermissionOwner_UserGroupDataTable found = 150 permOwnerUserGroupAdapter.GetDataByPermownerUsergroupId( 151 permOwner.Id, 152 userGroup.Id); 153 if (found.Count == 1) 154 permOwnerUserGroupRow = found[0]; 162 155 163 156 if (permOwnerUserGroupRow == null) { 164 157 permOwnerUserGroupRow = 165 permOwnerUserGroupData.NewPermissionOwner_UserGroupRow();158 found.NewPermissionOwner_UserGroupRow(); 166 159 167 160 permOwnerUserGroupRow.PermissionOwnerId = 168 permOwner. PermissionOwnerId;161 permOwner.Id; 169 162 permOwnerUserGroupRow.UserGroupId = 170 userGroup.PermissionOwnerId; 171 172 permOwnerUserGroupData.AddPermissionOwner_UserGroupRow( 173 permOwnerUserGroupRow); 163 userGroup.Id; 164 165 found.AddPermissionOwner_UserGroupRow(permOwnerUserGroupRow); 166 167 permOwnerUserGroupAdapter.Update(permOwnerUserGroupRow); 174 168 } 175 169 } 176 170 177 171 //thirdly check for deleted references 178 IEnumerable<dsHiveServer.PermissionOwner_UserGroupRow> userGroupRows = 179 from permOwner in 180 permOwnerUserGroupData.AsEnumerable<dsHiveServer.PermissionOwner_UserGroupRow>() 181 where permOwner.UserGroupId == userGroup.PermissionOwnerId 182 select permOwner; 172 dsHiveServer.PermissionOwner_UserGroupDataTable userGroupRows = 173 permOwnerUserGroupAdapter.GetDataByUserGroupId(userGroup.Id); 183 174 184 175 ICollection<dsHiveServer.PermissionOwner_UserGroupRow> deleted = … … 192 183 from p in 193 184 userGroup.Members 194 where p. PermissionOwnerId == permOwnerUserGroupRow.PermissionOwnerId185 where p.Id == permOwnerUserGroupRow.PermissionOwnerId 195 186 select p; 196 187 … … 203 194 } 204 195 205 foreach (dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow in 206 deleted) { 207 permOwnerUserGroupData.RemovePermissionOwner_UserGroupRow( 208 permOwnerUserGroupRow); 209 } 210 196 foreach (dsHiveServer.PermissionOwner_UserGroupRow 197 permOwnerUserGroupRow in deleted) { 198 permOwnerUserGroupRow.Delete(); 199 permOwnerUserGroupAdapter.Update(permOwnerUserGroupRow); 200 } 211 201 } 212 202 213 203 return row; 214 204 } 205 206 protected override dsHiveServer.UserGroupRow 207 InsertNewRow(UserGroup group) { 208 dsHiveServer.UserGroupRow row = 209 data.NewUserGroupRow(); 210 211 row.PermissionOwnerId = group.Id; 212 213 data.AddUserGroupRow(row); 214 adapter.Update(row); 215 216 return row; 217 } 218 219 protected override void 220 UpdateRow(dsHiveServer.UserGroupRow row) { 221 adapter.Update(row); 222 } 223 224 protected override IEnumerable<dsHiveServer.UserGroupRow> 225 FindById(long id) { 226 return adapter.GetDataById(id); 227 } 228 229 protected override IEnumerable<dsHiveServer.UserGroupRow> 230 FindAll() { 231 return adapter.GetData(); 232 } 233 #endregion 215 234 216 235 #region IUserGroupAdapter Members 217 236 [MethodImpl(MethodImplOptions.Synchronized)] 218 public void UpdateUserGroup(UserGroup group) {237 public override void Update(UserGroup group) { 219 238 if (group != null) { 220 PermOwnerAdapter.UpdatePermissionOwner(group); 221 222 dsHiveServer.UserGroupRow row = 223 data.FindByPermissionOwnerId(group.PermissionOwnerId); 224 225 if (row == null) { 226 row = data.NewUserGroupRow(); 227 row.PermissionOwnerId = group.PermissionOwnerId; 228 data.AddUserGroupRow(row); 229 } 230 231 Convert(group, row); 232 } 233 } 234 235 public UserGroup GetUserGroupById(long userGroupId) { 236 UserGroup userGroup = new UserGroup(); 237 238 dsHiveServer.UserGroupRow row = 239 data.FindByPermissionOwnerId(userGroupId); 240 241 if (row != null) { 242 Convert(row, userGroup); 243 244 return userGroup; 245 } else { 246 return null; 247 } 248 } 249 250 public UserGroup GetUserGroupByName(string name) { 251 UserGroup group = new UserGroup(); 252 253 PermissionOwner permOwner = 254 PermOwnerAdapter.GetPermissionOwnerByName(name); 255 256 if (permOwner != null) { 257 dsHiveServer.UserGroupRow row = 258 data.FindByPermissionOwnerId(permOwner.PermissionOwnerId); 259 260 if (row != null) { 261 Convert(row, group); 262 263 return group; 264 } 239 PermOwnerAdapter.Update(group); 240 241 base.Update(group); 242 } 243 } 244 245 public UserGroup GetByName(String name) { 246 if (name != null) { 247 return base.FindSingle( 248 delegate() { 249 return adapter.GetDataByName(name); 250 }); 265 251 } 266 252 267 253 return null; 268 }269 270 public ICollection<UserGroup> GetAllUserGroups() {271 ICollection<UserGroup> allUserGroups =272 new List<UserGroup>();273 274 foreach (dsHiveServer.UserGroupRow row in data) {275 UserGroup userGroup = new UserGroup();276 277 Convert(row, userGroup);278 allUserGroups.Add(userGroup);279 }280 281 return allUserGroups;282 254 } 283 255 … … 287 259 288 260 if (permOwner != null) { 289 IEnumerable<dsHiveServer.PermissionOwner_UserGroupRow> userGroupRows = 290 from userGroup in 291 permOwnerUserGroupData.AsEnumerable<dsHiveServer.PermissionOwner_UserGroupRow>() 292 where userGroup.PermissionOwnerId == permOwner.PermissionOwnerId 293 select userGroup; 261 dsHiveServer.PermissionOwner_UserGroupDataTable userGroupRows = 262 permOwnerUserGroupAdapter.GetDataByPermissionOwnerId(permOwner.Id); 294 263 295 264 foreach (dsHiveServer.PermissionOwner_UserGroupRow userGroupRow in 296 265 userGroupRows) { 297 266 UserGroup userGroup = 298 Get UserGroupById(userGroupRow.UserGroupId);267 GetById(userGroupRow.UserGroupId); 299 268 userGroups.Add(userGroup); 300 269 } … … 305 274 306 275 [MethodImpl(MethodImplOptions.Synchronized)] 307 public bool DeleteUserGroup(UserGroup group) {276 public override bool Delete(UserGroup group) { 308 277 if (group != null) { 309 dsHiveServer.UserGroupRow row = 310 data.FindByPermissionOwnerId(group.PermissionOwnerId); 311 312 if (row != null) { 313 ICollection<dsHiveServer.PermissionOwner_UserGroupRow> deleted = 314 new List<dsHiveServer.PermissionOwner_UserGroupRow>(); 315 316 foreach (dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow in 317 permOwnerUserGroupData) { 318 if (permOwnerUserGroupRow.UserGroupId == group.PermissionOwnerId || 319 permOwnerUserGroupRow.PermissionOwnerId == group.PermissionOwnerId) { 320 deleted.Add(permOwnerUserGroupRow); 321 } 322 } 323 324 foreach (dsHiveServer.PermissionOwner_UserGroupRow permOwnerUserGroupRow in 325 deleted) { 326 permOwnerUserGroupData.RemovePermissionOwner_UserGroupRow( 327 permOwnerUserGroupRow); 328 } 329 330 row.Delete(); 331 adapter.Update(row); 332 return PermOwnerAdapter.DeletePermissionOwner(group); 333 } 278 return base.Delete(group) && 279 PermOwnerAdapter.Delete(group); 334 280 } 335 281
Note: See TracChangeset
for help on using the changeset viewer.