Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ClientAdapter.cs @ 2534

Last change on this file since 2534 was 2082, checked in by svonolfe, 15 years ago

Avoid out of memory exceptions related to job objects (#372)

File size: 6.4 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;
[925]28using System.Linq.Expressions;
[1377]29using HeuristicLab.DataAccess.Interfaces;
30using HeuristicLab.DataAccess.ADOHelper;
[1468]31using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
32using System.Data.Common;
33using System.Data.SqlClient;
[1580]34using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
[826]35
36namespace HeuristicLab.Hive.Server.ADODataAccess {
[995]37  class ClientAdapter:
[1468]38    DataAdapterBase<
[995]39      dsHiveServerTableAdapters.ClientTableAdapter,
40      ClientInfo,
[1468]41      dsHiveServer.ClientRow>,
[995]42    IClientAdapter {
43    #region Fields
[948]44    private IResourceAdapter resAdapter = null;
[925]45
[948]46    private IResourceAdapter ResAdapter {
47      get {
48        if (resAdapter == null)
[1468]49          resAdapter =
50            this.Session.GetDataAdapter<Resource, IResourceAdapter>();
[948]51
52        return resAdapter;
53      }
54    }
55
[965]56    private IClientGroupAdapter clientGroupAdapter = null;
57
58    private IClientGroupAdapter ClientGroupAdapter {
59      get {
60        if (clientGroupAdapter == null) {
[1468]61          clientGroupAdapter =
62            this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
[965]63        }
64
65        return clientGroupAdapter;
66      }
67    }
68
[971]69    private IJobAdapter jobAdapter = null;
70
71    private IJobAdapter JobAdapter {
72      get {
73        if (jobAdapter == null) {
[1468]74          this.Session.GetDataAdapter<Job, IJobAdapter>();
[971]75        }
76
77        return jobAdapter;
78      }
79    }
[1999]80
81    private IClientConfigAdapter clientConfigAdapter = null;
82
83    private IClientConfigAdapter ClientConfigAdapter {
84      get {
85        if (clientConfigAdapter == null) {
86          clientConfigAdapter =
87            this.Session.GetDataAdapter<ClientConfig, IClientConfigAdapter>();
88        }
89
90        return clientConfigAdapter;
91      }
92    }
[995]93    #endregion
[971]94
[1468]95    public ClientAdapter():
96      base(new ClientAdapterWrapper()) {
[925]97    }
98
[995]99    #region Overrides
[1131]100    protected override ClientInfo ConvertRow(dsHiveServer.ClientRow row,
[899]101      ClientInfo client) {
102      if(row != null && client != null) {     
[845]103        /*Parent - resource*/
[995]104        client.Id = row.ResourceId;
105        ResAdapter.GetById(client);
[826]106
[1449]107        /*ClientInfo*/       
[899]108        if (!row.IsCPUSpeedNull())
109          client.CpuSpeedPerCore = row.CPUSpeed;
110        else
111          client.CpuSpeedPerCore = 0;
112
113        if (!row.IsMemoryNull())
114          client.Memory = row.Memory;
115        else
116          client.Memory = 0;
117
118        if (!row.IsLoginNull())
119          client.Login = row.Login;
120        else
121          client.Login = DateTime.MinValue;
122
123        if (!row.IsStatusNull())
[845]124          client.State = (State)Enum.Parse(typeof(State), row.Status, true);
[899]125        else
[995]126          client.State = State.nullState;
[845]127
[899]128        if (!row.IsNumberOfCoresNull())
129          client.NrOfCores = row.NumberOfCores;
130        else
131          client.NrOfCores = 0;
132
[1505]133        if (!row.IsNumberOfFreeCoresNull())
134          client.NrOfFreeCores = row.NumberOfFreeCores;
135        else
136          client.NrOfFreeCores = 0;
137
138        if (!row.IsFreeMemoryNull())
139          client.FreeMemory = row.FreeMemory;
140        else
141          client.FreeMemory = 0;
142
[1999]143        if (!row.IsClientConfigIdNull())
144          client.Config = ClientConfigAdapter.GetById(row.ClientConfigId);
145        else
146          client.Config = null;
[845]147
148        return client;
149      }
150      else
151        return null;
152    }
153
[1131]154    protected override dsHiveServer.ClientRow ConvertObj(ClientInfo client,
[845]155      dsHiveServer.ClientRow row) {
[1449]156      if (client != null && row != null) {
157        row.ResourceId = client.Id;
[845]158        row.CPUSpeed = client.CpuSpeedPerCore;
159        row.Memory = client.Memory;
160        row.Login = client.Login;
[995]161        if (client.State != State.nullState)
162          row.Status = client.State.ToString();
163        else
164          row.SetStatusNull();
[845]165        row.NumberOfCores = client.NrOfCores;
[1505]166        row.NumberOfFreeCores = client.NrOfFreeCores;
167        row.FreeMemory = client.FreeMemory;
[845]168
[1999]169        if (client.Config != null)
170          row.ClientConfigId = client.Config.Id;
171        else
172          row.SetClientConfigIdNull();
[845]173      }
174
175      return row;
176    }
177
[995]178    #endregion
[965]179
[995]180    #region IClientAdapter Members
[1468]181    protected override void doUpdate(ClientInfo client) {
[995]182      if (client != null) {
183        ResAdapter.Update(client);
[1999]184        ClientConfigAdapter.Update(client.Config);
[971]185
[1468]186        base.doUpdate(client);
[971]187      }
[995]188    }
[971]189
[995]190    public ClientInfo GetByName(string name) {
[2082]191      return (ClientInfo)
192        base.doInTransaction(
193        delegate() {
194          ClientInfo client = new ClientInfo();
195          Resource res =
196            ResAdapter.GetByName(name);
[826]197
[2082]198          return GetById(res.Id);
199        });
[826]200    }
201
[1468]202    protected override bool doDelete(ClientInfo client) {
[2082]203      return (bool)base.doInTransaction(
204        delegate() {
205          bool success = false;
[925]206
[2082]207          if (client != null) {
208            dsHiveServer.ClientRow row =
209              GetRowById(client.Id);
[925]210
[2082]211            if (row != null) {
212              success = base.doDelete(client) &&
213                ResAdapter.Delete(client);
214            }
215          }
216
217          return success;
218        });
[826]219    }
220
[1632]221    public ICollection<ClientInfo> GetGrouplessClients() {
[1634]222      return
223        base.FindMultiple(
224          delegate() {
225            return Adapter.GetDataByGroupless();
226          });
[1632]227    }
228
[826]229    #endregion
230  }
231}
Note: See TracBrowser for help on using the repository browser.