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 | 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.Message != null)
|
---|
68 | row.Message = result.Message;
|
---|
69 | else
|
---|
70 | row.SetMessageNull();
|
---|
71 |
|
---|
72 | return row;
|
---|
73 | } else
|
---|
74 | return null;
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected override JobResult Convert(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.Message = row.Message;
|
---|
99 | else
|
---|
100 | result.Message = 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 | }
|
---|