Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1134 was 1131, checked in by svonolfe, 15 years ago

fixed race condition issues, improved performance (#372)

File size: 3.9 KB
Line 
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 {
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      }
27    }
28
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      }
38    }
39    #endregion
40
41    #region Overrides
42    protected override dsHiveServer.JobResultRow ConvertObj(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
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        }           
64        else
65          row.SetResourceIdNull();
66
67        if (result.Exception != null)
68          row.Message = result.Exception.ToString();
69        else
70          row.SetMessageNull();
71
72        return row;
73      } else
74        return null;
75    }
76
77    protected override JobResult ConvertRow(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
97        if (!row.IsMessageNull())
98          result.Exception = new Exception(row.Message);
99        else
100          result.Exception = null;
101
102        return result;
103      } else
104        return null;
105    }
106
107    protected override void UpdateRow(dsHiveServer.JobResultRow row) {
108      Adapter.Update(row);
109    }
110
111    protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
112      dsHiveServer.JobResultRow row = data.NewJobResultRow();
113      data.AddJobResultRow(row);
114
115      return row;
116    }
117
118    protected override IEnumerable<dsHiveServer.JobResultRow> FindById(long id) {
119      return Adapter.GetDataById(id);
120    }
121
122    protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
123      return Adapter.GetData();
124    }
125    #endregion
126
127    #region IJobResultsAdapter Members
128    public override void Update(JobResult result) {
129      if (result != null) {
130        ClientAdapter.Update(result.Client);
131        JobAdapter.Update(result.Job);
132
133        base.Update(result);
134      }
135    }
136
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      }
145
146      return null;
147    }
148    #endregion
149  }
150}
Note: See TracBrowser for help on using the repository browser.