Free cookie consent management tool by TermsFeed Policy Generator

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

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

Changed SendJobResult Interface (#351)

File size: 3.9 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    dsHiveServer.JobResultDataTable data =
16        new dsHiveServer.JobResultDataTable();
17
18    private IClientAdapter clientAdapter = null;
19
20    private IClientAdapter ClientAdapter {
21      get {
22        if (clientAdapter == null)
23          clientAdapter = ServiceLocator.GetClientAdapter();
24
25        return clientAdapter;
26      }
[1000]27    }
28
[1005]29    private IJobAdapter jobAdapter = null;
30
31    private IJobAdapter JobAdapter {
32      get {
33        if (jobAdapter == null)
34          jobAdapter = ServiceLocator.GetJobAdapter();
35
36        return jobAdapter;
37      }
[1000]38    }
[1005]39    #endregion
[1000]40
[1005]41    #region Overrides
42    protected override dsHiveServer.JobResultRow Convert(JobResult result,
43      dsHiveServer.JobResultRow row) {
44      if (row != null && result != null) {
45        if (result.Job != null)
46          row.JobId = result.Job.Id;
47        else
48          row.SetJobIdNull();
49
50        if (result.Result != null)
51          row.JobResult = result.Result;
52        else
53          row.SetJobResultNull();
54
[1017]55        if (result.Client != null)  {
56          ClientInfo client =
57                 ClientAdapter.GetById(result.Client.ClientId);
58
59          if (client != null)
60            row.ResourceId = client.Id;
61          else
62            row.SetResourceIdNull();
63        }           
[1005]64        else
65          row.SetResourceIdNull();
66
[1103]67        if (result.Exception != null)
68          row.Message = result.Exception.ToString();
[1092]69        else
70          row.SetMessageNull();
71
[1005]72        return row;
73      } else
74        return null;
[1000]75    }
76
[1005]77    protected override JobResult Convert(dsHiveServer.JobResultRow row,
78      JobResult result) {
79      if (row != null && result != null) {
80        result.Id = row.JobResultId;
81
82        if (!row.IsJobIdNull())
83          result.Job = JobAdapter.GetById(row.JobId);
84        else
85          result.Job = null;
86
87        if (!row.IsJobResultNull())
88          result.Result = row.JobResult;
89        else
90          result.Result = null;
91
92        if (!row.IsResourceIdNull())
93          result.Client = ClientAdapter.GetById(row.ResourceId);
94        else
95          result.Client = null;
96
[1092]97        if (!row.IsMessageNull())
[1103]98          result.Exception = new Exception(row.Message);
[1092]99        else
[1103]100          result.Exception = null;
[1092]101
[1005]102        return result;
103      } else
104        return null;
105    }
106
[1000]107    protected override void UpdateRow(dsHiveServer.JobResultRow row) {
[1005]108      adapter.Update(row);
[1000]109    }
110
[1005]111    protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
112      dsHiveServer.JobResultRow row = data.NewJobResultRow();
113      data.AddJobResultRow(row);
114
115      return row;
116    }
117
[1000]118    protected override IEnumerable<dsHiveServer.JobResultRow> FindById(long id) {
[1005]119      return adapter.GetDataById(id);
[1000]120    }
121
122    protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
[1005]123      return adapter.GetData();
[1000]124    }
125    #endregion
126
127    #region IJobResultsAdapter Members
[1005]128    public override void Update(JobResult result) {
129      if (result != null) {
130        ClientAdapter.Update(result.Client);
131        JobAdapter.Update(result.Job);
[1000]132
[1005]133        base.Update(result);
134      }
[1000]135    }
136
[1005]137    public ICollection<JobResult> GetResultsOf(Job job) {
138      if (job != null) {
139        return
140          base.FindMultiple(
141            delegate() {
142              return adapter.GetDataByJob(job.Id);
143            });
144      }
[1000]145
[1005]146      return null;
[1000]147    }
148    #endregion
149  }
150}
Note: See TracBrowser for help on using the repository browser.