[1000] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
[1377] | 5 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[1000] | 6 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[1377] | 7 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
[1468] | 8 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
| 9 | using System.Data.Common;
|
---|
| 10 | using System.Data.SqlClient;
|
---|
[1000] | 11 |
|
---|
| 12 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[1468] | 13 | class JobResultsAdapterWrapper :
|
---|
| 14 | DataAdapterWrapperBase<dsHiveServerTableAdapters.JobResultTableAdapter,
|
---|
| 15 | JobResult,
|
---|
| 16 | dsHiveServer.JobResultRow> {
|
---|
| 17 | public override void UpdateRow(dsHiveServer.JobResultRow row) {
|
---|
| 18 | TransactionalAdapter.Update(row);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
|
---|
| 22 | dsHiveServer.JobResultDataTable data =
|
---|
| 23 | new dsHiveServer.JobResultDataTable();
|
---|
| 24 |
|
---|
| 25 | dsHiveServer.JobResultRow row = data.NewJobResultRow();
|
---|
| 26 | row.JobResultId = obj.Id;
|
---|
| 27 | data.AddJobResultRow(row);
|
---|
| 28 |
|
---|
| 29 | return row;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public override IEnumerable<dsHiveServer.JobResultRow> FindById(Guid id) {
|
---|
| 33 | return TransactionalAdapter.GetDataById(id);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
|
---|
| 37 | return TransactionalAdapter.GetData();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | protected override void SetConnection(DbConnection connection) {
|
---|
| 41 | adapter.Connection = connection as SqlConnection;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | protected override void SetTransaction(DbTransaction transaction) {
|
---|
| 45 | adapter.Transaction = transaction as SqlTransaction;
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[1000] | 49 | class JobResultsAdapter:
|
---|
| 50 | DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter,
|
---|
| 51 | JobResult,
|
---|
| 52 | dsHiveServer.JobResultRow>,
|
---|
| 53 | IJobResultsAdapter {
|
---|
[1005] | 54 | #region Fields
|
---|
| 55 | private IClientAdapter clientAdapter = null;
|
---|
| 56 |
|
---|
| 57 | private IClientAdapter ClientAdapter {
|
---|
| 58 | get {
|
---|
| 59 | if (clientAdapter == null)
|
---|
[1468] | 60 | clientAdapter =
|
---|
| 61 | this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[1005] | 62 |
|
---|
| 63 | return clientAdapter;
|
---|
| 64 | }
|
---|
[1000] | 65 | }
|
---|
| 66 |
|
---|
[1005] | 67 | private IJobAdapter jobAdapter = null;
|
---|
| 68 |
|
---|
| 69 | private IJobAdapter JobAdapter {
|
---|
| 70 | get {
|
---|
| 71 | if (jobAdapter == null)
|
---|
[1468] | 72 | jobAdapter =
|
---|
| 73 | this.Session.GetDataAdapter<Job, IJobAdapter>();
|
---|
[1005] | 74 |
|
---|
| 75 | return jobAdapter;
|
---|
| 76 | }
|
---|
[1000] | 77 | }
|
---|
[1005] | 78 | #endregion
|
---|
[1000] | 79 |
|
---|
[1468] | 80 | public JobResultsAdapter(): base(new JobResultsAdapterWrapper()) {
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[1005] | 83 | #region Overrides
|
---|
[1131] | 84 | protected override dsHiveServer.JobResultRow ConvertObj(JobResult result,
|
---|
[1005] | 85 | dsHiveServer.JobResultRow row) {
|
---|
| 86 | if (row != null && result != null) {
|
---|
| 87 | if (result.Job != null)
|
---|
| 88 | row.JobId = result.Job.Id;
|
---|
| 89 | else
|
---|
| 90 | row.SetJobIdNull();
|
---|
| 91 |
|
---|
| 92 | if (result.Result != null)
|
---|
| 93 | row.JobResult = result.Result;
|
---|
| 94 | else
|
---|
| 95 | row.SetJobResultNull();
|
---|
| 96 |
|
---|
[1017] | 97 | if (result.Client != null) {
|
---|
| 98 | ClientInfo client =
|
---|
[1449] | 99 | ClientAdapter.GetById(result.Client.Id);
|
---|
[1017] | 100 |
|
---|
| 101 | if (client != null)
|
---|
| 102 | row.ResourceId = client.Id;
|
---|
| 103 | else
|
---|
| 104 | row.SetResourceIdNull();
|
---|
| 105 | }
|
---|
[1005] | 106 | else
|
---|
| 107 | row.SetResourceIdNull();
|
---|
| 108 |
|
---|
[1103] | 109 | if (result.Exception != null)
|
---|
| 110 | row.Message = result.Exception.ToString();
|
---|
[1092] | 111 | else
|
---|
| 112 | row.SetMessageNull();
|
---|
| 113 |
|
---|
[1169] | 114 | row.Percentage = result.Percentage;
|
---|
| 115 |
|
---|
| 116 | if (result.DateFinished != DateTime.MinValue)
|
---|
| 117 | row.DateFinished = result.DateFinished;
|
---|
| 118 | else
|
---|
| 119 | row.SetDateFinishedNull();
|
---|
| 120 |
|
---|
[1005] | 121 | return row;
|
---|
| 122 | } else
|
---|
| 123 | return null;
|
---|
[1000] | 124 | }
|
---|
| 125 |
|
---|
[1131] | 126 | protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
|
---|
[1005] | 127 | JobResult result) {
|
---|
| 128 | if (row != null && result != null) {
|
---|
[1449] | 129 | row.JobResultId = result.Id;
|
---|
[1005] | 130 | result.Id = row.JobResultId;
|
---|
| 131 |
|
---|
| 132 | if (!row.IsJobIdNull())
|
---|
| 133 | result.Job = JobAdapter.GetById(row.JobId);
|
---|
| 134 | else
|
---|
| 135 | result.Job = null;
|
---|
| 136 |
|
---|
| 137 | if (!row.IsJobResultNull())
|
---|
| 138 | result.Result = row.JobResult;
|
---|
| 139 | else
|
---|
| 140 | result.Result = null;
|
---|
| 141 |
|
---|
| 142 | if (!row.IsResourceIdNull())
|
---|
| 143 | result.Client = ClientAdapter.GetById(row.ResourceId);
|
---|
| 144 | else
|
---|
| 145 | result.Client = null;
|
---|
| 146 |
|
---|
[1092] | 147 | if (!row.IsMessageNull())
|
---|
[1103] | 148 | result.Exception = new Exception(row.Message);
|
---|
[1092] | 149 | else
|
---|
[1103] | 150 | result.Exception = null;
|
---|
[1092] | 151 |
|
---|
[1169] | 152 | result.Percentage = row.Percentage;
|
---|
| 153 |
|
---|
| 154 | if (!row.IsDateFinishedNull())
|
---|
| 155 | result.DateFinished = row.DateFinished;
|
---|
| 156 | else
|
---|
| 157 | result.DateFinished = DateTime.MinValue;
|
---|
| 158 |
|
---|
[1005] | 159 | return result;
|
---|
| 160 | } else
|
---|
| 161 | return null;
|
---|
| 162 | }
|
---|
[1000] | 163 | #endregion
|
---|
| 164 |
|
---|
| 165 | #region IJobResultsAdapter Members
|
---|
[1468] | 166 | protected override void doUpdate(JobResult result) {
|
---|
[1005] | 167 | if (result != null) {
|
---|
| 168 | ClientAdapter.Update(result.Client);
|
---|
| 169 | JobAdapter.Update(result.Job);
|
---|
[1000] | 170 |
|
---|
[1468] | 171 | base.doUpdate(result);
|
---|
[1005] | 172 | }
|
---|
[1000] | 173 | }
|
---|
| 174 |
|
---|
[1005] | 175 | public ICollection<JobResult> GetResultsOf(Job job) {
|
---|
| 176 | if (job != null) {
|
---|
| 177 | return
|
---|
| 178 | base.FindMultiple(
|
---|
| 179 | delegate() {
|
---|
[1131] | 180 | return Adapter.GetDataByJob(job.Id);
|
---|
[1005] | 181 | });
|
---|
| 182 | }
|
---|
[1000] | 183 |
|
---|
[1005] | 184 | return null;
|
---|
[1000] | 185 | }
|
---|
| 186 | #endregion
|
---|
| 187 | }
|
---|
| 188 | }
|
---|