Changeset 3011 for trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess
- Timestamp:
- 03/12/10 10:57:21 (15 years ago)
- 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 5 5 6 6 namespace HeuristicLab.Hive.Server.LINQDataAccess { 7 public class BaseDao{7 public abstract class BaseDao<TBusiness, TDatabaseEntity> { 8 8 public static HiveDataContext Context { 9 9 get { … … 11 11 } 12 12 } 13 14 public abstract TDatabaseEntity DtoToEntity(TBusiness source, TDatabaseEntity target); 15 public abstract TBusiness EntityToDto(TDatabaseEntity source, TBusiness target); 16 13 17 } 14 18 } -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/ClientDao.cs
r2904 r3011 4 4 using System.Text; 5 5 using HeuristicLab.Hive.Contracts.BusinessObjects; 6 using HeuristicLab.Hive.Server.DataAccess; 7 using System.Threading; 6 8 7 9 namespace HeuristicLab.Hive.Server.LINQDataAccess { 8 public class ClientDao: BaseDao , IClientDao {10 public class ClientDao: BaseDao<ClientDto, Client>, IClientDao { 9 11 10 12 public ClientDao() { 11 13 } 12 14 13 public Client Info FindById(Guid id) {15 public ClientDto FindById(Guid id) { 14 16 return (from client in Context.Clients 15 17 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) 28 19 ).SingleOrDefault(); 29 20 } 30 21 31 public IEnumerable<Client Info> FindAll() {22 public IEnumerable<ClientDto> FindAll() { 32 23 return (from client in Context.Clients 33 24 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) 45 26 ).ToList(); 46 27 } 47 28 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 } 48 40 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); 61 43 Context.Clients.InsertOnSubmit(c); 62 44 Context.SubmitChanges(); … … 65 47 } 66 48 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); 82 53 Context.SubmitChanges(); 83 54 } 84 55 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 } 85 66 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(); 86 77 87 #region IGenericDao<ClientInfo,Client> Members 78 target.FreeMemory = source.FreeMemory; 79 target.Resource.Name = source.Name; 80 target.Resource.ResourceId = source.Id; 88 81 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 } 89 89 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 } 92 106 } 93 107 } -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/ContextFactory.cs
r2904 r3011 15 15 return _hiveDataContext; 16 16 } 17 set { 18 _hiveDataContext = value; 19 } 17 20 } 18 21 } -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/HeuristicLab.Hive.Server.LINQDataAccess-3.2.csproj
r2904 r3011 87 87 <ItemGroup> 88 88 <Compile Include="BaseDao.cs" /> 89 <Compile Include="ClientConfigDao.cs" /> 89 90 <Compile Include="ClientDao.cs" /> 91 <Compile Include="ClientGroupDao.cs" /> 90 92 <Compile Include="ContextFactory.cs" /> 91 93 <Compile Include="Hive.designer.cs"> … … 94 96 <DependentUpon>Hive.dbml</DependentUpon> 95 97 </Compile> 96 <Compile Include="IClientDao.cs" /> 97 <Compile Include="IGenericDao.cs" /> 98 <Compile Include="IJobDao.cs" /> 98 <Compile Include="JobDao.cs" /> 99 99 <Compile Include="LINQDataAccessPlugin.cs" /> 100 <Compile Include="PluginInfoDao.cs" /> 100 101 <Compile Include="Properties\AssemblyInfo.cs" /> 101 102 <Compile Include="Properties\Settings.Designer.cs"> … … 122 123 <Project>{134F93D7-E7C8-4ECD-9923-7F63259A60D8}</Project> 123 124 <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> 124 129 </ProjectReference> 125 130 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/Hive.dbml
r2904 r3011 51 51 <Column Name="ResourceId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" /> 52 52 <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" /> 54 54 <Column Name="DateCreated" Type="System.DateTime" DbType="DateTime" CanBeNull="true" /> 55 55 <Column Name="DateCalculated" Type="System.DateTime" DbType="DateTime" CanBeNull="true" /> … … 58 58 <Column Name="ProjectId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" /> 59 59 <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" /> 62 62 <Association Name="Job_AssignedResource" Member="AssignedResources" ThisKey="JobId" OtherKey="JobId" Type="AssignedResource" /> 63 63 <Association Name="Job_Job" Member="Jobs" ThisKey="JobId" OtherKey="ParentJobId" Type="Job" /> … … 88 88 <Column Name="JobId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" /> 89 89 <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" /> 91 91 <Association Name="Job_RequiredPlugin" Member="Job" ThisKey="JobId" OtherKey="JobId" Type="Job" IsForeignKey="true" /> 92 92 <Association Name="PluginInfo_RequiredPlugin" Member="PluginInfo" ThisKey="PluginId" OtherKey="PluginId" Type="PluginInfo" IsForeignKey="true" DeleteRule="CASCADE" DeleteOnNull="true" /> … … 95 95 <Table Name="dbo.Resource" Member="Resources"> 96 96 <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" /> 98 98 <Column Name="Name" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" /> 99 99 <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 132 132 </nestedChildShapes> 133 133 </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"> 135 135 <AssociationMoniker Name="/HiveDataContext/Client/Client_UptimeStatistic" /> 136 136 <nodes> … … 139 139 </nodes> 140 140 </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"> 142 142 <AssociationMoniker Name="/HiveDataContext/Client/Client_Job" /> 143 143 <nodes> … … 146 146 </nodes> 147 147 </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"> 149 149 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_Client" /> 150 150 <nodes> … … 153 153 </nodes> 154 154 </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"> 156 156 <AssociationMoniker Name="/HiveDataContext/ClientConfig/ClientConfig_Client" /> 157 157 <nodes> -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/Hive.designer.cs
r2904 r3011 604 604 } 605 605 606 [Column(Storage="_UpDownTimeCalendar", DbType="Xml", UpdateCheck=UpdateCheck.Never)]606 [Column(Storage="_UpDownTimeCalendar", DbType="Xml", CanBeNull=true, UpdateCheck=UpdateCheck.Never)] 607 607 public System.Xml.Linq.XElement UpDownTimeCalendar 608 608 { … … 1029 1029 private System.Nullable<double> _Percentage; 1030 1030 1031 private System.Data.Linq. Binary_SerializedJob;1031 private System.Data.Linq.Link<System.Data.Linq.Binary> _SerializedJob; 1032 1032 1033 1033 private System.Nullable<System.DateTime> _DateCreated; … … 1043 1043 private System.Nullable<System.Guid> _UserId; 1044 1044 1045 private System.Nullable<int>_CoresNeeded;1046 1047 private System.Nullable<int>_MemoryNeeded;1045 private int _CoresNeeded; 1046 1047 private int _MemoryNeeded; 1048 1048 1049 1049 private EntitySet<AssignedResource> _AssignedResources; … … 1087 1087 partial void OnUserIdChanging(System.Nullable<System.Guid> value); 1088 1088 partial void OnUserIdChanged(); 1089 partial void OnCoresNeededChanging( System.Nullable<int>value);1089 partial void OnCoresNeededChanging(int value); 1090 1090 partial void OnCoresNeededChanged(); 1091 partial void OnMemoryNeededChanging( System.Nullable<int>value);1091 partial void OnMemoryNeededChanging(int value); 1092 1092 partial void OnMemoryNeededChanged(); 1093 1093 #endregion … … 1212 1212 } 1213 1213 1214 [Column(Storage="_SerializedJob", DbType="VarBinary(MAX)", UpdateCheck=UpdateCheck.Never)]1214 [Column(Storage="_SerializedJob", DbType="VarBinary(MAX)", CanBeNull=true, UpdateCheck=UpdateCheck.Never)] 1215 1215 public System.Data.Linq.Binary SerializedJob 1216 1216 { 1217 1217 get 1218 1218 { 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)) 1224 1224 { 1225 1225 this.OnSerializedJobChanging(value); 1226 1226 this.SendPropertyChanging(); 1227 this._SerializedJob = value;1227 this._SerializedJob.Value = value; 1228 1228 this.SendPropertyChanged("SerializedJob"); 1229 1229 this.OnSerializedJobChanged(); … … 1357 1357 1358 1358 [Column(Storage="_CoresNeeded", DbType="Int")] 1359 public System.Nullable<int>CoresNeeded1359 public int CoresNeeded 1360 1360 { 1361 1361 get … … 1377 1377 1378 1378 [Column(Storage="_MemoryNeeded", DbType="Int")] 1379 public System.Nullable<int>MemoryNeeded1379 public int MemoryNeeded 1380 1380 { 1381 1381 get … … 1953 1953 } 1954 1954 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)] 1956 1956 public System.Guid RequiredPluginId 1957 1957 { … … 2099 2099 } 2100 2100 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)] 2102 2102 public System.Guid ResourceId 2103 2103 { -
trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/LINQDataAccessPlugin.cs
r2850 r3011 9 9 [PluginFile("HeuristicLab.Hive.Server.LINQDataAccess-3.2.dll", PluginFileType.Assembly)] 10 10 [PluginDependency("HeuristicLab.Core-3.2")] 11 [PluginDependency("HeuristicLab.Hive.Contracts-3.2")] 12 [PluginDependency("HeuristicLab.Hive.Server.DataAccess-3.2")] 11 13 public class LINQDataAccessPlugin: PluginBase { 12 14 }
Note: See TracChangeset
for help on using the changeset viewer.