Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Calendar/3.3/Properties/AssemblyInfo.cs	(revision 4769)
@@ -58,3 +58,3 @@
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("3.3.0.0")]
-[assembly: AssemblyFileVersion("3.3.0.4755")]
+[assembly: AssemblyFileVersion("3.3.0.4760")]
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentManagerView.cs
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentManagerView.cs	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentManagerView.cs	(revision 4769)
@@ -53,4 +53,5 @@
       Content_HiveExperimentsChanged(this, EventArgs.Empty);
       Content_IsProgressingChanged(this, EventArgs.Empty);
+      if(Content != null) UpdateExperimentsAsync();
     }
 
@@ -78,13 +79,5 @@
 
     private void updateExperimentsButton_Click(object sender, EventArgs e) {
-      MethodInvoker invoker = new MethodInvoker(Content.UpdateExperimentList);
-      invoker.BeginInvoke((ar) => {
-        try {
-          invoker.EndInvoke(ar);
-        }
-        catch (Exception ex) {
-          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
-        }
-      }, null);
+      if(Content != null) UpdateExperimentsAsync();
     }
 
@@ -116,4 +109,16 @@
       }
     }
+
+    private void UpdateExperimentsAsync() {
+      MethodInvoker invoker = new MethodInvoker(Content.UpdateExperimentList);
+      invoker.BeginInvoke((ar) => {
+        try {
+          invoker.EndInvoke(ar);
+        }
+        catch (Exception ex) {
+          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
+        }
+      }, null);
+    }
   }
 }
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.Designer.cs
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.Designer.cs	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.Designer.cs	(revision 4769)
@@ -313,9 +313,9 @@
       this.disconnectButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
       this.disconnectButton.Enabled = false;
-      this.disconnectButton.Location = new System.Drawing.Point(131, 500);
+      this.disconnectButton.Location = new System.Drawing.Point(234, 500);
       this.disconnectButton.Name = "disconnectButton";
       this.disconnectButton.Size = new System.Drawing.Size(120, 24);
       this.disconnectButton.TabIndex = 15;
-      this.disconnectButton.Text = "Disconnect from Hive";
+      this.disconnectButton.Text = "Stop Result Polling";
       this.toolTip.SetToolTip(this.disconnectButton, "Disconnect from Hive (Jobs will be continue to be calculated)");
       this.disconnectButton.UseVisualStyleBackColor = true;
@@ -326,9 +326,9 @@
       this.reconnectButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
       this.reconnectButton.Enabled = false;
-      this.reconnectButton.Location = new System.Drawing.Point(257, 500);
+      this.reconnectButton.Location = new System.Drawing.Point(120, 500);
       this.reconnectButton.Name = "reconnectButton";
-      this.reconnectButton.Size = new System.Drawing.Size(77, 24);
+      this.reconnectButton.Size = new System.Drawing.Size(108, 24);
       this.reconnectButton.TabIndex = 16;
-      this.reconnectButton.Text = "Reconnect";
+      this.reconnectButton.Text = "Start Result Polling";
       this.toolTip.SetToolTip(this.reconnectButton, "Reconnect to Hive");
       this.reconnectButton.UseVisualStyleBackColor = true;
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.resx
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.resx	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentView.resx	(revision 4769)
@@ -204,5 +204,5 @@
         fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+
         tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/
-        6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAAOvgAADr4B6kKxwAAAA2JJREFUOE9lk31MFHQY
+        6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAAOvQAADr0BR/uQrQAAA2JJREFUOE9lk31MFHQY
         x59JZIU62/QPF1gauDJXjkpyZLxVMEEubgpKU0NePKS6yp168qaJ4OIlMhUH6hRWChyuuuTaQjqFk8j0
         MEhlURdMRgp0XERccfjpx7G1Vn8822+/fb/fz/f54xFA/jtDf03S4fyTloE/6PhlFNfvY0xMTCjZ/7X/
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HeuristicLab.Hive.ExperimentManager-3.3.csproj
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HeuristicLab.Hive.ExperimentManager-3.3.csproj	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HeuristicLab.Hive.ExperimentManager-3.3.csproj	(revision 4769)
@@ -125,5 +125,5 @@
     <Compile Include="JobResultPoller.cs" />
     <Compile Include="Exceptions\JobResultPollingException.cs" />
-    <Compile Include="HiveClient.cs" />
+    <Compile Include="HiveExperimentManager.cs" />
     <Compile Include="HiveExperimentList.cs" />
     <Compile Include="HeuristicLabHiveExperimentManagerPlugin.cs" />
