Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 17:46:11 (16 years ago)
Author:
svonolfe
Message:

Added PluginInfoAdapter (#372)

File:
1 edited

Legend:

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

    r1530 r1580  
    3131using System.Data.Common;
    3232using System.Data.SqlClient;
     33using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
    3334
    3435namespace HeuristicLab.Hive.Server.ADODataAccess {
    35   class JobAdapterWrapper :
    36     DataAdapterWrapperBase<dsHiveServerTableAdapters.JobTableAdapter,
    37                       Job,
    38                       dsHiveServer.JobRow> {   
    39     public override void UpdateRow(dsHiveServer.JobRow row) {
    40       TransactionalAdapter.Update(row);
    41     }
    42 
    43     public override dsHiveServer.JobRow
    44       InsertNewRow(Job job) {
    45       dsHiveServer.JobDataTable data =
    46         new dsHiveServer.JobDataTable();
    47 
    48       dsHiveServer.JobRow row = data.NewJobRow();
    49       row.JobId = job.Id;
    50       data.AddJobRow(row);
    51 
    52       return row;
    53     }
    54 
    55     public override IEnumerable<dsHiveServer.JobRow>
    56       FindById(Guid id) {
    57       return TransactionalAdapter.GetDataById(id);
    58     }
    59 
    60     public override IEnumerable<dsHiveServer.JobRow>
    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  
    7436  class JobAdapter :
    7537    DataAdapterBase<dsHiveServerTableAdapters.JobTableAdapter,
     
    7840    IJobAdapter {
    7941    #region Fields
     42    private ManyToManyRelationHelper<
     43      dsHiveServerTableAdapters.RequiredPluginsTableAdapter,
     44      dsHiveServer.RequiredPluginsRow> manyToManyRelationHelper = null;
     45
     46    private ManyToManyRelationHelper<
     47      dsHiveServerTableAdapters.RequiredPluginsTableAdapter,
     48      dsHiveServer.RequiredPluginsRow> ManyToManyRelationHelper {
     49      get {
     50        if (manyToManyRelationHelper == null) {
     51          manyToManyRelationHelper =
     52            new ManyToManyRelationHelper<dsHiveServerTableAdapters.RequiredPluginsTableAdapter,
     53              dsHiveServer.RequiredPluginsRow>(new RequiredPluginsAdapterWrapper());
     54        }
     55
     56        manyToManyRelationHelper.Session = Session as Session;
     57
     58        return manyToManyRelationHelper;
     59      }
     60    }
     61
    8062    private IClientAdapter clientAdapter = null;
    8163
     
    10284      }
    10385    }
     86
     87    private IPluginInfoAdapter pluginInfoAdapter = null;
     88
     89    private IPluginInfoAdapter PluginInfoAdapter {
     90      get {
     91        if (pluginInfoAdapter == null) {
     92          pluginInfoAdapter =
     93            this.Session.GetDataAdapter<HivePluginInfo, IPluginInfoAdapter>();
     94        }
     95
     96        return pluginInfoAdapter;
     97      }
     98    }
    10499    #endregion
    105100
     
    167162        else
    168163          job.MemoryNeeded = default(int);
     164
     165        ICollection<Guid> requiredPlugins =
     166          ManyToManyRelationHelper.GetRelationships(job.Id);
     167       
     168        job.PluginsNeeded.Clear();
     169        foreach (Guid requiredPlugin in requiredPlugins) {
     170          HivePluginInfo pluginInfo =
     171            PluginInfoAdapter.GetById(requiredPlugin);
     172
     173          job.PluginsNeeded.Add(pluginInfo);
     174        }
    169175
    170176        return job;
     
    296302    }
    297303
     304    protected override void doUpdate(Job obj) {
     305      base.doUpdate(obj);
     306
     307      //update relationships
     308      List<Guid> relationships =
     309        new List<Guid>();
     310      foreach (HivePluginInfo pluginInfo in obj.PluginsNeeded) {
     311        PluginInfoAdapter.Update(pluginInfo);
     312        relationships.Add(pluginInfo.Id);
     313      }
     314
     315      ManyToManyRelationHelper.UpdateRelationships(
     316        obj.Id, relationships);
     317    }
     318
    298319    protected override bool doDelete(Job job) {
    299320      if (job != null) {
     
    310331          }
    311332
     333          //delete all relationships
     334          ManyToManyRelationHelper.UpdateRelationships(job.Id,
     335            new List<Guid>());
     336
    312337          return base.doDelete(job);
    313338        }
Note: See TracChangeset for help on using the changeset viewer.