[826] | 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.Core.InternalInterfaces.DataAccess;
|
---|
| 27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[995] | 30 | class ResourceAdapter:
|
---|
| 31 | CachedDataAdapter<
|
---|
| 32 | dsHiveServerTableAdapters.ResourceTableAdapter,
|
---|
| 33 | Resource,
|
---|
| 34 | dsHiveServer.ResourceRow,
|
---|
| 35 | dsHiveServer.ResourceDataTable>,
|
---|
| 36 | IResourceAdapter {
|
---|
| 37 | #region Fields
|
---|
| 38 | private IClientAdapter clientAdapter = null;
|
---|
[925] | 39 |
|
---|
[995] | 40 | private IClientAdapter ClientAdapter {
|
---|
| 41 | get {
|
---|
| 42 | if (clientAdapter == null)
|
---|
| 43 | clientAdapter = ServiceLocator.GetClientAdapter();
|
---|
| 44 |
|
---|
| 45 | return clientAdapter;
|
---|
| 46 | }
|
---|
[925] | 47 | }
|
---|
[995] | 48 | #endregion
|
---|
[925] | 49 |
|
---|
[995] | 50 | #region Overrides
|
---|
[1131] | 51 | protected override Resource ConvertRow(dsHiveServer.ResourceRow row,
|
---|
[899] | 52 | Resource resource) {
|
---|
| 53 | if (row != null && resource != null) {
|
---|
[995] | 54 | resource.Id = row.ResourceId;
|
---|
[899] | 55 | if (!row.IsNameNull())
|
---|
| 56 | resource.Name = row.Name;
|
---|
| 57 | else
|
---|
| 58 | resource.Name = String.Empty;
|
---|
[845] | 59 |
|
---|
| 60 | return resource;
|
---|
[925] | 61 | } else
|
---|
[845] | 62 | return null;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[1131] | 65 | protected override dsHiveServer.ResourceRow ConvertObj(Resource resource,
|
---|
[845] | 66 | dsHiveServer.ResourceRow row) {
|
---|
| 67 | if (resource != null && row != null) {
|
---|
| 68 | row.Name = resource.Name;
|
---|
| 69 |
|
---|
[899] | 70 | return row;
|
---|
| 71 | } else
|
---|
| 72 | return null;
|
---|
[845] | 73 | }
|
---|
| 74 |
|
---|
[995] | 75 | protected override void UpdateRow(dsHiveServer.ResourceRow row) {
|
---|
[1131] | 76 | Adapter.Update(row);
|
---|
[995] | 77 | }
|
---|
[826] | 78 |
|
---|
[995] | 79 | protected override dsHiveServer.ResourceRow
|
---|
| 80 | InsertNewRow(Resource resource) {
|
---|
[1166] | 81 | dsHiveServer.ResourceDataTable data =
|
---|
| 82 | new dsHiveServer.ResourceDataTable();
|
---|
| 83 |
|
---|
[995] | 84 | dsHiveServer.ResourceRow row = data.NewResourceRow();
|
---|
| 85 | data.AddResourceRow(row);
|
---|
[826] | 86 |
|
---|
[995] | 87 | return row;
|
---|
| 88 | }
|
---|
[925] | 89 |
|
---|
[995] | 90 | protected override dsHiveServer.ResourceRow
|
---|
| 91 | InsertNewRowInCache(Resource resource) {
|
---|
| 92 | dsHiveServer.ResourceRow row = cache.NewResourceRow();
|
---|
| 93 | cache.AddResourceRow(row);
|
---|
| 94 |
|
---|
| 95 | return row;
|
---|
[826] | 96 | }
|
---|
| 97 |
|
---|
[995] | 98 | protected override void FillCache() {
|
---|
[1131] | 99 | Adapter.FillByActive(cache);
|
---|
[995] | 100 | }
|
---|
| 101 |
|
---|
[1149] | 102 | protected override void SynchronizeWithDb() {
|
---|
[1131] | 103 | Adapter.Update(cache);
|
---|
[995] | 104 | }
|
---|
| 105 |
|
---|
| 106 | protected override bool PutInCache(Resource obj) {
|
---|
| 107 | return (obj is ClientInfo &&
|
---|
| 108 | (obj as ClientInfo).State != State.offline);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | protected override IEnumerable<dsHiveServer.ResourceRow>
|
---|
| 112 | FindById(long id) {
|
---|
[1131] | 113 | return Adapter.GetDataById(id);
|
---|
[995] | 114 | }
|
---|
| 115 |
|
---|
| 116 | protected override dsHiveServer.ResourceRow
|
---|
| 117 | FindCachedById(long id) {
|
---|
| 118 | return cache.FindByResourceId(id);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | protected override IEnumerable<dsHiveServer.ResourceRow>
|
---|
| 122 | FindAll() {
|
---|
| 123 | return FindMultipleRows(
|
---|
[1131] | 124 | new Selector(Adapter.GetData),
|
---|
[995] | 125 | new Selector(cache.AsEnumerable<dsHiveServer.ResourceRow>));
|
---|
| 126 | }
|
---|
[1094] | 127 |
|
---|
[995] | 128 | #endregion
|
---|
| 129 |
|
---|
| 130 | #region IResourceAdapter Members
|
---|
| 131 | public bool GetById(Resource resource) {
|
---|
[899] | 132 | if (resource != null) {
|
---|
[925] | 133 | dsHiveServer.ResourceRow row =
|
---|
[995] | 134 | GetRowById(resource.Id);
|
---|
| 135 |
|
---|
[925] | 136 | if (row != null) {
|
---|
[899] | 137 | Convert(row, resource);
|
---|
| 138 |
|
---|
| 139 | return true;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | return false;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[995] | 146 | public Resource GetByName(string name) {
|
---|
| 147 | dsHiveServer.ResourceRow row =
|
---|
| 148 | base.FindSingleRow(
|
---|
| 149 | delegate() {
|
---|
[1131] | 150 | return Adapter.GetDataByName(name);
|
---|
[995] | 151 | },
|
---|
| 152 | delegate() {
|
---|
| 153 | return from r in
|
---|
| 154 | cache.AsEnumerable<dsHiveServer.ResourceRow>()
|
---|
| 155 | where !r.IsNameNull() &&
|
---|
| 156 | r.Name == name
|
---|
| 157 | select r;
|
---|
| 158 | });
|
---|
[899] | 159 |
|
---|
[971] | 160 | if (row != null) {
|
---|
[976] | 161 | Resource res = new Resource();
|
---|
[1131] | 162 | res = Convert(row, res);
|
---|
[971] | 163 |
|
---|
[976] | 164 | return res;
|
---|
[971] | 165 | } else {
|
---|
| 166 | return null;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[826] | 170 | #endregion
|
---|
| 171 | }
|
---|
| 172 | }
|
---|