1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
6 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
7 |
|
---|
8 | namespace 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 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 |
|
---|
55 | if (result.Client != null)
|
---|
56 | row.ResourceId = result.Client.Id;
|
---|
57 | else
|
---|
58 | row.SetResourceIdNull();
|
---|
59 |
|
---|
60 | return row;
|
---|
61 | } else
|
---|
62 | return null;
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override JobResult Convert(dsHiveServer.JobResultRow row,
|
---|
66 | JobResult result) {
|
---|
67 | if (row != null && result != null) {
|
---|
68 | result.Id = row.JobResultId;
|
---|
69 |
|
---|
70 | if (!row.IsJobIdNull())
|
---|
71 | result.Job = JobAdapter.GetById(row.JobId);
|
---|
72 | else
|
---|
73 | result.Job = null;
|
---|
74 |
|
---|
75 | if (!row.IsJobResultNull())
|
---|
76 | result.Result = row.JobResult;
|
---|
77 | else
|
---|
78 | result.Result = null;
|
---|
79 |
|
---|
80 | if (!row.IsResourceIdNull())
|
---|
81 | result.Client = ClientAdapter.GetById(row.ResourceId);
|
---|
82 | else
|
---|
83 | result.Client = null;
|
---|
84 |
|
---|
85 | return result;
|
---|
86 | } else
|
---|
87 | return null;
|
---|
88 | }
|
---|
89 |
|
---|
90 | protected override void UpdateRow(dsHiveServer.JobResultRow row) {
|
---|
91 | adapter.Update(row);
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
|
---|
95 | dsHiveServer.JobResultRow row = data.NewJobResultRow();
|
---|
96 | data.AddJobResultRow(row);
|
---|
97 |
|
---|
98 | return row;
|
---|
99 | }
|
---|
100 |
|
---|
101 | protected override IEnumerable<dsHiveServer.JobResultRow> FindById(long id) {
|
---|
102 | return adapter.GetDataById(id);
|
---|
103 | }
|
---|
104 |
|
---|
105 | protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
|
---|
106 | return adapter.GetData();
|
---|
107 | }
|
---|
108 | #endregion
|
---|
109 |
|
---|
110 | #region IJobResultsAdapter Members
|
---|
111 | public override void Update(JobResult result) {
|
---|
112 | if (result != null) {
|
---|
113 | ClientAdapter.Update(result.Client);
|
---|
114 | JobAdapter.Update(result.Job);
|
---|
115 |
|
---|
116 | base.Update(result);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | public ICollection<JobResult> GetResultsOf(Job job) {
|
---|
121 | if (job != null) {
|
---|
122 | return
|
---|
123 | base.FindMultiple(
|
---|
124 | delegate() {
|
---|
125 | return adapter.GetDataByJob(job.Id);
|
---|
126 | });
|
---|
127 | }
|
---|
128 |
|
---|
129 | return null;
|
---|
130 | }
|
---|
131 | #endregion
|
---|
132 | }
|
---|
133 | }
|
---|