Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs	(revision 5404)
@@ -143,5 +143,5 @@
     public static DT.Slave ToDto(Slave source) {
       if (source == null) return null;
-      return new DT.Slave { Id = source.ResourceId, ParentResourceId = source.ParentResourceId, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveState = source.SlaveState };
+      return new DT.Slave { Id = source.ResourceId, ParentResourceId = source.ParentResourceId, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveState = source.SlaveState, CpuArchitecture = source.CpuArchitecture, OperatingSystem = source.OperatingSystem };
     }
     public static Slave ToEntity(DT.Slave source) {
@@ -152,5 +152,5 @@
     public static void ToEntity(DT.Slave source, Slave target) {
       if ((source != null) && (target != null)) {
-        target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = source.SlaveState;
+        target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = source.SlaveState; target.CpuArchitecture = source.CpuArchitecture; target.OperatingSystem = source.OperatingSystem;
       }
     }
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Exceptions/DaoException.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Exceptions/DaoException.cs	(revision 5404)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Exceptions/DaoException.cs	(revision 5404)
@@ -0,0 +1,10 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace HeuristicLab.Services.Hive.DataAccess {
+  public class DaoException : Exception {
+    public DaoException(string message) : base(message) { }
+  }
+}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HeuristicLab.Services.Hive.DataAccess-3.4.csproj	(revision 5404)
@@ -103,4 +103,5 @@
     <Compile Include="Convert.cs" />
     <None Include="HeuristicLabServicesHiveDataAccessPlugin.cs.frame" />
+    <Compile Include="Exceptions\DaoException.cs" />
     <Compile Include="HeuristicLabServicesHiveDataAccessPlugin.cs" />
     <Compile Include="HiveDao.cs" />
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDao.cs	(revision 5404)
@@ -82,29 +82,35 @@
     }
 
-    public IEnumerable<DT.Job> GetWaitingParentJobs(Guid slaveId) {
-      using (var db = CreateContext()) {
-        // todo: slaveId is unused!
+    public IEnumerable<DT.Job> GetWaitingParentJobs(IEnumerable<Guid> resourceIds, int count) {
+      using (var db = CreateContext()) {
         var query = from ar in db.AssignedResources
-                    where ar.Job.JobState == JobState.WaitingForChildJobs &&
-                      (from child in db.Jobs
-                       where child.ParentJobId == ar.Job.JobId
-                       select child.JobState == JobState.Finished).All(x => x) &&
-                      (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet)
-                       where child.ParentJobId == ar.Job.JobId
-                       select child).Count() > 0
+                    where resourceIds.Contains(ar.ResourceId)
+                       && ar.Job.JobState == JobState.WaitingForChildJobs
+                       && (from child in db.Jobs
+                           where child.ParentJobId == ar.Job.JobId
+                           select child.JobState == JobState.Finished).All(x => x)
+                       && (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet)
+                           where child.ParentJobId == ar.Job.JobId
+                           select child).Count() > 0
                     orderby ar.Job.Priority descending
                     select Convert.ToDto(ar.Job);
-        return query.ToArray();
-      }
-    }
-
-    public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave) {
-      using (var db = CreateContext()) {
-        var query = from j in db.Jobs
-                    where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory
-                    orderby j.Priority descending
-                    select Convert.ToDto(j);
-        var waitingJobs = query.ToArray();
-        var waitingParentJobs = GetWaitingParentJobs(slave.Id);
+        return count == 0 ? query.ToArray() : query.Take(count).ToArray();
+      }
+    }
+
+    public IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count) {
+      using (var db = CreateContext()) {
+        var resourceIds = GetParentResources(slave.Id).Select(r => r.Id);
+        var waitingParentJobs = GetWaitingParentJobs(resourceIds, count);
+        if (count > 0 && waitingParentJobs.Count() >= count) return waitingParentJobs.Take(count).ToArray();
+
+        var query = from ar in db.AssignedResources
+                    where resourceIds.Contains(ar.ResourceId)
+                       && ar.Job.JobState == JobState.Waiting
+                       && ar.Job.CoresNeeded <= slave.FreeCores
+                       && ar.Job.MemoryNeeded <= slave.FreeMemory
+                    orderby ar.Job.Priority descending
+                    select Convert.ToDto(ar.Job);
+        var waitingJobs = (count == 0 ? query : query.Take(count)).ToArray();
         return waitingJobs.Union(waitingParentJobs).OrderByDescending(x => x.Priority);
       }
@@ -350,5 +356,10 @@
       using (var db = CreateContext()) {
         var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id);
-        if (entity != null) db.Resources.DeleteOnSubmit(entity);
+        if (entity != null) {
+          if (db.Resources.Where(r => r.ParentResourceId == id).Count() > 0) {
+            throw new DaoException("Cannot delete SlaveGroup as long as there are Slaves in the group");
+          }
+          db.Resources.DeleteOnSubmit(entity);
+        }
         db.SubmitChanges();
       }
