Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2106 was 2099, checked in by svonolfe, 15 years ago

Further avoided out of memory exceptions by updating the JobResult DAO (#372)

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