Changeset 4905 for branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess
- Timestamp:
- 11/22/10 17:13:27 (14 years ago)
- Location:
- branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New
- Property svn:ignore
-
old new 1 1 *.suo 2 Tests
-
- Property svn:ignore
-
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Convert.cs
r4649 r4905 45 45 SlaveId = source.SlaveId, 46 46 JobState = source.JobState, 47 UserId = source.UserId 47 UserId = source.UserId, 48 PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList() 48 49 }; 49 50 } … … 69 70 target.JobState = source.JobState; 70 71 target.UserId = source.UserId; 72 // target.RequiredPlugins = db.Plugins.Select(x => source.PluginsNeededIds.Contains(x.PluginId)); - this is difficult 71 73 } 72 74 } … … 107 109 #endregion 108 110 111 #region Plugin 112 public static DT.Plugin ToDto(Plugin source) { 113 if (source == null) return null; 114 return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version) }; 115 } 116 public static Plugin ToEntity(DT.Plugin source) { 117 if (source == null) return null; 118 var entity = new Plugin(); ToEntity(source, entity); 119 return entity; 120 } 121 public static void ToEntity(DT.Plugin source, Plugin target) { 122 if ((source != null) && (target != null)) { 123 target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString(); 124 } 125 } 126 #endregion 127 128 #region PluginData 129 public static DT.PluginData ToDto(PluginData source) { 130 if (source == null) return null; 131 return new DT.PluginData { PluginId = source.PluginId, Data = source.Data.ToArray() }; 132 } 133 public static PluginData ToEntity(DT.PluginData source) { 134 if (source == null) return null; 135 var entity = new PluginData(); ToEntity(source, entity); 136 return entity; 137 } 138 public static void ToEntity(DT.PluginData source, PluginData target) { 139 if ((source != null) && (target != null)) { 140 target.PluginId = source.PluginId; target.Data = new Binary(source.Data); 141 } 142 } 143 #endregion 144 109 145 #region Slave 110 146 public static DT.Slave ToDto(Slave source) { … … 137 173 if ((source != null) && (target != null)) { 138 174 target.ResourceId = source.Id; 139 target.Name = source.Name; 175 target.Name = source.Name; 140 176 //target.SlaveGroup_Resources_Children = // TODO: see how working with groups will work, then decide how to handle enumerations in here 141 177 //target.SlaveGroup_Resources_Parents = -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj
r4796 r4905 50 50 <HintPath>..\..\..\..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 51 51 </Reference> 52 <Reference Include="HeuristicLab.Tracing-3.3, Version=3.2.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 52 <Reference Include="HeuristicLab.Tracing-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 53 <SpecificVersion>False</SpecificVersion> 54 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Tracing-3.3.dll</HintPath> 55 </Reference> 53 56 <Reference Include="System" /> 54 57 <Reference Include="System.Core" /> -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDao.cs
r4649 r4905 11 11 12 12 public class HiveDao : IHiveDao { 13 public HiveDataContext CreateContext() {13 public static HiveDataContext CreateContext() { 14 14 return new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 15 15 } … … 74 74 } 75 75 76 public IEnumerable<DT.Job> Get AvailableJobs(DT.Slave slave) {76 public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave) { 77 77 using (var db = CreateContext()) { 78 78 var query = from j in db.Jobs … … 166 166 #endregion 167 167 168 #region Plugin Methods 169 public DT.Plugin GetPlugin(Guid id) { 170 using (var db = CreateContext()) { 171 return Convert.ToDto(db.Plugins.SingleOrDefault(x => x.PluginId == id)); 172 } 173 } 174 175 public IEnumerable<DT.Plugin> GetPlugins(Expression<Func<Plugin, bool>> predicate) { 176 using (var db = CreateContext()) { 177 return db.Plugins.Where(predicate).Select(x => Convert.ToDto(x)).ToArray(); 178 } 179 } 180 181 public Guid AddPlugin(DT.Plugin dto) { 182 using (var db = CreateContext()) { 183 var entity = Convert.ToEntity(dto); 184 db.Plugins.InsertOnSubmit(entity); 185 db.SubmitChanges(); 186 return entity.PluginId; 187 } 188 } 189 190 public void UpdatePlugin(DT.Plugin dto) { 191 using (var db = CreateContext()) { 192 var entity = db.Plugins.FirstOrDefault(x => x.PluginId == dto.Id); 193 if (entity == null) db.Plugins.InsertOnSubmit(Convert.ToEntity(dto)); 194 else Convert.ToEntity(dto, entity); 195 db.SubmitChanges(); 196 } 197 } 198 199 public void DeletePlugin(Guid id) { 200 using (var db = CreateContext()) { 201 var entity = db.Plugins.FirstOrDefault(x => x.PluginId == id); 202 if (entity != null) db.Plugins.DeleteOnSubmit(entity); 203 db.SubmitChanges(); 204 } 205 } 206 #endregion 207 208 #region PluginData Methods 209 210 public DT.PluginData GetPluginData(Guid id) { 211 using (var db = CreateContext()) { 212 return Convert.ToDto(db.PluginDatas.SingleOrDefault(x => x.PluginId == id)); 213 } 214 } 215 216 public IEnumerable<DT.PluginData> GetPluginDatas(Expression<Func<PluginData, bool>> predicate) { 217 using (var db = CreateContext()) { 218 return db.PluginDatas.Where(predicate).Select(x => Convert.ToDto(x)).ToArray(); 219 } 220 } 221 222 public Guid AddPluginData(DT.PluginData dto) { 223 using (var db = CreateContext()) { 224 var entity = Convert.ToEntity(dto); 225 db.PluginDatas.InsertOnSubmit(entity); 226 db.SubmitChanges(); 227 return entity.PluginId; 228 } 229 } 230 231 public void UpdatePluginData(DT.PluginData dto) { 232 using (var db = CreateContext()) { 233 var entity = db.PluginDatas.FirstOrDefault(x => x.PluginId == dto.PluginId); 234 if (entity == null) db.PluginDatas.InsertOnSubmit(Convert.ToEntity(dto)); 235 else Convert.ToEntity(dto, entity); 236 db.SubmitChanges(); 237 } 238 } 239 240 public void DeletePluginData(Guid id) { 241 using (var db = CreateContext()) { 242 var entity = db.PluginDatas.FirstOrDefault(x => x.PluginId == id); // check if all the byte[] is loaded into memory here. otherwise work around to delete without loading it 243 if (entity != null) db.PluginDatas.DeleteOnSubmit(entity); 244 db.SubmitChanges(); 245 } 246 } 247 #endregion 248 168 249 #region Slave Methods 169 250 public DT.Slave GetSlave(Guid id) { -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
r4649 r4905 40 40 <Column Name="Name" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" /> 41 41 <Column Name="Version" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" /> 42 <Column Name="BuildDate" Type="System.String" DbType="VarChar(20)" CanBeNull="false" />43 42 <Association Name="Plugin_RequiredPlugin" Member="RequiredPlugins" ThisKey="PluginId" OtherKey="PluginId" Type="RequiredPlugin" /> 44 43 <Association Name="Plugin_PluginData" Member="PluginData" ThisKey="PluginId" OtherKey="PluginId" Type="PluginData" Cardinality="One" /> -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout
r4615 r4905 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 17.25, 12. 5" name="HiveDataContext">2 <ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 17.25, 12.25" name="HiveDataContext"> 3 3 <DataContextMoniker Name="/HiveDataContext" /> 4 4 <nestedChildShapes> … … 27 27 </nestedChildShapes> 28 28 </classShape> 29 <classShape Id="7d998e56-4fba-41ca-a1a8-1dcdb9068edf" absoluteBounds="9, 10.625, 2, 1. 5785953776041666">29 <classShape Id="7d998e56-4fba-41ca-a1a8-1dcdb9068edf" absoluteBounds="9, 10.625, 2, 1.3862939453125005"> 30 30 <DataClassMoniker Name="/HiveDataContext/Plugin" /> 31 31 <nestedChildShapes> 32 <elementListCompartment Id="ec4ba325-6dff-4418-baad-59af81ae2024" absoluteBounds="9.015, 11.085, 1.9700000000000002, 1.0185953776041665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />32 <elementListCompartment Id="ec4ba325-6dff-4418-baad-59af81ae2024" absoluteBounds="9.015, 11.085, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 33 33 </nestedChildShapes> 34 34 </classShape> … … 189 189 </nestedChildShapes> 190 190 </classShape> 191 <associationConnector edgePoints="[(11 : 11.2219962565104); (11.5 : 11.2219962565104)]" fixedFrom=" NotFixed" fixedTo="NotFixed">191 <associationConnector edgePoints="[(11 : 11.2219962565104); (11.5 : 11.2219962565104)]" fixedFrom="Algorithm" fixedTo="Algorithm"> 192 192 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_PluginData" /> 193 193 <nodes> … … 203 203 </nodes> 204 204 </associationConnector> 205 <associationConnector edgePoints="[(10.125 : 10.625); (10.125 : 10.2612939453125)]" fixedFrom=" NotFixed" fixedTo="NotFixed">205 <associationConnector edgePoints="[(10.125 : 10.625); (10.125 : 10.2612939453125)]" fixedFrom="Algorithm" fixedTo="Algorithm"> 206 206 <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" /> 207 207 <nodes> -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
r4649 r4905 907 907 private string _Version; 908 908 909 private string _BuildDate;910 911 909 private EntitySet<RequiredPlugin> _RequiredPlugins; 912 910 … … 921 919 partial void OnVersionChanging(string value); 922 920 partial void OnVersionChanged(); 923 partial void OnBuildDateChanging(string value);924 partial void OnBuildDateChanged();925 921 #endregion 926 922 … … 987 983 this.SendPropertyChanged("Version"); 988 984 this.OnVersionChanged(); 989 }990 }991 }992 993 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_BuildDate", DbType="VarChar(20)", CanBeNull=false)]994 public string BuildDate995 {996 get997 {998 return this._BuildDate;999 }1000 set1001 {1002 if ((this._BuildDate != value))1003 {1004 this.OnBuildDateChanging(value);1005 this.SendPropertyChanging();1006 this._BuildDate = value;1007 this.SendPropertyChanged("BuildDate");1008 this.OnBuildDateChanged();1009 985 } 1010 986 } -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IHiveDao.cs
r4629 r4905 15 15 void UpdateJob(DT.Job dto); 16 16 void DeleteJob(Guid id); 17 IEnumerable<DT.Job> Get AvailableJobs(DT.Slave slave);17 IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave); 18 18 #endregion 19 19 … … 35 35 36 36 #region Plugin Methods 37 DT.Plugin GetPlugin(Guid id); 38 IEnumerable<DT.Plugin> GetPlugins(Expression<Func<Plugin, bool>> predicate); 39 Guid AddPlugin(DT.Plugin dto); 40 void UpdatePlugin(DT.Plugin dto); 41 void DeletePlugin(Guid id); 37 42 #endregion 38 43 39 44 #region PluginData Methods 45 DT.PluginData GetPluginData(Guid id); 46 IEnumerable<DT.PluginData> GetPluginDatas(Expression<Func<PluginData, bool>> predicate); 47 Guid AddPluginData(DT.PluginData dto); 48 void UpdatePluginData(DT.PluginData dto); 49 void DeletePluginData(Guid id); 40 50 #endregion 41 51 -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Tools/CreateHiveDatabaseApplication.cs
r4649 r4905 27 27 28 28 public override void Run() { 29 var dao = new HiveDao(); 30 using (var db = dao.CreateContext()) { 29 using (var db = HiveDao.CreateContext()) { 31 30 if (db.DatabaseExists()) 32 31 db.DeleteDatabase(); -
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Tools/prepareHiveDatabase.sql
r4629 r4905 31 31 ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId ADD ROWGUIDCOL; 32 32 ALTER TABLE dbo.AssignedResources WITH NOCHECK ADD CONSTRAINT [DF_AssignedResources_AssignedRessourcesId] DEFAULT (newid()) FOR AssignedRessourcesId; 33 ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [Job_AssignedResource] 34 ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [Job_AssignedResource] FOREIGN KEY([JobId]) 35 REFERENCES [dbo].[Job] ([JobId]) 36 ON UPDATE CASCADE 37 ON DELETE CASCADE 38 GO 39 ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [Resource_AssignedResource] 40 ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [Resource_AssignedResource] FOREIGN KEY([ResourceId]) 41 REFERENCES [dbo].[Resource] ([ResourceId]) 42 ON UPDATE CASCADE 43 ON DELETE CASCADE 44 GO 33 45 34 46 ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL; … … 50 62 ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (newid()) FOR RequiredPluginId; 51 63 64 ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Job_RequiredPlugin] 65 ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Job_RequiredPlugin] FOREIGN KEY([JobId]) 66 REFERENCES [dbo].[Job] ([JobId]) 67 ON UPDATE CASCADE 68 ON DELETE CASCADE 69 GO 70 71 ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Plugin_RequiredPlugin] 72 ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY([PluginId]) 73 REFERENCES [dbo].[Plugin] ([PluginId]) 74 ON UPDATE CASCADE 75 ON DELETE CASCADE 76 GO 77 52 78 ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL; 53 79 ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (newid()) FOR ResourceId; … … 64 90 /* create indices */ 65 91 CREATE INDEX Index_RequiredPlugins_JobId ON RequiredPlugins(JobId); 92 93 /* triggers */ 94 SET ANSI_NULLS ON 95 GO 96 SET QUOTED_IDENTIFIER ON 97 GO 98 -- ============================================= 99 -- Author: cneumuel 100 -- Create date: 11.11.2010 101 -- Description: Deletes the root-job of the experiment when experiment is deleted 102 -- ============================================= 103 CREATE TRIGGER [dbo].[tr_HiveExperimentDeleteCascade] ON [dbo].[HiveExperiment] FOR DELETE AS 104 SET NOCOUNT ON 105 DELETE Job FROM deleted, Job WHERE Job.JobId = deleted.RootJobId 106 GO 107 108 SET ANSI_NULLS ON 109 GO 110 SET QUOTED_IDENTIFIER ON 111 GO 112 -- ============================================= 113 -- Author: cneumuel 114 -- Create date: 11.11.2010 115 -- Description: Recursively deletes all child-jobs of a job when it is deleted. (Source: http://devio.wordpress.com/2008/05/23/recursive-delete-in-sql-server/) 116 -- ============================================= 117 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS 118 BEGIN 119 CREATE TABLE #Table( 120 JobId uniqueidentifier 121 ) 122 INSERT INTO #Table (JobId) 123 SELECT JobId FROM deleted 124 125 DECLARE @c INT 126 SET @c = 0 127 128 WHILE @c <> (SELECT COUNT(JobId) FROM #Table) BEGIN 129 SELECT @c = COUNT(JobId) FROM #Table 130 131 INSERT INTO #Table (JobId) 132 SELECT Job.JobId 133 FROM Job 134 LEFT OUTER JOIN #Table ON Job.JobId = #Table.JobId 135 WHERE Job.ParentJobId IN (SELECT JobId FROM #Table) 136 AND #Table.JobId IS NULL 137 END 138 139 DELETE Job FROM Job INNER JOIN #Table ON Job.JobId = #Table.JobId 140 END
Note: See TracChangeset
for help on using the changeset viewer.