Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3149 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
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;
[1468]8using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
9using System.Data.Common;
10using System.Data.SqlClient;
[1580]11using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
[2117]12using System.IO;
[1000]13
14namespace HeuristicLab.Hive.Server.ADODataAccess {
15  class JobResultsAdapter:
16    DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter,
17                    JobResult,
18                    dsHiveServer.JobResultRow>,
19    IJobResultsAdapter {
[1005]20    #region Fields
21    private IClientAdapter clientAdapter = null;
22
23    private IClientAdapter ClientAdapter {
24      get {
25        if (clientAdapter == null)
[1468]26          clientAdapter =
[3011]27            this.Session.GetDataAdapter<ClientDto, IClientAdapter>();
[1005]28
29        return clientAdapter;
30      }
[1000]31    }
32
[1005]33    private IJobAdapter jobAdapter = null;
34
35    private IJobAdapter JobAdapter {
36      get {
37        if (jobAdapter == null)
[1468]38          jobAdapter =
[3011]39            this.Session.GetDataAdapter<JobDto, IJobAdapter>();
[1005]40
41        return jobAdapter;
42      }
[1000]43    }
[1005]44    #endregion
[1000]45
[1468]46    public JobResultsAdapter(): base(new JobResultsAdapterWrapper()) {
47    }
48
[1005]49    #region Overrides
[1131]50    protected override dsHiveServer.JobResultRow ConvertObj(JobResult result,
[1005]51      dsHiveServer.JobResultRow row) {
52      if (row != null && result != null) {
[1939]53        if (result.JobId != Guid.Empty)
54          row.JobId = result.JobId;
[1005]55        else
56          row.SetJobIdNull();
57
[1939]58        if (result.ClientId != Guid.Empty)  {
[3011]59          ClientDto client =
[1939]60                 ClientAdapter.GetById(result.ClientId);
[1017]61
62          if (client != null)
63            row.ResourceId = client.Id;
64          else
65            row.SetResourceIdNull();
66        }           
[1005]67        else
68          row.SetResourceIdNull();
69
[1103]70        if (result.Exception != null)
71          row.Message = result.Exception.ToString();
[1092]72        else
73          row.SetMessageNull();
74
[1169]75        row.Percentage = result.Percentage;
76
77        if (result.DateFinished != DateTime.MinValue)
78          row.DateFinished = result.DateFinished;
79        else
80          row.SetDateFinishedNull();
81
[1005]82        return row;
83      } else
84        return null;
[1000]85    }
86
[1131]87    protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
[1005]88      JobResult result) {
89      if (row != null && result != null) {
90        result.Id = row.JobResultId;
91
92        if (!row.IsJobIdNull())
[1939]93          result.JobId = row.JobId;
[1005]94        else
[1939]95          result.JobId = Guid.Empty;
[1005]96
97        if (!row.IsResourceIdNull())
[1939]98          result.ClientId = row.ResourceId;
[1005]99        else
[1939]100          result.ClientId = Guid.Empty;
[1005]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    }
[1000]118    #endregion
119
120    #region IJobResultsAdapter Members
[2099]121    public ICollection<JobResult> GetResultsOf(Guid jobId) {
[1005]122        return
123          base.FindMultiple(
124            delegate() {
[2099]125              return Adapter.GetDataByJob(jobId);
[1005]126            });
[1000]127    }
[2086]128
[2099]129    public JobResult GetLastResultOf(Guid jobId) {
[2086]130        return
131          base.FindSingle(
132            delegate() {
[2099]133              return Adapter.GetDataByLastResult(jobId);
[2086]134            });
[2099]135    }
[2086]136
[2099]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        });
[2086]153    }
[2099]154
[2117]155    public Stream GetSerializedJobResultStream(Guid jobResultId, bool useExistingConnection) {
156      return
157        ((JobResultsAdapterWrapper)
158        base.DataAdapterWrapper).
159          GetSerializedJobResultStream(jobResultId, useExistingConnection);
160    }
161
[2099]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    }
[1000]174    #endregion
175  }
176}
Note: See TracBrowser for help on using the repository browser.