Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1597


Ignore:
Timestamp:
04/17/09 14:03:06 (16 years ago)
Author:
svonolfe
Message:

Refactored ResourceAdapter (polymorphic implementation) (#372)

Location:
trunk/sources
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAccess/3.2/HeuristicLab.DataAccess-3.2.csproj

    r1534 r1597  
    9595  </ItemGroup>
    9696  <ItemGroup>
     97    <Compile Include="Interfaces\IPolymorphicDataAdapter.cs" />
    9798    <Compile Include="Properties\AssemblyInfo.cs" />
    9899    <Compile Include="DataAccessPlugin.cs" />
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ClientGroupAdapter.cs

    r1580 r1597  
    7171      }
    7272    }
    73 
    74     private IClientAdapter clientAdapter = null;
    75 
    76     private IClientAdapter ClientAdapter {
    77       get {
    78         if (clientAdapter == null)
    79           clientAdapter =
    80             this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
    81 
    82         return clientAdapter;
    83       }
    84     }
    8573    #endregion
    8674
     
    10290       clientGroup.Resources.Clear();
    10391        foreach(Guid resource in resources) {
    104           ClientInfo client =
    105             ClientAdapter.GetById(resource);
     92          Resource res =
     93            ResAdapter.GetByIdPolymorphic(resource);
    10694
    107           if (client == null) {
    108             //client group
    109             ClientGroup group =
    110               GetById(resource);
    111 
    112             clientGroup.Resources.Add(group);
    113           } else {
    114             clientGroup.Resources.Add(client);
    115           }         
     95            clientGroup.Resources.Add(res);         
    11696        }
    11797
     
    141121          new List<Guid>();
    142122        foreach(Resource res in group.Resources) {
    143           if (res is ClientInfo) {
    144             ClientAdapter.Update(res as ClientInfo);
    145           } else if (res is ClientGroup) {
    146             Update(res as ClientGroup);
    147           } else {
    148             ResAdapter.Update(res);
    149           }
     123          ResAdapter.UpdatePolymorphic(res);
    150124
    151125          relationships.Add(res.Id);
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/ResourceAdapter.cs

    r1580 r1597  
    4949       
    5050        return clientAdapter;
     51      }
     52    }
     53
     54    private IClientGroupAdapter clientGroupAdapter = null;
     55
     56    private IClientGroupAdapter ClientGroupAdapter {
     57      get {
     58        if (clientGroupAdapter == null)
     59          clientGroupAdapter =
     60            this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
     61
     62        return clientGroupAdapter;
    5163      }
    5264    }
     
    108120
    109121    #endregion
     122
     123    #region IPolymorphicDataAdapter<Resource> Members
     124
     125    public void UpdatePolymorphic(Resource res) {
     126      if (res is ClientInfo) {
     127        ClientAdapter.Update(res as ClientInfo);
     128      } else if (res is ClientGroup) {
     129        ClientGroupAdapter.Update(res as ClientGroup);
     130      } else {
     131        this.Update(res);
     132      }
     133    }
     134
     135    public Resource GetByIdPolymorphic(Guid id) {
     136      ClientGroup group =
     137        ClientGroupAdapter.GetById(id);
     138
     139      if (group != null)
     140        return group;
     141      else {
     142        ClientInfo client =
     143          ClientAdapter.GetById(id);
     144
     145        if (client != null)
     146          return client;
     147        else {
     148          return this.GetById(id);
     149        }
     150      }
     151    }
     152
     153    public bool DeletePolymorphic(Resource res) {
     154      if (res is ClientInfo) {
     155        return ClientAdapter.Delete(res as ClientInfo);
     156      } else if (res is ClientGroup) {
     157        return ClientGroupAdapter.Delete(res as ClientGroup);
     158      } else {
     159        return this.Delete(res);
     160      }
     161    }
     162
     163    #endregion
    110164  }
    111165}
  • trunk/sources/HeuristicLab.Hive.Server.DataAccess/3.2/IResourceAdapter.cs

    r1530 r1597  
    3030  /// The resource database adapter
    3131  /// </summary>
    32   public interface IResourceAdapter: IDataAdapter<Resource> {
     32  public interface IResourceAdapter: IPolymorphicDataAdapter<Resource> {
    3333    /// <summary>
    3434    /// Gets the resource and updates the values of the object
Note: See TracChangeset for help on using the changeset viewer.