Index: anches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HiveClient.cs
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HiveClient.cs	(revision 4768)
+++ 	(revision )
@@ -1,168 +1,0 @@
-﻿#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * This file is part of HeuristicLab.
- *
- * HeuristicLab is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * HeuristicLab is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
- */
-#endregion
-
-using System;
-using System.Linq;
-using HeuristicLab.Collections;
-using HeuristicLab.Core;
-using HeuristicLab.Hive.Contracts;
-using HeuristicLab.Hive.Contracts.BusinessObjects;
-using HeuristicLab.Hive.Contracts.Interfaces;
-using HeuristicLab.Hive.Contracts.ResponseObjects;
-using HeuristicLab.Common;
-
-namespace HeuristicLab.Hive.ExperimentManager {
-  [Item("Hive Experiment Manager", "Connects to Hive and lists all submitted experiments by the current user.")]
-  public class HiveExperimentManager : Item, IProgressReporter {
-    private static object locker = new object();
-    private bool currentlyUpdating;
-
-    private ILog log;
-    public ILog Log {
-      get { return log; }
-    }
-
-    private HiveExperimentList hiveExperiments;
-    public HiveExperimentList HiveExperiments {
-      get { return hiveExperiments; }
-      set {
-        if (hiveExperiments != value) {
-          DeRegisterHiveExperimentsEvents();
-          hiveExperiments = value;
-          RegisterHiveExperimentsEvent();
-          OnHiveExperimentsChanged();
-        }
-      }
-    }
-
-    private bool isProgressing;
-    public bool IsProgressing {
-      get { return isProgressing; }
-      set {
-        if (isProgressing != value) {
-          isProgressing = value;
-          OnIsProgressingChanged();
-        }
-      }
-    }
-
-    private IProgress progress;
-    public IProgress Progress {
-      get { return progress; }
-    }
-
-    private void RegisterHiveExperimentsEvent() {
-      if (hiveExperiments != null) {
-        hiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
-      }
-    }
-
-    private void DeRegisterHiveExperimentsEvents() {
-      if (hiveExperiments != null) {
-        hiveExperiments.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
-      }
-    }
-
-    public HiveExperimentManager() {
-      this.log = new Log();
-    }
-    protected HiveExperimentManager(HiveExperimentManager original, Cloner cloner)
-      : base(original, cloner) {
-      this.log = cloner.Clone(original.Log);
-      this.HiveExperiments = cloner.Clone(original.HiveExperiments);
-    }
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new HiveExperimentManager(this, cloner);
-    }
-
-    public void UpdateExperimentList() {
-      this.progress = new Progress("Downloading HiveExperiments...");
-      try {
-        IsProgressing = true;
-        if (this.HiveExperiments == null) {
-          this.HiveExperiments = new HiveExperimentList();
-        }
-        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
-          currentlyUpdating = true;
-          ResponseObject<HiveExperimentDtoList> response = service.Obj.GetHiveExperiments();
-          progress.Status = "Populating HiveExperiment list...";
-          RefreshExperimentList(response.Obj);
-          currentlyUpdating = false;
-        }
-      }
-      catch (Exception) {
-        this.HiveExperiments = null;
-        throw;
-      }
-      finally {
-        IsProgressing = false;
-      }
-    }
-
-    private void RefreshExperimentList(HiveExperimentDtoList hiveExperiments) {
-      foreach (HiveExperimentDto hiveExperimentDto in hiveExperiments) {
-        HiveExperiment hiveExperiment = GetHiveExperiment(hiveExperimentDto.Id);
-        if (hiveExperiment == null) {
-          // not yet there, create new
-          this.HiveExperiments.Add(new HiveExperiment(hiveExperimentDto));
-        } else {
-          // update
-          hiveExperiment.UpdateFromDto(hiveExperimentDto);
-        }
-      }
-    }
-
-    private HiveExperiment GetHiveExperiment(Guid hiveExperimentId) {
-      return this.HiveExperiments.SingleOrDefault(he => he.HiveExperimentId.Equals(hiveExperimentId));
-    }
-
-    private void LogMessage(string message) {
-      // HeuristicLab.Log is not Thread-Safe, so lock on every call
-      lock (locker) {
-        log.LogMessage(message);
-      }
-    }
-
-    public event EventHandler HiveExperimentsChanged;
-    private void OnHiveExperimentsChanged() {
-      var handler = HiveExperimentsChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-
-    void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
-      if (!currentlyUpdating) {
-        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
-          foreach (IndexedItem<HiveExperiment> item in e.Items) {
-            if (item.Value.HiveExperimentId != Guid.Empty) {
-              service.Obj.DeleteHiveExperiment(item.Value.HiveExperimentId);
-            }
-          }
-        }
-      }
-    }
-
-    public event EventHandler IsProgressingChanged;
-    private void OnIsProgressingChanged() {
-      var handler = IsProgressingChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-  }
-}
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HiveExperimentManager.cs
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HiveExperimentManager.cs	(revision 4769)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager/3.3/HiveExperimentManager.cs	(revision 4769)
@@ -0,0 +1,168 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Linq;
+using HeuristicLab.Collections;
+using HeuristicLab.Core;
+using HeuristicLab.Hive.Contracts;
+using HeuristicLab.Hive.Contracts.BusinessObjects;
+using HeuristicLab.Hive.Contracts.Interfaces;
+using HeuristicLab.Hive.Contracts.ResponseObjects;
+using HeuristicLab.Common;
+
+namespace HeuristicLab.Hive.ExperimentManager {
+  [Item("Hive Experiment Manager", "Connects to Hive and lists all submitted experiments by the current user.")]
+  public class HiveExperimentManager : Item, IProgressReporter {
+    private static object locker = new object();
+    private bool currentlyUpdating;
+
+    private ILog log;
+    public ILog Log {
+      get { return log; }
+    }
+
+    private HiveExperimentList hiveExperiments;
+    public HiveExperimentList HiveExperiments {
+      get { return hiveExperiments; }
+      set {
+        if (hiveExperiments != value) {
+          DeRegisterHiveExperimentsEvents();
+          hiveExperiments = value;
+          RegisterHiveExperimentsEvent();
+          OnHiveExperimentsChanged();
+        }
+      }
+    }
+
+    private bool isProgressing;
+    public bool IsProgressing {
+      get { return isProgressing; }
+      set {
+        if (isProgressing != value) {
+          isProgressing = value;
+          OnIsProgressingChanged();
+        }
+      }
+    }
+
+    private IProgress progress;
+    public IProgress Progress {
+      get { return progress; }
+    }
+
+    private void RegisterHiveExperimentsEvent() {
+      if (hiveExperiments != null) {
+        hiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
+      }
+    }
+
+    private void DeRegisterHiveExperimentsEvents() {
+      if (hiveExperiments != null) {
+        hiveExperiments.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
+      }
+    }
+
+    public HiveExperimentManager() {
+      this.log = new Log();
+    }
+    protected HiveExperimentManager(HiveExperimentManager original, Cloner cloner)
+      : base(original, cloner) {
+      this.log = cloner.Clone(original.Log);
+      this.HiveExperiments = cloner.Clone(original.HiveExperiments);
+    }
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new HiveExperimentManager(this, cloner);
+    }
+
+    public void UpdateExperimentList() {
+      this.progress = new Progress("Downloading HiveExperiments...");
+      try {
+        IsProgressing = true;
+        if (this.HiveExperiments == null) {
+          this.HiveExperiments = new HiveExperimentList();
+        }
+        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
+          currentlyUpdating = true;
+          ResponseObject<HiveExperimentDtoList> response = service.Obj.GetHiveExperiments();
+          progress.Status = "Populating HiveExperiment list...";
+          RefreshExperimentList(response.Obj);
+          currentlyUpdating = false;
+        }
+      }
+      catch (Exception) {
+        this.HiveExperiments = null;
+        throw;
+      }
+      finally {
+        IsProgressing = false;
+      }
+    }
+
+    private void RefreshExperimentList(HiveExperimentDtoList hiveExperiments) {
+      foreach (HiveExperimentDto hiveExperimentDto in hiveExperiments) {
+        HiveExperiment hiveExperiment = GetHiveExperiment(hiveExperimentDto.Id);
+        if (hiveExperiment == null) {
+          // not yet there, create new
+          this.HiveExperiments.Add(new HiveExperiment(hiveExperimentDto));
+        } else {
+          // update
+          hiveExperiment.UpdateFromDto(hiveExperimentDto);
+        }
+      }
+    }
+
+    private HiveExperiment GetHiveExperiment(Guid hiveExperimentId) {
+      return this.HiveExperiments.SingleOrDefault(he => he.HiveExperimentId.Equals(hiveExperimentId));
+    }
+
+    private void LogMessage(string message) {
+      // HeuristicLab.Log is not Thread-Safe, so lock on every call
+      lock (locker) {
+        log.LogMessage(message);
+      }
+    }
+
+    public event EventHandler HiveExperimentsChanged;
+    private void OnHiveExperimentsChanged() {
+      var handler = HiveExperimentsChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+
+    void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
+      if (!currentlyUpdating) {
+        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
+          foreach (IndexedItem<HiveExperiment> item in e.Items) {
+            if (item.Value.HiveExperimentId != Guid.Empty) {
+              service.Obj.DeleteHiveExperiment(item.Value.HiveExperimentId);
+            }
+          }
+        }
+      }
+    }
+
+    public event EventHandler IsProgressingChanged;
+    private void OnIsProgressingChanged() {
+      var handler = IsProgressingChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+  }
+}
Index: /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql
===================================================================
--- /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql	(revision 4768)
+++ /branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.LINQDataAccess/3.3/Scripts/prepareHiveDatabase.sql	(revision 4769)
@@ -1,3 +1,5 @@
 /* this script is supposed to be executed after the plain DB is generated by the linq-to-sql schema */
