Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1378 was 1377, checked in by svonolfe, 16 years ago

Created Heuristiclab DB Core (refactoring) #527

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