- Timestamp:
- 03/31/09 01:33:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs
r1449 r1468 29 29 using HeuristicLab.DataAccess.Interfaces; 30 30 using HeuristicLab.DataAccess.ADOHelper; 31 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 32 using System.Data.Common; 33 using System.Data.SqlClient; 31 34 32 35 namespace HeuristicLab.Hive.Server.ADODataAccess { 36 class ClientAdapterWrapper : 37 DataAdapterWrapperBase< 38 dsHiveServerTableAdapters.ClientTableAdapter, 39 ClientInfo, 40 dsHiveServer.ClientRow> { 41 public override void UpdateRow(dsHiveServer.ClientRow row) { 42 TransactionalAdapter.Update(row); 43 } 44 45 public override dsHiveServer.ClientRow 46 InsertNewRow(ClientInfo client) { 47 dsHiveServer.ClientDataTable data = 48 new dsHiveServer.ClientDataTable(); 49 50 dsHiveServer.ClientRow row = data.NewClientRow(); 51 row.ResourceId = client.Id; 52 data.AddClientRow(row); 53 54 return row; 55 } 56 57 public override IEnumerable<dsHiveServer.ClientRow> 58 FindById(Guid id) { 59 return TransactionalAdapter.GetDataById(id); 60 } 61 62 public override IEnumerable<dsHiveServer.ClientRow> 63 FindAll() { 64 return TransactionalAdapter.GetData(); 65 } 66 67 protected override void SetConnection(DbConnection connection) { 68 adapter.Connection = connection as SqlConnection; 69 } 70 71 protected override void SetTransaction(DbTransaction transaction) { 72 adapter.Transaction = transaction as SqlTransaction; 73 } 74 } 75 33 76 class ClientAdapter: 34 CachedDataAdapter<77 DataAdapterBase< 35 78 dsHiveServerTableAdapters.ClientTableAdapter, 36 79 ClientInfo, 37 dsHiveServer.ClientRow, 38 dsHiveServer.ClientDataTable>, 80 dsHiveServer.ClientRow>, 39 81 IClientAdapter { 40 82 #region Fields … … 44 86 get { 45 87 if (resAdapter == null) 46 resAdapter = ServiceLocator.GetResourceAdapter(); 88 resAdapter = 89 this.Session.GetDataAdapter<Resource, IResourceAdapter>(); 47 90 48 91 return resAdapter; … … 55 98 get { 56 99 if (clientGroupAdapter == null) { 57 clientGroupAdapter = ServiceLocator.GetClientGroupAdapter(); 100 clientGroupAdapter = 101 this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 58 102 } 59 103 … … 67 111 get { 68 112 if (jobAdapter == null) { 69 jobAdapter = ServiceLocator.GetJobAdapter();113 this.Session.GetDataAdapter<Job, IJobAdapter>(); 70 114 } 71 115 … … 75 119 #endregion 76 120 77 public ClientAdapter(): 78 base(ServiceLocator.GetDBSynchronizer()) { 79 parentAdapters.Add(this.ResAdapter as ICachedDataAdapter); 80 } 81 121 public ClientAdapter(): 122 base(new ClientAdapterWrapper()) { 123 } 82 124 83 125 #region Overrides … … 146 188 } 147 189 148 protected override void UpdateRow(dsHiveServer.ClientRow row) {149 Adapter.Update(row);150 }151 152 protected override dsHiveServer.ClientRow153 InsertNewRow(ClientInfo client) {154 dsHiveServer.ClientDataTable data =155 new dsHiveServer.ClientDataTable();156 157 dsHiveServer.ClientRow row = data.NewClientRow();158 row.ResourceId = client.Id;159 data.AddClientRow(row);160 161 return row;162 }163 164 protected override dsHiveServer.ClientRow165 InsertNewRowInCache(ClientInfo client) {166 dsHiveServer.ClientRow row = cache.NewClientRow();167 row.ResourceId = client.Id;168 cache.AddClientRow(row);169 170 return row;171 }172 173 protected override void FillCache() {174 Adapter.FillByActive(cache);175 }176 177 protected override void SynchronizeWithDb() {178 Adapter.Update(cache);179 }180 181 protected override bool PutInCache(ClientInfo obj) {182 return (obj.State != State.offline && obj.State != State.nullState);183 }184 185 protected override IEnumerable<dsHiveServer.ClientRow>186 FindById(Guid id) {187 return Adapter.GetDataById(id);188 }189 190 protected override dsHiveServer.ClientRow191 FindCachedById(Guid id) {192 return cache.FindByResourceId(id);193 }194 195 protected override IEnumerable<dsHiveServer.ClientRow>196 FindAll() {197 return FindMultipleRows(198 new Selector(Adapter.GetData),199 new Selector(cache.AsEnumerable<dsHiveServer.ClientRow>));200 }201 202 190 #endregion 203 191 204 192 #region IClientAdapter Members 205 p ublic override voidUpdate(ClientInfo client) {193 protected override void doUpdate(ClientInfo client) { 206 194 if (client != null) { 207 195 ResAdapter.Update(client); 208 196 209 base. Update(client);197 base.doUpdate(client); 210 198 } 211 199 } … … 219 207 } 220 208 221 p ublic override boolDelete(ClientInfo client) {209 protected override bool doDelete(ClientInfo client) { 222 210 bool success = false; 223 211 Guid locked = Guid.Empty; … … 240 228 } 241 229 242 success = base. Delete(client) &&230 success = base.doDelete(client) && 243 231 ResAdapter.Delete(client); 244 232 }
Note: See TracChangeset
for help on using the changeset viewer.