+USE [HeuristicLab.Hive]
+GO
 
 /*
@@ -32,4 +34,16 @@
 ALTER TABLE dbo.AssignedResources ALTER COLUMN AssignedRessourcesId ADD ROWGUIDCOL;
 ALTER TABLE dbo.AssignedResources WITH NOCHECK ADD CONSTRAINT [DF_AssignedResources_AssignedRessourcesId] DEFAULT (newid()) FOR AssignedRessourcesId;
+ALTER TABLE [dbo].[AssignedResources]  DROP  CONSTRAINT [Job_AssignedResource]
+ALTER TABLE [dbo].[AssignedResources]  WITH CHECK ADD  CONSTRAINT [Job_AssignedResource] FOREIGN KEY([JobId])
+REFERENCES [dbo].[Job] ([JobId])
+ON UPDATE CASCADE
+ON DELETE CASCADE
+GO
+ALTER TABLE [dbo].[AssignedResources]  DROP  CONSTRAINT [Resource_AssignedResource]
+ALTER TABLE [dbo].[AssignedResources]  WITH CHECK ADD  CONSTRAINT [Resource_AssignedResource] FOREIGN KEY([ResourceId])
+REFERENCES [dbo].[Resource] ([ResourceId])
+ON UPDATE CASCADE
+ON DELETE CASCADE
+GO
 
 ALTER TABLE dbo.Job ALTER COLUMN JobId ADD ROWGUIDCOL;
@@ -51,4 +65,18 @@
 ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (newid()) FOR RequiredPluginId;
 
+ALTER TABLE [dbo].[RequiredPlugins]  DROP  CONSTRAINT [Job_RequiredPlugin]
+ALTER TABLE [dbo].[RequiredPlugins]  WITH CHECK ADD  CONSTRAINT [Job_RequiredPlugin] FOREIGN KEY([JobId])
+REFERENCES [dbo].[Job] ([JobId])
+ON UPDATE CASCADE
+ON DELETE CASCADE
+GO
+
+ALTER TABLE [dbo].[RequiredPlugins]  DROP  CONSTRAINT [PluginInfo_RequiredPlugin]
+ALTER TABLE [dbo].[RequiredPlugins]  WITH CHECK ADD  CONSTRAINT [PluginInfo_RequiredPlugin] FOREIGN KEY([PluginId])
+REFERENCES [dbo].[PluginInfo] ([PluginId])
+ON UPDATE CASCADE
+ON DELETE CASCADE
+GO
+
 ALTER TABLE dbo.Resource ALTER COLUMN ResourceId ADD ROWGUIDCOL;
 ALTER TABLE dbo.Resource WITH NOCHECK ADD CONSTRAINT [DF_Resource_ResourceId] DEFAULT (newid()) FOR ResourceId;
@@ -65,2 +93,51 @@
 /* create indices */
 CREATE INDEX Index_RequiredPlugins_JobId ON RequiredPlugins(JobId);
