Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/10 10:57:21 (15 years ago)
Author:
kgrading
Message:

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

Location:
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2
Files:
4 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/BaseDao.cs

    r2904 r3011  
    55
    66namespace HeuristicLab.Hive.Server.LINQDataAccess {
    7   public class BaseDao {
     7  public abstract class BaseDao<TBusiness, TDatabaseEntity> {
    88    public static HiveDataContext Context {
    99      get {
     
    1111      }
    1212    }
     13
     14    public abstract TDatabaseEntity DtoToEntity(TBusiness source, TDatabaseEntity target);
     15    public abstract TBusiness EntityToDto(TDatabaseEntity source, TBusiness target);
     16
    1317  }
    1418}
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/ClientDao.cs

    r2904 r3011  
    44using System.Text;
    55using HeuristicLab.Hive.Contracts.BusinessObjects;
     6using HeuristicLab.Hive.Server.DataAccess;
     7using System.Threading;
    68
    79namespace HeuristicLab.Hive.Server.LINQDataAccess {
    8   public class ClientDao: BaseDao, IClientDao {
     10  public class ClientDao: BaseDao<ClientDto, Client>, IClientDao {
    911
    1012    public ClientDao() {     
    1113    }
    1214
    13     public ClientInfo FindById(Guid id) {
     15    public ClientDto FindById(Guid id) {
    1416      return (from client in Context.Clients
    1517              where client.ResourceId.Equals(id)
    16               select
    17                 new ClientInfo {
    18                   CpuSpeedPerCore = client.CPUSpeed,
    19                   FreeMemory = client.FreeMemory,
    20                   Id = client.ResourceId,
    21                   Login = client.Login,
    22                   Memory = client.Memory,
    23                   Name = client.Resource.Name,
    24                   NrOfCores = client.NumberOfCores,
    25                   NrOfFreeCores = client.NumberOfFreeCores,
    26                   State = (State)Enum.Parse(typeof(State), client.Status)
    27                 }
     18              select EntityToDto(client, null)
    2819            ).SingleOrDefault();     
    2920    }
    3021
    31     public IEnumerable<ClientInfo> FindAll() {
     22    public IEnumerable<ClientDto> FindAll() {
    3223      return (from client in Context.Clients
    3324              select
    34                 new ClientInfo {
    35                                  CpuSpeedPerCore = client.CPUSpeed,
    36                                  FreeMemory = client.FreeMemory,
    37                                  Id = client.ResourceId,
    38                                  Login = client.Login,
    39                                  Memory = client.Memory,
    40                                  Name = client.Resource.Name,
    41                                  NrOfCores = client.NumberOfCores,
    42                                  NrOfFreeCores = client.NumberOfFreeCores,
    43                                  State = (State) Enum.Parse(typeof (State), client.Status)
    44                                }
     25                EntityToDto(client, null)
    4526             ).ToList();
    4627    }
    4728
     29    public IEnumerable<ClientDto> FindAllClientsWithoutGroup() {
     30      return (from client in Context.Clients
     31              where client.Resource.ClientGroup_Resources.Count == 0
     32              select EntityToDto(client, null)).ToList();
     33    }
     34
     35    public ClientDto GetClientForJob(Guid jobId) {
     36      return (from job in Context.Jobs
     37              where job.JobId.Equals(jobId)
     38              select EntityToDto(job.Client, null)).SingleOrDefault();
     39    }
    4840 
    49     public ClientInfo Insert(ClientInfo info) {
    50       Client c = new Client {
    51                               CPUSpeed = info.CpuSpeedPerCore,
    52                               FreeMemory = info.FreeMemory,
    53                               Resource = new Resource {Name = info.Name, ResourceId = info.Id},
    54                               Login = info.Login,
    55                               Memory = info.Memory,
    56                               NumberOfCores = info.NrOfCores,
    57                               NumberOfFreeCores = info.NrOfFreeCores,
    58                               Status = Enum.GetName(typeof (State), info.State)
    59                             };
    60 
     41    public ClientDto Insert(ClientDto info) {
     42      Client c = DtoToEntity(info, null);     
    6143      Context.Clients.InsertOnSubmit(c);
    6244      Context.SubmitChanges();
     
    6547    }
    6648
    67     public void Delete(ClientInfo info) {
    68       Client client = Context.Clients.SingleOrDefault(c => c.ResourceId.Equals(info.Id));
    69       Context.Clients.DeleteOnSubmit(client);
    70     }
    71 
    72     public void Update(ClientInfo info) {
    73       Client client = Context.Clients.SingleOrDefault(c => c.ResourceId.Equals(info.Id));
    74       client.CPUSpeed = info.CpuSpeedPerCore;
    75       client.FreeMemory = info.FreeMemory;
    76       client.Resource.Name = info.Name;
    77       client.Login = info.Login;
    78       client.Memory = info.Memory;
    79       client.NumberOfCores = info.NrOfCores;
    80       client.NumberOfFreeCores = info.NrOfFreeCores;
    81       client.Status = Enum.GetName(typeof (State), info.State);
     49    //Cascading delete takes care of the rest
     50    public void Delete(ClientDto info) {
     51      Resource res = Context.Resources.SingleOrDefault(c => c.ResourceId.Equals(info.Id));           
     52      Context.Resources.DeleteOnSubmit(res);
    8253      Context.SubmitChanges();
    8354    }
    8455
     56    public void Update(ClientDto info) {
     57      Client client = Context.Clients.SingleOrDefault(c => c.ResourceId.Equals(info.Id));
     58      DtoToEntity(info, client);
     59      try {
     60        Console.WriteLine("Sending from thread: " + Thread.CurrentThread.ManagedThreadId);
     61        Context.SubmitChanges();
     62      } catch (System.Data.Linq.ChangeConflictException cce) {
     63        Console.WriteLine(cce);       
     64      }
     65    }
    8566
     67    public override Client DtoToEntity(ClientDto source, Client target) {
     68      if (source == null)
     69        return null;
     70      if (target == null)
     71        target = new Client();
     72     
     73      target.CPUSpeed = source.CpuSpeedPerCore;
     74     
     75      if(target.Resource == null)
     76        target.Resource = new Resource();
    8677
    87     #region IGenericDao<ClientInfo,Client> Members
     78      target.FreeMemory = source.FreeMemory;
     79      target.Resource.Name = source.Name;
     80      target.Resource.ResourceId = source.Id;
    8881
     82      target.Login = source.Login;
     83      target.Memory = source.Memory;
     84      target.NumberOfCores = source.NrOfCores;
     85      target.NumberOfFreeCores = source.NrOfFreeCores;
     86      target.Status = Enum.GetName(typeof(State), source.State);
     87      return target;
     88    }
    8989
    90 
    91     #endregion
     90    public override ClientDto EntityToDto(Client source, ClientDto target) {
     91      if (source == null)
     92        return null;
     93      if(target == null)
     94        target = new ClientDto();
     95      target.CpuSpeedPerCore = source.CPUSpeed;
     96      target.FreeMemory = source.FreeMemory;
     97      target.Id = source.ResourceId;
     98      target.Login = source.Login;
     99      target.Memory = source.Memory;
     100      target.Name = source.Resource.Name;
     101      target.NrOfCores = source.NumberOfCores;
     102      target.NrOfFreeCores = source.NumberOfFreeCores;
     103      target.State = (State) Enum.Parse(typeof (State), source.Status);
     104      return target;
     105    }
    92106  }
    93107}
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/ContextFactory.cs

    r2904 r3011  
    1515        return _hiveDataContext;       
    1616      }
     17      set {
     18        _hiveDataContext = value;
     19      }
    1720    }
    1821  }
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/HeuristicLab.Hive.Server.LINQDataAccess-3.2.csproj

    r2904 r3011  
    8787  <ItemGroup>
    8888    <Compile Include="BaseDao.cs" />
     89    <Compile Include="ClientConfigDao.cs" />
    8990    <Compile Include="ClientDao.cs" />
     91    <Compile Include="ClientGroupDao.cs" />
    9092    <Compile Include="ContextFactory.cs" />
    9193    <Compile Include="Hive.designer.cs">
     
    9496      <DependentUpon>Hive.dbml</DependentUpon>
    9597    </Compile>
    96     <Compile Include="IClientDao.cs" />
    97     <Compile Include="IGenericDao.cs" />
    98     <Compile Include="IJobDao.cs" />
     98    <Compile Include="JobDao.cs" />
    9999    <Compile Include="LINQDataAccessPlugin.cs" />
     100    <Compile Include="PluginInfoDao.cs" />
    100101    <Compile Include="Properties\AssemblyInfo.cs" />
    101102    <Compile Include="Properties\Settings.Designer.cs">
     
    122123      <Project>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</Project>
    123124      <Name>HeuristicLab.Hive.Contracts-3.2</Name>
     125    </ProjectReference>
     126    <ProjectReference Include="..\..\HeuristicLab.Hive.Server.DataAccess\3.2\HeuristicLab.Hive.Server.DataAccess-3.2.csproj">
     127      <Project>{4D5A2A16-66C2-431D-9AA3-BD3041E64B84}</Project>
     128      <Name>HeuristicLab.Hive.Server.DataAccess-3.2</Name>
    124129    </ProjectReference>
    125130    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/Hive.dbml

    r2904 r3011  
    5151      <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    5252      <Column Name="Percentage" Type="System.Double" DbType="Float" CanBeNull="true" />
    53       <Column Name="SerializedJob" Type="System.Data.Linq.Binary" DbType="VarBinary(MAX)" CanBeNull="true" UpdateCheck="Never" />
     53      <Column Name="SerializedJob" Type="System.Data.Linq.Binary" DbType="VarBinary(MAX)" CanBeNull="true" UpdateCheck="Never" IsDelayLoaded="true" />
    5454      <Column Name="DateCreated" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    5555      <Column Name="DateCalculated" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
     
    5858      <Column Name="ProjectId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    5959      <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    60       <Column Name="CoresNeeded" Type="System.Int32" DbType="Int" CanBeNull="true" />
    61       <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int" CanBeNull="true" />
     60      <Column Name="CoresNeeded" Type="System.Int32" DbType="Int" CanBeNull="false" />
     61      <Column Name="MemoryNeeded" Type="System.Int32" DbType="Int" CanBeNull="false" />
    6262      <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" />
    6363      <Association Name="Job_Job" Member="Jobs" ThisKey="JobId" OtherKey="ParentJobId" Type="Job" />
     
    8888      <Column Name="JobId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
    8989      <Column Name="PluginId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" />
    90       <Column Name="RequiredPluginId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
     90      <Column Name="RequiredPluginId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" UpdateCheck="Never" />
    9191      <Association Name="Job_RequiredPlugin" Member="Job" ThisKey="JobId" OtherKey="JobId" Type="Job" IsForeignKey="true" />
    9292      <Association Name="PluginInfo_RequiredPlugin" Member="PluginInfo" ThisKey="PluginId" OtherKey="PluginId" Type="PluginInfo" IsForeignKey="true" DeleteRule="CASCADE" DeleteOnNull="true" />
     
    9595  <Table Name="dbo.Resource" Member="Resources">
    9696    <Type Name="Resource">
    97       <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
     97      <Column Name="ResourceId" AutoSync="OnInsert" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    9898      <Column Name="Name" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
    9999      <Association Name="Resource_AssignedResource" Member="AssignedResources" ThisKey="ResourceId" OtherKey="ResourceId" Type="AssignedResource" />
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/Hive.dbml.layout

    r2904 r3011  
    132132      </nestedChildShapes>
    133133    </classShape>
    134     <associationConnector edgePoints="[(3.625 : 9.70755126953125); (2.75 : 9.70755126953125)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     134    <associationConnector edgePoints="[(3.625 : 9.70755126953125); (2.75 : 9.70755126953125)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    135135      <AssociationMoniker Name="/HiveDataContext/Client/Client_UptimeStatistic" />
    136136      <nodes>
     
    139139      </nodes>
    140140    </associationConnector>
    141     <associationConnector edgePoints="[(5.625 : 8.78770182291667); (9 : 8.78770182291667)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     141    <associationConnector edgePoints="[(5.625 : 8.78770182291667); (9 : 8.78770182291667)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    142142      <AssociationMoniker Name="/HiveDataContext/Client/Client_Job" />
    143143      <nodes>
     
    146146      </nodes>
    147147    </associationConnector>
    148     <associationConnector edgePoints="[(4.5 : 6.94399251302083); (4.5 : 7.625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     148    <associationConnector edgePoints="[(4.5 : 6.94399251302083); (4.5 : 7.625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    149149      <AssociationMoniker Name="/HiveDataContext/Resource/Resource_Client" />
    150150      <nodes>
     
    153153      </nodes>
    154154    </associationConnector>
    155     <associationConnector edgePoints="[(4.625 : 11); (4.625 : 10.1651025390625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     155    <associationConnector edgePoints="[(4.625 : 11); (4.625 : 10.1651025390625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    156156      <AssociationMoniker Name="/HiveDataContext/ClientConfig/ClientConfig_Client" />
    157157      <nodes>
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/Hive.designer.cs

    r2904 r3011  
    604604    }
    605605   
    606     [Column(Storage="_UpDownTimeCalendar", DbType="Xml", UpdateCheck=UpdateCheck.Never)]
     606    [Column(Storage="_UpDownTimeCalendar", DbType="Xml", CanBeNull=true, UpdateCheck=UpdateCheck.Never)]
    607607    public System.Xml.Linq.XElement UpDownTimeCalendar
    608608    {
     
    10291029    private System.Nullable<double> _Percentage;
    10301030   
    1031     private System.Data.Linq.Binary _SerializedJob;
     1031    private System.Data.Linq.Link<System.Data.Linq.Binary> _SerializedJob;
    10321032   
    10331033    private System.Nullable<System.DateTime> _DateCreated;
     
    10431043    private System.Nullable<System.Guid> _UserId;
    10441044   
    1045     private System.Nullable<int> _CoresNeeded;
    1046    
    1047     private System.Nullable<int> _MemoryNeeded;
     1045    private int _CoresNeeded;
     1046   
     1047    private int _MemoryNeeded;
    10481048   
    10491049    private EntitySet<AssignedResource> _AssignedResources;
     
    10871087    partial void OnUserIdChanging(System.Nullable<System.Guid> value);
    10881088    partial void OnUserIdChanged();
    1089     partial void OnCoresNeededChanging(System.Nullable<int> value);
     1089    partial void OnCoresNeededChanging(int value);
    10901090    partial void OnCoresNeededChanged();
    1091     partial void OnMemoryNeededChanging(System.Nullable<int> value);
     1091    partial void OnMemoryNeededChanging(int value);
    10921092    partial void OnMemoryNeededChanged();
    10931093    #endregion
     
    12121212    }
    12131213   
    1214     [Column(Storage="_SerializedJob", DbType="VarBinary(MAX)", UpdateCheck=UpdateCheck.Never)]
     1214    [Column(Storage="_SerializedJob", DbType="VarBinary(MAX)", CanBeNull=true, UpdateCheck=UpdateCheck.Never)]
    12151215    public System.Data.Linq.Binary SerializedJob
    12161216    {
    12171217      get
    12181218      {
    1219         return this._SerializedJob;
    1220       }
    1221       set
    1222       {
    1223         if ((this._SerializedJob != value))
     1219        return this._SerializedJob.Value;
     1220      }
     1221      set
     1222      {
     1223        if ((this._SerializedJob.Value != value))
    12241224        {
    12251225          this.OnSerializedJobChanging(value);
    12261226          this.SendPropertyChanging();
    1227           this._SerializedJob = value;
     1227          this._SerializedJob.Value = value;
    12281228          this.SendPropertyChanged("SerializedJob");
    12291229          this.OnSerializedJobChanged();
     
    13571357   
    13581358    [Column(Storage="_CoresNeeded", DbType="Int")]
    1359     public System.Nullable<int> CoresNeeded
     1359    public int CoresNeeded
    13601360    {
    13611361      get
     
    13771377   
    13781378    [Column(Storage="_MemoryNeeded", DbType="Int")]
    1379     public System.Nullable<int> MemoryNeeded
     1379    public int MemoryNeeded
    13801380    {
    13811381      get
     
    19531953    }
    19541954   
    1955     [Column(Storage="_RequiredPluginId", AutoSync=AutoSync.OnInsert, DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true)]
     1955    [Column(Storage="_RequiredPluginId", AutoSync=AutoSync.OnInsert, DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
    19561956    public System.Guid RequiredPluginId
    19571957    {
     
    20992099    }
    21002100   
    2101     [Column(Storage="_ResourceId", AutoSync=AutoSync.OnInsert, DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true, IsDbGenerated=true)]
     2101    [Column(Storage="_ResourceId", AutoSync=AutoSync.OnInsert, DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)]
    21022102    public System.Guid ResourceId
    21032103    {
  • trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/LINQDataAccessPlugin.cs

    r2850 r3011  
    99  [PluginFile("HeuristicLab.Hive.Server.LINQDataAccess-3.2.dll", PluginFileType.Assembly)]
    1010  [PluginDependency("HeuristicLab.Core-3.2")]
     11  [PluginDependency("HeuristicLab.Hive.Contracts-3.2")]
     12  [PluginDependency("HeuristicLab.Hive.Server.DataAccess-3.2")]
    1113  public class LINQDataAccessPlugin: PluginBase {
    1214  }
Note: See TracChangeset for help on using the changeset viewer.