Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ResourceAdapter.cs @ 1584

Last change on this file since 1584 was 1580, checked in by svonolfe, 16 years ago

Added PluginInfoAdapter (#372)

File size: 3.1 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
[1377]26using HeuristicLab.Hive.Server.DataAccess;
[826]27using HeuristicLab.Hive.Contracts.BusinessObjects;
[1377]28using HeuristicLab.DataAccess.ADOHelper;
[1468]29using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
30using System.Data.Common;
31using System.Data.SqlClient;
[1580]32using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
[826]33
34namespace HeuristicLab.Hive.Server.ADODataAccess {
[995]35  class ResourceAdapter:
[1468]36    DataAdapterBase<
[995]37      dsHiveServerTableAdapters.ResourceTableAdapter,
38      Resource,
[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 =
48            this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
[995]49       
50        return clientAdapter;
51      }
[925]52    }
[995]53    #endregion
[925]54
[1468]55    public ResourceAdapter(): base(new ResourceAdapterWrapper()) {
56    }
57
[995]58    #region Overrides
[1131]59    protected override Resource ConvertRow(dsHiveServer.ResourceRow row,
[899]60      Resource resource) {
61      if (row != null && resource != null) {
[995]62        resource.Id = row.ResourceId;
[899]63        if (!row.IsNameNull())
64          resource.Name = row.Name;
65        else
66          resource.Name = String.Empty;
[845]67
68        return resource;
[925]69      } else
[845]70        return null;
71    }
72
[1131]73    protected override dsHiveServer.ResourceRow ConvertObj(Resource resource,
[845]74      dsHiveServer.ResourceRow row) {
75      if (resource != null && row != null) {
[1449]76        row.ResourceId = resource.Id;
[845]77        row.Name = resource.Name;
78
[899]79        return row;
80      } else
81        return null;
[845]82    }
[995]83    #endregion
84
85    #region IResourceAdapter Members
86    public bool GetById(Resource resource) {
[899]87      if (resource != null) {
[925]88        dsHiveServer.ResourceRow row =
[995]89          GetRowById(resource.Id);
90
[925]91        if (row != null) {
[899]92          Convert(row, resource);
93
94          return true;
95        }
96      }
97
98      return false;
99    }
100
[995]101    public Resource GetByName(string name) {
[1515]102      return
103        base.FindSingle (
[995]104          delegate() {
[1131]105            return Adapter.GetDataByName(name);
[995]106          });
[971]107    }
108
[826]109    #endregion
110  }
111}
Note: See TracBrowser for help on using the repository browser.