@@ -408,4 +419,21 @@
         return job.AssignedResources.Select(x => Convert.ToDto(x.Resource)).ToArray();
       }
+    }
+
+    /// <summary>
+    /// Returns all parent resources of a resource (the given resource is also added)
+    /// </summary>
+    private IEnumerable<DT.Resource> GetParentResources(Guid resourceId) {
+      using (var db = CreateContext()) {
+        var resources = new List<Resource>();
+        CollectParentResources(resources, db.Resources.Where(r => r.ResourceId == resourceId).Single());
+        return resources.Select(r => Convert.ToDto(r)).ToArray();
+      }
+    }
+
+    private void CollectParentResources(List<Resource> resources, Resource resource) {
+      if (resource == null) return;
+      resources.Add(resource);
+      CollectParentResources(resources, resource.ParentResource);
     }
     #endregion
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml	(revision 5404)
@@ -49,4 +49,6 @@
         <Column Name="FreeMemory" Type="System.Int32" DbType="Int" CanBeNull="true" />
         <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" />
+        <Column Name="CpuArchitecture" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture" DbType="VarChar(3)" CanBeNull="false" />
+        <Column Name="OperatingSystem" Type="System.String" DbType="VarChar(MAX)" CanBeNull="false" />
         <Association Name="Slave_Job" Member="Jobs" ThisKey="ResourceId" OtherKey="SlaveId" Type="Job" />
       </Type>
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.dbml.layout	(revision 5404)
@@ -45,8 +45,8 @@
       </nestedChildShapes>
     </classShape>
-    <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2.3478011067708335">
+    <classShape Id="26f4edfa-91dd-4941-a058-359f89e567a8" absoluteBounds="8.875, 1, 2, 2.7324039713541666">
       <DataClassMoniker Name="/HiveDataContext/Slave" />
       <nestedChildShapes>
-        <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
+        <elementListCompartment Id="1e61f36b-08dc-4df7-8594-c9dcd95c0791" absoluteBounds="8.89, 1.46, 1.9700000000000002, 2.1724039713541665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
       </nestedChildShapes>
     </classShape>
@@ -69,5 +69,5 @@
       </nodes>
     </inheritanceConnector>
-    <associationConnector edgePoints="[(12.25 : 2.57859537760417); (12.25 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
+    <associationConnector edgePoints="[(11.9843735 : 2.57859537760417); (11.9843735 : 4.44314697265625); (10.875 : 4.44314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Resource/Resource_AssignedResource" />
       <nodes>
@@ -97,5 +97,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(8.875 : 2.17390055338542); (8.5 : 2.17390055338542)]" fixedFrom="NotFixed" fixedTo="NotFixed">
+    <associationConnector edgePoints="[(8.875 : 2.36620198567708); (8.5 : 2.36620198567708)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Slave/Slave_Job" />
       <nodes>
