Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobResultsAdapter.cs @ 1197

Last change on this file since 1197 was 1169, checked in by svonolfe, 16 years ago

Added job attributes to DB (#372)

File size: 4.3 KB
RevLine 
[1000]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
6using HeuristicLab.Hive.Contracts.BusinessObjects;
7
8namespace HeuristicLab.Hive.Server.ADODataAccess {
9  class JobResultsAdapter:
10    DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter,
11                    JobResult,
12                    dsHiveServer.JobResultRow>,
13    IJobResultsAdapter {
[1005]14    #region Fields
15    private IClientAdapter clientAdapter = null;
16
17    private IClientAdapter ClientAdapter {
18      get {
19        if (clientAdapter == null)
20          clientAdapter = ServiceLocator.GetClientAdapter();
21
22        return clientAdapter;
23      }
[1000]24    }
25
[1005]26    private IJobAdapter jobAdapter = null;
27
28    private IJobAdapter JobAdapter {
29      get {
30        if (jobAdapter == null)
31          jobAdapter = ServiceLocator.GetJobAdapter();
32
33        return jobAdapter;
34      }
[1000]35    }
[1005]36    #endregion
[1000]37
[1005]38    #region Overrides
[1131]39    protected override dsHiveServer.JobResultRow ConvertObj(JobResult result,
[1005]40      dsHiveServer.JobResultRow row) {
41      if (row != null && result != null) {
42        if (result.Job != null)
43          row.JobId = result.Job.Id;
44        else
45          row.SetJobIdNull();
46
47        if (result.Result != null)
48          row.JobResult = result.Result;
49        else
50          row.SetJobResultNull();
51
[1017]52        if (result.Client != null)  {
53          ClientInfo client =
54                 ClientAdapter.GetById(result.Client.ClientId);
55
56          if (client != null)
57            row.ResourceId = client.Id;
58          else
59            row.SetResourceIdNull();
60        }           
[1005]61        else
62          row.SetResourceIdNull();
63
[1103]64        if (result.Exception != null)
65          row.Message = result.Exception.ToString();
[1092]66        else
67          row.SetMessageNull();
68
[1169]69        row.Percentage = result.Percentage;
70
71        if (result.DateFinished != DateTime.MinValue)
72          row.DateFinished = result.DateFinished;
73        else
74          row.SetDateFinishedNull();
75
[1005]76        return row;
77      } else
78        return null;
[1000]79    }
80
[1131]81    protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
[1005]82      JobResult result) {
83      if (row != null && result != null) {
84        result.Id = row.JobResultId;
85
86        if (!row.IsJobIdNull())
87          result.Job = JobAdapter.GetById(row.JobId);
88        else
89          result.Job = null;
90
91        if (!row.IsJobResultNull())
92          result.Result = row.JobResult;
93        else
94          result.Result = null;
95
96        if (!row.IsResourceIdNull())
97          result.Client = ClientAdapter.GetById(row.ResourceId);
98        else
99          result.Client = null;
100
[1092]101        if (!row.IsMessageNull())
[1103]102          result.Exception = new Exception(row.Message);
[1092]103        else
[1103]104          result.Exception = null;
[1092]105
[1169]106        result.Percentage = row.Percentage;
107
108        if (!row.IsDateFinishedNull())
109          result.DateFinished = row.DateFinished;
110        else
111          result.DateFinished = DateTime.MinValue;
112
[1005]113        return result;
114      } else
115        return null;
116    }
117
[1000]118    protected override void UpdateRow(dsHiveServer.JobResultRow row) {
[1131]119      Adapter.Update(row);
[1000]120    }
121
[1005]122    protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
[1166]123      dsHiveServer.JobResultDataTable data =
124        new dsHiveServer.JobResultDataTable();
125
[1005]126      dsHiveServer.JobResultRow row = data.NewJobResultRow();
127      data.AddJobResultRow(row);
128
129      return row;
130    }
131
[1000]132    protected override IEnumerable<dsHiveServer.JobResultRow> FindById(long id) {
[1131]133      return Adapter.GetDataById(id);
[1000]134    }
135
136    protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
[1131]137      return Adapter.GetData();
[1000]138    }
139    #endregion
140
141    #region IJobResultsAdapter Members
[1005]142    public override void Update(JobResult result) {
143      if (result != null) {
144        ClientAdapter.Update(result.Client);
145        JobAdapter.Update(result.Job);
[1000]146
[1005]147        base.Update(result);
148      }
[1000]149    }
150
[1005]151    public ICollection<JobResult> GetResultsOf(Job job) {
152      if (job != null) {
153        return
154          base.FindMultiple(
155            delegate() {
[1131]156              return Adapter.GetDataByJob(job.Id);
[1005]157            });
158      }
[1000]159
[1005]160      return null;
[1000]161    }
162    #endregion
163  }
164}
Note: See TracBrowser for help on using the repository browser.