[3011] | 1 | #region License Information
|
---|
[826] | 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;
|
---|
[1377] | 26 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[826] | 27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[1377] | 28 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
[1468] | 29 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
| 30 | using System.Data.Common;
|
---|
| 31 | using System.Data.SqlClient;
|
---|
[1580] | 32 | using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
|
---|
[826] | 33 |
|
---|
| 34 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[995] | 35 | class ResourceAdapter:
|
---|
[1468] | 36 | DataAdapterBase<
|
---|
[995] | 37 | dsHiveServerTableAdapters.ResourceTableAdapter,
|
---|
[3011] | 38 | ResourceDto,
|
---|
[1468] | 39 | dsHiveServer.ResourceRow>,
|
---|
[995] | 40 | IResourceAdapter {
|
---|
| 41 | #region Fields
|
---|
| 42 | private IClientAdapter clientAdapter = null;
|
---|
[925] | 43 |
|
---|
[995] | 44 | private IClientAdapter ClientAdapter {
|
---|
| 45 | get {
|
---|
| 46 | if (clientAdapter == null)
|
---|
[1468] | 47 | clientAdapter =
|
---|
[3011] | 48 | this.Session.GetDataAdapter<ClientDto, IClientAdapter>();
|
---|
[995] | 49 |
|
---|
| 50 | return clientAdapter;
|
---|
| 51 | }
|
---|
[925] | 52 | }
|
---|
[1597] | 53 |
|
---|
| 54 | private IClientGroupAdapter clientGroupAdapter = null;
|
---|
| 55 |
|
---|
| 56 | private IClientGroupAdapter ClientGroupAdapter {
|
---|
| 57 | get {
|
---|
| 58 | if (clientGroupAdapter == null)
|
---|
| 59 | clientGroupAdapter =
|
---|
[3011] | 60 | this.Session.GetDataAdapter<ClientGroupDto, IClientGroupAdapter>();
|
---|
[1597] | 61 |
|
---|
| 62 | return clientGroupAdapter;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
[995] | 65 | #endregion
|
---|
[925] | 66 |
|
---|
[1468] | 67 | public ResourceAdapter(): base(new ResourceAdapterWrapper()) {
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[995] | 70 | #region Overrides
|
---|
[3011] | 71 | protected override ResourceDto ConvertRow(dsHiveServer.ResourceRow row,
|
---|
| 72 | ResourceDto resource) {
|
---|
[899] | 73 | if (row != null && resource != null) {
|
---|
[995] | 74 | resource.Id = row.ResourceId;
|
---|
[899] | 75 | if (!row.IsNameNull())
|
---|
| 76 | resource.Name = row.Name;
|
---|
| 77 | else
|
---|
| 78 | resource.Name = String.Empty;
|
---|
[845] | 79 |
|
---|
| 80 | return resource;
|
---|
[925] | 81 | } else
|
---|
[845] | 82 | return null;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[3011] | 85 | protected override dsHiveServer.ResourceRow ConvertObj(ResourceDto resource,
|
---|
[845] | 86 | dsHiveServer.ResourceRow row) {
|
---|
| 87 | if (resource != null && row != null) {
|
---|
[1449] | 88 | row.ResourceId = resource.Id;
|
---|
[845] | 89 | row.Name = resource.Name;
|
---|
| 90 |
|
---|
[899] | 91 | return row;
|
---|
| 92 | } else
|
---|
| 93 | return null;
|
---|
[845] | 94 | }
|
---|
[995] | 95 | #endregion
|
---|
| 96 |
|
---|
| 97 | #region IResourceAdapter Members
|
---|
[3011] | 98 | public bool GetById(ResourceDto resource) {
|
---|
[899] | 99 | if (resource != null) {
|
---|
[925] | 100 | dsHiveServer.ResourceRow row =
|
---|
[995] | 101 | GetRowById(resource.Id);
|
---|
| 102 |
|
---|
[925] | 103 | if (row != null) {
|
---|
[899] | 104 | Convert(row, resource);
|
---|
| 105 |
|
---|
| 106 | return true;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | return false;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[3011] | 113 | public ResourceDto GetByName(string name) {
|
---|
[1515] | 114 | return
|
---|
| 115 | base.FindSingle (
|
---|
[995] | 116 | delegate() {
|
---|
[1131] | 117 | return Adapter.GetDataByName(name);
|
---|
[995] | 118 | });
|
---|
[971] | 119 | }
|
---|
| 120 |
|
---|
[826] | 121 | #endregion
|
---|
[1597] | 122 |
|
---|
| 123 | #region IPolymorphicDataAdapter<Resource> Members
|
---|
| 124 |
|
---|
[3011] | 125 | public void UpdatePolymorphic(ResourceDto res) {
|
---|
| 126 | if (res is ClientDto) {
|
---|
| 127 | ClientAdapter.Update(res as ClientDto);
|
---|
| 128 | } else if (res is ClientGroupDto) {
|
---|
| 129 | ClientGroupAdapter.Update(res as ClientGroupDto);
|
---|
[1597] | 130 | } else {
|
---|
| 131 | this.Update(res);
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[3011] | 135 | public ResourceDto GetByIdPolymorphic(Guid id) {
|
---|
| 136 | ClientGroupDto group =
|
---|
[1597] | 137 | ClientGroupAdapter.GetById(id);
|
---|
| 138 |
|
---|
| 139 | if (group != null)
|
---|
| 140 | return group;
|
---|
| 141 | else {
|
---|
[3011] | 142 | ClientDto client =
|
---|
[1597] | 143 | ClientAdapter.GetById(id);
|
---|
| 144 |
|
---|
| 145 | if (client != null)
|
---|
| 146 | return client;
|
---|
| 147 | else {
|
---|
| 148 | return this.GetById(id);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[3011] | 153 | public bool DeletePolymorphic(ResourceDto res) {
|
---|
| 154 | if (res is ClientDto) {
|
---|
| 155 | return ClientAdapter.Delete(res as ClientDto);
|
---|
| 156 | } else if (res is ClientGroupDto) {
|
---|
| 157 | return ClientGroupAdapter.Delete(res as ClientGroupDto);
|
---|
[1597] | 158 | } else {
|
---|
| 159 | return this.Delete(res);
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | #endregion
|
---|
[826] | 164 | }
|
---|
| 165 | }
|
---|