Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3381 was 3011, checked in by kgrading, 15 years ago

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

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