@@ -130,5 +130,5 @@
       </nestedChildShapes>
     </classShape>
-    <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom="Algorithm" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(11 : 6.28929768880208); (11.625 : 6.28929768880208)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_PluginData" />
       <nodes>
@@ -144,5 +144,5 @@
       </nodes>
     </associationConnector>
-    <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom="Algorithm" fixedTo="Algorithm">
+    <associationConnector edgePoints="[(9 : 6.19314697265625); (8.5 : 6.19314697265625)]" fixedFrom="NotFixed" fixedTo="NotFixed">
       <AssociationMoniker Name="/HiveDataContext/Plugin/Plugin_RequiredPlugin" />
       <nodes>
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/HiveDataContext.designer.cs	(revision 5404)
@@ -3,5 +3,5 @@
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.1
+//     Runtime Version:4.0.30319.208
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
@@ -1060,4 +1060,8 @@
 		private bool _IsAllowedToCalculate;
 		
+		private global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture _CpuArchitecture;
+		
+		private string _OperatingSystem;
+		
 		private EntitySet<Job> _Jobs;
 		
@@ -1082,4 +1086,8 @@
     partial void OnIsAllowedToCalculateChanging(bool value);
     partial void OnIsAllowedToCalculateChanged();
+    partial void OnCpuArchitectureChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture value);
+    partial void OnCpuArchitectureChanged();
+    partial void OnOperatingSystemChanging(string value);
+    partial void OnOperatingSystemChanged();
     #endregion
 		
@@ -1246,4 +1254,44 @@
 					this.SendPropertyChanged("IsAllowedToCalculate");
 					this.OnIsAllowedToCalculateChanged();
+				}
+			}
+		}
+		
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CpuArchitecture", DbType="VarChar(3)", CanBeNull=false)]
+		public global::HeuristicLab.Services.Hive.Common.DataTransfer.CpuArchitecture CpuArchitecture
+		{
+			get
+			{
+				return this._CpuArchitecture;
+			}
+			set
+			{
+				if ((this._CpuArchitecture != value))
+				{
+					this.OnCpuArchitectureChanging(value);
+					this.SendPropertyChanging();
+					this._CpuArchitecture = value;
+					this.SendPropertyChanged("CpuArchitecture");
+					this.OnCpuArchitectureChanged();
+				}
+			}
+		}
+		
+		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OperatingSystem", DbType="VarChar(MAX)", CanBeNull=false)]
+		public string OperatingSystem
+		{
+			get
+			{
+				return this._OperatingSystem;
+			}
+			set
+			{
+				if ((this._OperatingSystem != value))
+				{
+					this.OnOperatingSystemChanging(value);
+					this.SendPropertyChanging();
+					this._OperatingSystem = value;
+					this.SendPropertyChanged("OperatingSystem");
+					this.OnOperatingSystemChanged();
 				}
 			}
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Interfaces/IHiveDao.cs	(revision 5404)
@@ -15,5 +15,5 @@
     void UpdateJob(DT.Job dto);
     void DeleteJob(Guid id);
-    IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave);
+    IEnumerable<DT.Job> GetWaitingJobs(DT.Slave slave, int count);
     #endregion
 
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql	(revision 5402)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql	(revision 5404)
@@ -40,4 +40,11 @@
 ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
 ALTER TABLE dbo.Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (newid()) FOR JobId;
+
+--ALTER TABLE [dbo].[Job]  DROP  CONSTRAINT [Slave_Job]
+--ALTER TABLE [dbo].[Job]  WITH CHECK ADD  CONSTRAINT [Slave_Job] FOREIGN KEY([ResourceId])
+--REFERENCES [dbo].[Resource] ([ResourceId])
+--ON UPDATE CASCADE
+--ON DELETE SET NULL
+--GO
 
 ALTER TABLE dbo.Plugin ALTER COLUMN PluginId ADD ROWGUIDCOL;
