1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
28 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
29 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
30 | using System.Data.Common;
|
---|
31 | using System.Data.SqlClient;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
34 | class ResourceAdapterWrapper :
|
---|
35 | DataAdapterWrapperBase<
|
---|
36 | dsHiveServerTableAdapters.ResourceTableAdapter,
|
---|
37 | Resource,
|
---|
38 | dsHiveServer.ResourceRow> {
|
---|
39 | public override void UpdateRow(dsHiveServer.ResourceRow row) {
|
---|
40 | TransactionalAdapter.Update(row);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override dsHiveServer.ResourceRow
|
---|
44 | InsertNewRow(Resource resource) {
|
---|
45 | dsHiveServer.ResourceDataTable data =
|
---|
46 | new dsHiveServer.ResourceDataTable();
|
---|
47 |
|
---|
48 | dsHiveServer.ResourceRow row = data.NewResourceRow();
|
---|
49 | row.ResourceId = resource.Id;
|
---|
50 | data.AddResourceRow(row);
|
---|
51 |
|
---|
52 | return row;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public override IEnumerable<dsHiveServer.ResourceRow>
|
---|
56 | FindById(Guid id) {
|
---|
57 | return TransactionalAdapter.GetDataById(id);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public override IEnumerable<dsHiveServer.ResourceRow>
|
---|
61 | FindAll() {
|
---|
62 | return TransactionalAdapter.GetData();
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void SetConnection(DbConnection connection) {
|
---|
66 | adapter.Connection = connection as SqlConnection;
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected override void SetTransaction(DbTransaction transaction) {
|
---|
70 | adapter.Transaction = transaction as SqlTransaction;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | class ResourceAdapter:
|
---|
75 | DataAdapterBase<
|
---|
76 | dsHiveServerTableAdapters.ResourceTableAdapter,
|
---|
77 | Resource,
|
---|
78 | dsHiveServer.ResourceRow>,
|
---|
79 | IResourceAdapter {
|
---|
80 | #region Fields
|
---|
81 | private IClientAdapter clientAdapter = null;
|
---|
82 |
|
---|
83 | private IClientAdapter ClientAdapter {
|
---|
84 | get {
|
---|
85 | if (clientAdapter == null)
|
---|
86 | clientAdapter =
|
---|
87 | this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
88 |
|
---|
89 | return clientAdapter;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | public ResourceAdapter(): base(new ResourceAdapterWrapper()) {
|
---|
95 | }
|
---|
96 |
|
---|
97 | #region Overrides
|
---|
98 | protected override Resource ConvertRow(dsHiveServer.ResourceRow row,
|
---|
99 | Resource resource) {
|
---|
100 | if (row != null && resource != null) {
|
---|
101 | resource.Id = row.ResourceId;
|
---|
102 | if (!row.IsNameNull())
|
---|
103 | resource.Name = row.Name;
|
---|
104 | else
|
---|
105 | resource.Name = String.Empty;
|
---|
106 |
|
---|
107 | return resource;
|
---|
108 | } else
|
---|
109 | return null;
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected override dsHiveServer.ResourceRow ConvertObj(Resource resource,
|
---|
113 | dsHiveServer.ResourceRow row) {
|
---|
114 | if (resource != null && row != null) {
|
---|
115 | row.ResourceId = resource.Id;
|
---|
116 | row.Name = resource.Name;
|
---|
117 |
|
---|
118 | return row;
|
---|
119 | } else
|
---|
120 | return null;
|
---|
121 | }
|
---|
122 | #endregion
|
---|
123 |
|
---|
124 | #region IResourceAdapter Members
|
---|
125 | public bool GetById(Resource resource) {
|
---|
126 | if (resource != null) {
|
---|
127 | dsHiveServer.ResourceRow row =
|
---|
128 | GetRowById(resource.Id);
|
---|
129 |
|
---|
130 | if (row != null) {
|
---|
131 | Convert(row, resource);
|
---|
132 |
|
---|
133 | return true;
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | return false;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public Resource GetByName(string name) {
|
---|
141 | dsHiveServer.ResourceRow row =
|
---|
142 | base.FindSingleRow(
|
---|
143 | delegate() {
|
---|
144 | return Adapter.GetDataByName(name);
|
---|
145 | });
|
---|
146 |
|
---|
147 | if (row != null) {
|
---|
148 | Resource res = new Resource();
|
---|
149 | res = Convert(row, res);
|
---|
150 |
|
---|
151 | return res;
|
---|
152 | } else {
|
---|
153 | return null;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | #endregion
|
---|
158 | }
|
---|
159 | }
|
---|