Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/09 01:33:37 (15 years ago)
Author:
svonolfe
Message:

Added transaction management (#527)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs

    r1449 r1468  
    2929using HeuristicLab.DataAccess.Interfaces;
    3030using HeuristicLab.DataAccess.ADOHelper;
     31using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
     32using System.Data.Common;
     33using System.Data.SqlClient;
    3134
    3235namespace 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
    3376  class ClientAdapter:
    34     CachedDataAdapter<
     77    DataAdapterBase<
    3578      dsHiveServerTableAdapters.ClientTableAdapter,
    3679      ClientInfo,
    37       dsHiveServer.ClientRow,
    38       dsHiveServer.ClientDataTable>,
     80      dsHiveServer.ClientRow>,
    3981    IClientAdapter {
    4082    #region Fields
     
    4486      get {
    4587        if (resAdapter == null)
    46           resAdapter = ServiceLocator.GetResourceAdapter();
     88          resAdapter =
     89            this.Session.GetDataAdapter<Resource, IResourceAdapter>();
    4790
    4891        return resAdapter;
     
    5598      get {
    5699        if (clientGroupAdapter == null) {
    57           clientGroupAdapter = ServiceLocator.GetClientGroupAdapter();
     100          clientGroupAdapter =
     101            this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
    58102        }
    59103
     
    67111      get {
    68112        if (jobAdapter == null) {
    69           jobAdapter = ServiceLocator.GetJobAdapter();
     113          this.Session.GetDataAdapter<Job, IJobAdapter>();
    70114        }
    71115
     
    75119    #endregion
    76120
    77     public ClientAdapter():
    78       base(ServiceLocator.GetDBSynchronizer()) {
    79       parentAdapters.Add(this.ResAdapter as ICachedDataAdapter);
    80     }
    81 
     121    public ClientAdapter():
     122      base(new ClientAdapterWrapper()) {
     123    }
    82124
    83125    #region Overrides
     
    146188    }
    147189
    148     protected override void UpdateRow(dsHiveServer.ClientRow row) {
    149       Adapter.Update(row);
    150     }
    151 
    152     protected override dsHiveServer.ClientRow
    153       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.ClientRow
    165       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.ClientRow
    191       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 
    202190    #endregion
    203191
    204192    #region IClientAdapter Members
    205     public override void Update(ClientInfo client) {
     193    protected override void doUpdate(ClientInfo client) {
    206194      if (client != null) {
    207195        ResAdapter.Update(client);
    208196
    209         base.Update(client);
     197        base.doUpdate(client);
    210198      }
    211199    }
     
    219207    }
    220208
    221     public override bool Delete(ClientInfo client) {
     209    protected override bool doDelete(ClientInfo client) {
    222210      bool success = false;
    223211      Guid locked = Guid.Empty;
     
    240228          }
    241229
    242           success = base.Delete(client) &&
     230          success = base.doDelete(client) &&
    243231            ResAdapter.Delete(client);
    244232        }
Note: See TracChangeset for help on using the changeset viewer.