[826] | 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 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
| 27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
| 30 | class ResourceAdapter: IResourceAdapter {
|
---|
| 31 | #region IResourceAdapter Members
|
---|
| 32 | private dsHiveServerTableAdapters.ResourceTableAdapter adapter =
|
---|
| 33 | new dsHiveServerTableAdapters.ResourceTableAdapter();
|
---|
| 34 |
|
---|
[845] | 35 | private Resource Convert(dsHiveServer.ResourceRow row) {
|
---|
| 36 | if (row != null) {
|
---|
| 37 | Resource resource = new Resource();
|
---|
| 38 |
|
---|
| 39 | resource.ResourceId = row.ResourceId;
|
---|
| 40 | resource.Name = row.Name;
|
---|
| 41 |
|
---|
| 42 | return resource;
|
---|
| 43 | } else
|
---|
| 44 | return null;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | private dsHiveServer.ResourceRow Convert(Resource resource,
|
---|
| 48 | dsHiveServer.ResourceRow row) {
|
---|
| 49 | if (resource != null && row != null) {
|
---|
| 50 | row.Name = resource.Name;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | return row;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[826] | 56 | public void UpdateResource(Resource resource) {
|
---|
| 57 | if (resource != null) {
|
---|
| 58 | dsHiveServer.ResourceDataTable data =
|
---|
| 59 | adapter.GetDataById(resource.ResourceId);
|
---|
| 60 |
|
---|
| 61 | dsHiveServer.ResourceRow row;
|
---|
| 62 | if (data.Count == 0) {
|
---|
| 63 | row = data.NewResourceRow();
|
---|
| 64 | data.AddResourceRow(row);
|
---|
| 65 | } else {
|
---|
| 66 | row = data[0];
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[845] | 69 | Convert(resource, row);
|
---|
[826] | 70 |
|
---|
| 71 | adapter.Update(data);
|
---|
| 72 |
|
---|
| 73 | resource.ResourceId = row.ResourceId;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[845] | 77 | public Resource GetResourceById(long resourceId) {
|
---|
| 78 | dsHiveServer.ResourceDataTable data =
|
---|
| 79 | adapter.GetDataById(resourceId);
|
---|
| 80 | if (data.Count == 1) {
|
---|
| 81 | dsHiveServer.ResourceRow row =
|
---|
| 82 | data[0];
|
---|
| 83 | return Convert(row);
|
---|
| 84 | } else {
|
---|
| 85 | return null;
|
---|
| 86 | }
|
---|
[826] | 87 | }
|
---|
| 88 |
|
---|
| 89 | public ICollection<Resource> GetAllResources() {
|
---|
[845] | 90 | ICollection<Resource> allResources =
|
---|
| 91 | new List<Resource>();
|
---|
| 92 |
|
---|
| 93 | dsHiveServer.ResourceDataTable data =
|
---|
| 94 | adapter.GetData();
|
---|
| 95 |
|
---|
| 96 | foreach (dsHiveServer.ResourceRow row in data) {
|
---|
| 97 | allResources.Add(Convert(row));
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | return allResources;
|
---|
[826] | 101 | }
|
---|
| 102 |
|
---|
| 103 | public bool DeleteResource(Resource resource) {
|
---|
[845] | 104 | if(resource != null) {
|
---|
[826] | 105 |
|
---|
[845] | 106 | dsHiveServer.ResourceDataTable data =
|
---|
| 107 | adapter.GetDataById(resource.ResourceId);
|
---|
[826] | 108 |
|
---|
[845] | 109 | if (data.Count == 1) {
|
---|
| 110 | dsHiveServer.ResourceRow row = data[0];
|
---|
| 111 |
|
---|
| 112 | row.Delete();
|
---|
| 113 | return adapter.Update(data) > 0;
|
---|
| 114 | }
|
---|
[826] | 115 | }
|
---|
[845] | 116 |
|
---|
| 117 | return false;
|
---|
[826] | 118 | }
|
---|
| 119 |
|
---|
| 120 | #endregion
|
---|
| 121 | }
|
---|
| 122 | }
|
---|