Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Agent.cs
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Agent.cs	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Agent.cs	(revision 1307)
@@ -0,0 +1,36 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Linq.Mapping;
+using HeuristicLab.CEDMA.DB.Interfaces;
+
+namespace HeuristicLab.CEDMA.DB {
+  [Table(Name = "AgentTable")]
+  class Agent : IAgent {
+    [Column(IsPrimaryKey = true)]
+    public int ID;
+    [Column]
+    public string Name;
+    [Column]
+    public AgentStatus Status;
+    [Column]
+    public byte[] RawData;
+
+    string IAgent.Name {
+      get { return this.Name; }
+    }
+
+    AgentStatus IAgent.Status {
+      get { return this.Status; }
+    }
+
+    byte[] IAgent.RawData {
+      get { return this.RawData; }
+    }
+
+    public void Save() {
+      throw new NotImplementedException();
+    }
+  }
+}
Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Database.cs
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Database.cs	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Database.cs	(revision 1307)
@@ -0,0 +1,622 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 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.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Linq;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using System.ServiceModel;
+using System.Data;
+using System.Data.SQLite;
+using System.Data.Common;
+using System.Threading;
+
+namespace HeuristicLab.CEDMA.DB {
+  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
+  public class Database : IDatabase {
+    private string connectionString;
+    private ReaderWriterLockSlim rwLock;
+    public Database(string connectionString) {
+      this.connectionString = connectionString;
+      rwLock = new ReaderWriterLockSlim();
+    }
+
+    #region create empty database
+    public void CreateNew() {
+      rwLock.EnterWriteLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationTime DateTime)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, ParentAgentId integer, Name text, Status text default " + ProcessStatus.Unknown + ", CreationTime DateTime, RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, Summary text, Description text, CreationTime DateTime, RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            using(DbCommand cmd = cnn.CreateCommand()) {
+              cmd.CommandText = "CREATE TABLE Operator (ID integer primary key autoincrement, Name text, RawData Blob)";
+              cmd.Transaction = t;
+              cmd.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+    #endregion
+
+    #region insert agent/result/sub-result
+    public long InsertAgent(long? parentAgentId, string name, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Agent (Name, ParentAgentId, CreationTime, RawData) values (@Name, @ParentAgentId, @CreationTime, @RawData); select last_insert_rowid()";
+              DbParameter nameParam = c.CreateParameter();
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              c.Parameters.Add(nameParam);
+              DbParameter parentParam = c.CreateParameter();
+              parentParam.ParameterName = "@ParentAgentId";
+              parentParam.Value = parentAgentId;
+              c.Parameters.Add(parentParam);
+              DbParameter creationTimeParam = c.CreateParameter();
+              creationTimeParam.ParameterName = "@CreationTime";
+              creationTimeParam.Value = DateTime.Now;
+              c.Parameters.Add(creationTimeParam);
+              DbParameter dataParam = c.CreateParameter();
+              dataParam.ParameterName = "@RawData";
+              dataParam.Value = rawData;
+              c.Parameters.Add(dataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public long InsertResult(long agentId, string summary, string description, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Result (AgentId, CreationTime, Summary, Description, RawData) values (@AgentId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
+              DbParameter agentIdParam = c.CreateParameter();
+              agentIdParam.ParameterName = "@AgentId";
+              agentIdParam.Value = agentId;
+              c.Parameters.Add(agentIdParam);
+              DbParameter creationParam = c.CreateParameter();
+              creationParam.ParameterName = "@CreationTime";
+              DateTime now = DateTime.Now;
+              creationParam.Value = now;
+              c.Parameters.Add(creationParam);
+              DbParameter summaryParam = c.CreateParameter();
+              summaryParam.ParameterName = "@Summary";
+              summaryParam.Value = summary;
+              c.Parameters.Add(summaryParam);
+              DbParameter descParam = c.CreateParameter();
+              descParam.ParameterName = "@Description";
+              descParam.Value = description;
+              c.Parameters.Add(descParam);
+              DbParameter rawDataParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              c.Parameters.Add(rawDataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public long InsertSubResult(long resultId, string summary, string description, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Result (ParentResultId, CreationTime, Summary, Description, RawData) values (@ParentResultId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
+              DbParameter resultIdParam = c.CreateParameter();
+              resultIdParam.ParameterName = "@ParentResultId";
+              resultIdParam.Value = resultId;
+              c.Parameters.Add(resultIdParam);
+              DbParameter creationParam = c.CreateParameter();
+              creationParam.ParameterName = "@CreationTime";
+              DateTime now = DateTime.Now;
+              creationParam.Value = now;
+              c.Parameters.Add(creationParam);
+              DbParameter summaryParam = c.CreateParameter();
+              summaryParam.ParameterName = "@Summary";
+              summaryParam.Value = summary;
+              c.Parameters.Add(summaryParam);
+              DbParameter descParam = c.CreateParameter();
+              descParam.ParameterName = "@Description";
+              descParam.Value = description;
+              c.Parameters.Add(descParam);
+              DbParameter rawDataParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              c.Parameters.Add(rawDataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public long InsertOperator(string name, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          long id;
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Insert into Operator (Name, RawData) values (@Name, @RawData); select last_insert_rowid()";
+              DbParameter nameParam = c.CreateParameter();
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              c.Parameters.Add(nameParam);
+              DbParameter dataParam = c.CreateParameter();
+              dataParam.ParameterName = "@RawData";
+              dataParam.Value = rawData;
+              c.Parameters.Add(dataParam);
+              id = (long)c.ExecuteScalar();
+            }
+            t.Commit();
+            return id;
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+    #endregion
+
+    #region update agent, run, operator
+    public void UpdateAgent(long id, string name) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set Name=@Name where id=@Id";
+              DbParameter nameParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(nameParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public void UpdateAgent(long id, ProcessStatus status) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set Status=@Status where id=@Id";
+              DbParameter statusParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              statusParam.ParameterName = "@Status";
+              statusParam.Value = status.ToString();
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(statusParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public void UpdateAgent(long id, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Agent set RawData=@RawData where id=@Id";
+              DbParameter rawDataParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(rawDataParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    public void UpdateOperator(long id, string name, byte[] rawData) {
+      rwLock.EnterWriteLock();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(SQLiteTransaction t = cnn.BeginTransaction()) {
+            using(SQLiteCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Update Operator set Name=@Name, RawData=@RawData where id=@Id";
+              DbParameter rawDataParam = c.CreateParameter();
+              DbParameter nameParam = c.CreateParameter();
+              DbParameter idParam = c.CreateParameter();
+              rawDataParam.ParameterName = "@RawData";
+              rawDataParam.Value = rawData;
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              nameParam.ParameterName = "@Name";
+              nameParam.Value = name;
+              c.Parameters.Add(rawDataParam);
+              c.Parameters.Add(nameParam);
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+
+    #endregion
+
+    #region get agent/result/sub-result/operator
+
+    public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
+      rwLock.EnterReadLock();
+      List<AgentEntry> agents = new List<AgentEntry>();
+      try {
+        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          SQLiteCommand c = cnn.CreateCommand();
+          c.CommandText = "Select id, name from Agent where Status=@Status";
+          DbParameter statusParameter = c.CreateParameter();
+          statusParameter.ParameterName = "@Status";
+          statusParameter.Value = status.ToString();
+          c.Parameters.Add(statusParameter);
+          SQLiteDataReader r = c.ExecuteReader();
+          while(r.Read()) {
+            AgentEntry agent = new AgentEntry();
+            agent.ParentAgentId = null;
+            agent.Status = status;
+            agent.Id = r.GetInt32(0);
+            agent.Name = r.IsDBNull(1) ? "" : r.GetString(1);
+            agents.Add(agent);
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return agents;
+    }
+
+    public ICollection<AgentEntry> GetAgents() {
+      rwLock.EnterReadLock();
+      List<AgentEntry> agents = new List<AgentEntry>();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select id, name, status from Agent where ParentAgentId isnull";
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                AgentEntry agent = new AgentEntry();
+                agent.ParentAgentId = null;
+                agent.Id = r.GetInt32(0);
+                agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
+                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
+                agents.Add(agent);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return agents;
+    }
+
+    public ICollection<AgentEntry> GetSubAgents(long parentAgentId) {
+      rwLock.EnterReadLock();
+      List<AgentEntry> agents = new List<AgentEntry>();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select id, name, status from Agent where ParentAgentId=@ParentAgentId";
+            DbParameter parentParameter = c.CreateParameter();
+            parentParameter.ParameterName = "@ParentAgentId";
+            parentParameter.Value = parentAgentId;
+            c.Parameters.Add(parentParameter);
+
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                AgentEntry agent = new AgentEntry();
+                agent.ParentAgentId = parentAgentId;
+                agent.Id = r.GetInt32(0);
+                agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
+                agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
+                agents.Add(agent);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return agents;
+    }
+
+    public byte[] GetAgentRawData(long id) {
+      rwLock.EnterReadLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select RawData from Agent where Id=@Id";
+            DbParameter idParameter = c.CreateParameter();
+            idParameter.ParameterName = "@Id";
+            idParameter.Value = id;
+            c.Parameters.Add(idParameter);
+            using(DbDataReader r = c.ExecuteReader()) {
+              if(r.HasRows) {
+                r.Read();
+                return (byte[])r.GetValue(0);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return null; // agent with the given id not found
+    }
+
+    public ICollection<ResultEntry> GetResults(long agentId) {
+      List<ResultEntry> results = new List<ResultEntry>();
+      rwLock.EnterReadLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select Id, CreationTime, Summary, Description from Result where AgentId=@AgentId";
+            DbParameter agentParam = c.CreateParameter();
+            agentParam.ParameterName = "@AgentId";
+            agentParam.Value = agentId;
+            c.Parameters.Add(agentParam);
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                ResultEntry result = new ResultEntry();
+                result.AgentId = agentId;
+                result.Id = r.GetInt32(0);
+                result.CreationTime = r.GetDateTime(1);
+                result.Summary = r.GetString(2);
+                result.Description = r.GetString(3);
+                results.Add(result);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return results;
+    }
+
+    public ICollection<ResultEntry> GetSubResults(long resultId) {
+      List<ResultEntry> results = new List<ResultEntry>();
+      rwLock.EnterReadLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select Id, CreationTime, Summary, Description from Result where ParentResultId=@ParentResultId";
+            DbParameter parentParam = c.CreateParameter();
+            parentParam.ParameterName = "@ParentResultId";
+            parentParam.Value = resultId;
+            c.Parameters.Add(parentParam);
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                ResultEntry result = new ResultEntry();
+                result.ParentResultId = resultId;
+                result.Id = r.GetInt32(0);
+                result.CreationTime = r.GetDateTime(1);
+                result.Summary = r.GetString(2);
+                result.Description = r.GetString(3);
+                results.Add(result);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return results;
+    }
+
+    public byte[] GetResultRawData(long id) {
+      rwLock.EnterReadLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select RawData from Result where Id=@Id";
+            DbParameter idParameter = c.CreateParameter();
+            idParameter.ParameterName = "@Id";
+            idParameter.Value = id;
+            c.Parameters.Add(idParameter);
+            using(DbDataReader r = c.ExecuteReader()) {
+              if(r.HasRows) {
+                r.Read();
+                return (byte[])r.GetValue(0);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return null; // result with the given id not found
+    }
+
+    public ICollection<OperatorEntry> GetOperators() {
+      rwLock.EnterReadLock();
+      List<OperatorEntry> operators = new List<OperatorEntry>();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select id, name, rawdata from Operator";
+            using(DbDataReader r = c.ExecuteReader()) {
+              while(r.Read()) {
+                OperatorEntry op = new OperatorEntry();
+                op.Id = r.GetInt32(0);
+                op.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
+                op.RawData = (byte[])r.GetValue(2);
+                operators.Add(op);
+              }
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+      return operators;
+    }
+    public OperatorEntry GetOperator(long id) {
+      rwLock.EnterReadLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbCommand c = cnn.CreateCommand()) {
+            c.CommandText = "Select id, name, rawdata from Operator where id=@Id";
+            DbParameter idParam = c.CreateParameter();
+            idParam.ParameterName = "@Id";
+            idParam.Value = id;
+            c.Parameters.Add(idParam);
+            using(DbDataReader r = c.ExecuteReader()) {
+              r.Read();
+              OperatorEntry op = new OperatorEntry();
+              op.Id = r.GetInt32(0);
+              op.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
+              op.RawData = (byte[])r.GetValue(2);
+              return op;
+            }
+          }
+        }
+      } finally {
+        rwLock.ExitReadLock();
+      }
+    }
+    #endregion
+
+    #region delete operator
+    public void DeleteOperator(long id) {
+      rwLock.EnterWriteLock();
+      try {
+        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
+          cnn.Open();
+          using(DbTransaction t = cnn.BeginTransaction()) {
+            using(DbCommand c = cnn.CreateCommand()) {
+              c.Transaction = t;
+              c.CommandText = "Delete from Operator where id=@Id";
+              DbParameter idParam = c.CreateParameter();
+              idParam.ParameterName = "@Id";
+              idParam.Value = id;
+              c.Parameters.Add(idParam);
+              c.ExecuteNonQuery();
+            }
+            t.Commit();
+          }
+        }
+      } finally {
+        rwLock.ExitWriteLock();
+      }
+    }
+    #endregion
+  }
+}
Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLab.CEDMA.DB.csproj
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLab.CEDMA.DB.csproj	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLab.CEDMA.DB.csproj	(revision 1307)
@@ -0,0 +1,123 @@
+﻿<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{B3D6D8D9-2B1F-47EC-9C73-77FAECF87310}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HeuristicLab.CEDMA.DB</RootNamespace>
+    <AssemblyName>HeuristicLab.CEDMA.DB-3.2</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SignAssembly>false</SignAssembly>
+    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
+    <StartupObject>
+    </StartupObject>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="SemWeb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
+    <Reference Include="SemWeb.SqliteStore, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.ServiceModel">
+      <RequiredTargetFramework>3.0</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Store.cs" />
+    <Compile Include="HeuristicLabCedmaDbPlugin.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="HeuristicLab.snk" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\HeuristicLab.CEDMA.DB.Interfaces\HeuristicLab.CEDMA.DB.Interfaces.csproj">
+      <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>
+      <Name>HeuristicLab.CEDMA.DB.Interfaces</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
+      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
+      <Name>HeuristicLab.Core</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj">
+      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
+      <Name>HeuristicLab.Data</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
+      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
+      <Name>HeuristicLab.PluginInfrastructure</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="SemWeb.dll">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+    <Content Include="SemWeb.SqliteStore.dll" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+  <PropertyGroup>
+    <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+
+call PreBuildEvent.cmd</PreBuildEvent>
+  </PropertyGroup>
+</Project>
Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLabCedmaDbPlugin.cs
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLabCedmaDbPlugin.cs	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/HeuristicLabCedmaDbPlugin.cs	(revision 1307)
@@ -0,0 +1,33 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 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.Collections.Generic;
+using System.Text;
+using HeuristicLab.PluginInfrastructure;
+
+namespace HeuristicLab.CEDMA.DB {
+  [ClassInfo(Name = "HeuristicLab.CEDMA.DB-3.2")]
+  [PluginFile(Filename = "HeuristicLab.CEDMA.DB-3.2.dll", Filetype = PluginFileType.Assembly)]
+  [Dependency(Dependency = "HeuristicLab.CEDMA.DB.Interfaces-3.2")]
+  public class HeuristicLabCedmaDbPlugin : PluginBase {
+  }
+}
Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Properties/AssemblyInfo.frame
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Properties/AssemblyInfo.frame	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Properties/AssemblyInfo.frame	(revision 1307)
@@ -0,0 +1,38 @@
+﻿using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using HeuristicLab.PluginInfrastructure;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("HeuristicLab.CEDMA.DB")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HeuristicLab")]
+[assembly: AssemblyCopyright("(c) 2002-2008 HEAL")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("58cd6e79-3f9b-4307-944e-b858e8957bbf")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("3.2.0.$WCREV$")]
+[assembly: AssemblyFileVersion("3.2.0.$WCREV$")]
+[assembly: AssemblyBuildDate("$WCNOW$")]
Index: /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Store.cs
===================================================================
--- /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Store.cs	(revision 1307)
+++ /branches/plugins/HeuristicLab.CEDMA.DB/3.2/Store.cs	(revision 1307)
@@ -0,0 +1,226 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 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.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Linq;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using System.ServiceModel;
+using System.Data;
+using System.Data.Common;
+using System.Threading;
+using HeuristicLab.Data;
+using HeuristicLab.Core;
+using System.Xml;
+using System.IO;
+
+namespace HeuristicLab.CEDMA.DB {
+  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
+  public class Store : IStore {
+    private string connectionString;
+    private SemWeb.Store store;
+    private object bigLock = new object();
+    public Store(string connectionString) {
+      lock (bigLock) {
+        this.connectionString = connectionString;
+        store = SemWeb.Store.Create(connectionString);
+        InitStore();
+      }
+    }
+
+    private void InitStore() {
+      foreach (Statement s in Ontology.InitialStatements) {
+        Add(s);
+      }
+    }
+
+    public void Add(Statement statement) {
+      lock (bigLock) {
+        store.Add(Translate(statement));
+      }
+    }
+
+
+    public ICollection<VariableBindings> Query(string query) {
+      MyQueryResultSink resultSink = new MyQueryResultSink();
+      SemWeb.N3Reader n3Reader = new SemWeb.N3Reader(new StringReader(query));
+      SemWeb.Query.GraphMatch matcher = new SemWeb.Query.GraphMatch(n3Reader);
+      matcher.Run(store, resultSink);
+      return resultSink.Bindings;
+    }
+
+    public ICollection<VariableBindings> Query(ICollection<Statement> query) {
+      MyQueryResultSink resultSink = new MyQueryResultSink();
+      Translate(query).Run(store, resultSink);
+      return resultSink.Bindings;
+    }
+
+    private SemWeb.Query.Query Translate(ICollection<Statement> query) {
+      Dictionary<object, object> translatedObjects = new Dictionary<object, object>();
+      SemWeb.MemoryStore queryStore = new SemWeb.MemoryStore(query.Select(st => Translate(st, translatedObjects)).ToArray());
+
+      return new SemWeb.Query.GraphMatch(queryStore);
+    }
+
+
+    //public ICollection<Statement> Select(Statement template) {
+    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
+    //  lock (bigLock) {
+    //    store.Select(Translate(template), memStore);
+    //  }
+    //  return memStore.Select(x=>Translate(x)).ToList();
+    //}
+
+    //public ICollection<Statement> Select(SelectFilter filter) {
+    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
+    //  lock (bigLock) {
+    //    store.Select(Translate(filter), memStore);
+    //  }
+    //  return memStore.Select(x => Translate(x)).ToList();
+    //}
+
+    //private SemWeb.SelectFilter Translate(SelectFilter filter) {
+    //  SemWeb.SelectFilter f = new SemWeb.SelectFilter();
+    //  f.Subjects = Array.ConvertAll(filter.Subjects, s => Translate(s));
+    //  f.Predicates = Array.ConvertAll(filter.Predicates, p => Translate(p));
+    //  f.Objects = Array.ConvertAll(filter.Properties, prop => Translate(prop));
+    //  return f;
+    //}
+
+    private static SemWeb.Entity Translate(Entity e) {
+      return e.Uri == null ? null : new SemWeb.Entity(e.Uri);
+    }
+
+    private static SemWeb.Resource Translate(Resource prop) {
+      if (prop is Literal) {
+        return TranslateLiteral((Literal)prop);
+      } else if (prop is SerializedLiteral) {
+        return TranslateLiteral((SerializedLiteral)prop);
+      } else {
+        return Translate((Entity)prop);
+      }
+    }
+
+    private static Statement Translate(SemWeb.Statement statement) {
+      return Translate(statement, new Dictionary<object, object>());
+    }
+
+    private static Statement Translate(SemWeb.Statement statement, Dictionary<object, object> translatedObjects) {
+      if (!translatedObjects.ContainsKey(statement.Subject)) {
+        translatedObjects[statement.Subject] = new Entity(statement.Subject.Uri);
+      }
+      if (!translatedObjects.ContainsKey(statement.Predicate)) {
+        translatedObjects[statement.Predicate] = new Entity(statement.Predicate.Uri);
+      }
+      if (!translatedObjects.ContainsKey(statement.Object)) {
+        if (statement.Object is SemWeb.Literal) {
+          translatedObjects[statement.Object] = TranslateLiteral((SemWeb.Literal)statement.Object);
+        } else {
+          translatedObjects[statement.Object] = new Entity(((SemWeb.Entity)statement.Object).Uri);
+        }
+      }
+
+      Entity subjectEntity = (Entity)translatedObjects[statement.Subject];
+      Entity predicateEntity = (Entity)translatedObjects[statement.Predicate];
+      Resource property = (Resource)translatedObjects[statement.Object];
+
+      return new Statement(
+        subjectEntity,
+        predicateEntity,
+        property);
+    }
+
+    private static SemWeb.Statement Translate(Statement statement) {
+      return Translate(statement, new Dictionary<object, object>());
+    }
+
+    private static SemWeb.Statement Translate(Statement statement, Dictionary<object, object> translatedObjects) {
+      if (!translatedObjects.ContainsKey(statement.Subject)) {
+        translatedObjects[statement.Subject] = Translate(statement.Subject);
+      }
+      if (!translatedObjects.ContainsKey(statement.Predicate)) {
+        translatedObjects[statement.Predicate] = Translate(statement.Predicate);
+      }
+      if (!translatedObjects.ContainsKey(statement.Property)) {
+        translatedObjects[statement.Property] = Translate(statement.Property);
+      }
+
+      SemWeb.Entity subject = (SemWeb.Entity)translatedObjects[statement.Subject];
+      SemWeb.Entity predicate = (SemWeb.Entity)translatedObjects[statement.Predicate];
+      SemWeb.Resource property = (SemWeb.Resource)translatedObjects[statement.Property];
+
+      return new SemWeb.Statement(
+        subject,
+        predicate,
+        property);
+    }
+
+    private static SemWeb.Literal TranslateLiteral(SerializedLiteral l) {
+      if (l.RawData == null) return null;
+      return new SemWeb.Literal(l.RawData, null, "serializedItem");
+    }
+
+    private static SemWeb.Literal TranslateLiteral(Literal l) {
+      if (l.Value == null) return null;
+      if (l.Value is double) return SemWeb.Literal.FromValue((double)l.Value);
+      else if (l.Value is bool) return SemWeb.Literal.FromValue((bool)l.Value);
+      else if (l.Value is int) return SemWeb.Literal.FromValue((int)l.Value);
+      else if (l.Value is long) return SemWeb.Literal.FromValue((long)l.Value);
+      else if (l.Value is string) return SemWeb.Literal.FromValue((string)l.Value);
+      else return new SemWeb.Literal(l.Value.ToString());
+    }
+
+    private static Resource TranslateLiteral(SemWeb.Literal l) {
+      if (l.DataType == "serializedItem") {
+        return new SerializedLiteral(l.Value);
+      } else if (l.DataType != null) {
+        return new Literal(l.ParseValue());
+      } else {
+        return new Literal(l.Value);
+      }
+    }
+
+    private class MyQueryResultSink : SemWeb.Query.QueryResultSink {
+
+      private List<VariableBindings> bindings = new List<VariableBindings>();
+      public ICollection<VariableBindings> Bindings {
+        get { return bindings.AsReadOnly(); }
+      }
+
+      public override bool Add(SemWeb.Query.VariableBindings result) {
+        VariableBindings varBindings = new VariableBindings();
+        foreach (SemWeb.Variable var in result.Variables) {
+          if (var.LocalName != null && result[var] != null) {
+            if (result[var] is SemWeb.Literal) {
+              varBindings.Add(var.LocalName, TranslateLiteral((SemWeb.Literal)result[var]));
+            } else {
+              varBindings.Add(var.LocalName, new Entity(((SemWeb.Entity)result[var]).Uri));
+            }
+          }
+          bindings.Add(varBindings);
+        }
+        return true;
+      }
+    }
+  }
+}