+
+/* triggers */
+SET ANSI_NULLS ON
+GO
+SET QUOTED_IDENTIFIER ON
+GO
+-- =============================================
+-- Author:		cneumuel
+-- Create date: 11.11.2010
+-- Description:	Deletes the root-job of the experiment when experiment is deleted
+-- =============================================
+CREATE TRIGGER [dbo].[tr_HiveExperimentDeleteCascade] ON [dbo].[HiveExperiment] FOR DELETE AS 
+SET NOCOUNT ON
+DELETE Job FROM deleted, Job WHERE Job.JobId = deleted.RootJobId
+GO
+
+SET ANSI_NULLS ON
+GO
+SET QUOTED_IDENTIFIER ON
+GO
+-- =============================================
+-- Author:		cneumuel
+-- Create date: 11.11.2010
+-- 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/)
+-- =============================================
+CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS 
+BEGIN
+	CREATE TABLE #Table( 
+		JobId uniqueidentifier 
+	)
+	INSERT INTO #Table (JobId)
+	SELECT JobId FROM deleted
+	
+	DECLARE @c INT
+	SET @c = 0
+	
+	WHILE @c <> (SELECT COUNT(JobId) FROM #Table) BEGIN
+		SELECT @c = COUNT(JobId) FROM #Table
+		
+		INSERT INTO #Table (JobId)
+			SELECT Job.JobId
+			FROM Job
+			LEFT OUTER JOIN #Table ON Job.JobId = #Table.JobId
+			WHERE Job.ParentJobId IN (SELECT JobId FROM #Table)
+				AND #Table.JobId IS NULL
+	END
+	
+	DELETE Job FROM Job INNER JOIN #Table ON Job.JobId = #Table.JobId
+END
