diff --git a/lib/modeljoin.jar b/lib/modeljoin.jar
index 7dd9eed4acaada106ddb92d3b771163185721b73..f8f8f1c984bdb976963788009f4efb26734c4e40 100644
Binary files a/lib/modeljoin.jar and b/lib/modeljoin.jar differ
diff --git a/src/main/java/org/rosi_project/model_management/util/query/ModelJoinCreator.java b/src/main/java/org/rosi_project/model_management/util/query/ModelJoinCreator.java
index 16881a09afc8c98dd37eaf3b35f14696be758ec0..9a6f68855970be59da7b72fc708b661b165f1ba5 100644
--- a/src/main/java/org/rosi_project/model_management/util/query/ModelJoinCreator.java
+++ b/src/main/java/org/rosi_project/model_management/util/query/ModelJoinCreator.java
@@ -14,6 +14,8 @@ import java.io.File;
 import org.rosi_project.model_sync.model_join.representation.core.AttributePath;
 import org.rosi_project.model_sync.model_join.representation.core.ClassResource;
 import org.rosi_project.model_sync.model_join.representation.grammar.CompoundKeepBuilder;
+import org.rosi_project.model_sync.model_join.representation.grammar.CompoundKeepExpression;
+import org.rosi_project.model_sync.model_join.representation.grammar.JoinExpression;
 import org.rosi_project.model_sync.model_join.representation.grammar.KeepExpression;
 import org.rosi_project.model_sync.model_join.representation.grammar.ModelJoinExpression;
 import org.rosi_project.model_sync.model_join.representation.util.JoinFactory.AbstractJoinBuilder;
@@ -22,28 +24,23 @@ import org.rosi_project.model_sync.model_join.representation.writer.FileBasedMod
 
 public class ModelJoinCreator {
 
-	private AbstractJoinBuilder ajb = null;
-
 	public AbstractJoinBuilder createNaturalJoin(String start) {
 		ClassResource classRessource = ClassResource.fromQualifiedName(start);
-		ajb = naturalJoin().join(classRessource).with(classRessource).as(classRessource);
-		return ajb;
+		return naturalJoin().join(classRessource).with(classRessource).as(classRessource);
 	}
 
 	public AbstractJoinBuilder createThetaJoin(String start, String condition) {
 		ClassResource classRessource = ClassResource.fromQualifiedName(start);
-		ajb = thetaJoin().where(condition).join(classRessource).with(classRessource).as(classRessource);
-		return ajb;
+		return thetaJoin().where(condition).join(classRessource).with(classRessource).as(classRessource);
 	}
 
 	public AbstractJoinBuilder createOuterJoin(String start, boolean left) {
 		ClassResource classRessource = ClassResource.fromQualifiedName(start);
 		if (left) {
-			ajb = outerJoin().leftOuter().join(classRessource).with(classRessource).as(classRessource);
+			return outerJoin().leftOuter().join(classRessource).with(classRessource).as(classRessource);
 		} else {
-			ajb = outerJoin().rightOuter().join(classRessource).with(classRessource).as(classRessource);
+			return outerJoin().rightOuter().join(classRessource).with(classRessource).as(classRessource);
 		}
-		return ajb;
 	}
 
 	public void createAttribute(Object o, String ressourceName, String attrName) {
@@ -58,16 +55,18 @@ public class ModelJoinCreator {
 		}
 	}
 
-	public CompoundKeepBuilder createOutgoingReference(String ressourceName, String attrName) {
-		ClassResource classRessource = ClassResource.fromQualifiedName(ressourceName);
-		AttributePath attrPath = AttributePath.from(classRessource, attrName);
-		return outgoing(attrPath).as(classRessource);
+	public CompoundKeepBuilder createOutgoingReference(String fromRessource, String toRessource, String attrName) {
+		ClassResource toClassRes = ClassResource.fromQualifiedName(toRessource);
+		ClassResource fromClassRes = ClassResource.fromQualifiedName(fromRessource);
+		AttributePath attrPath = AttributePath.from(fromClassRes, attrName);
+		return outgoing(attrPath).as(toClassRes);
 	}
 
-	public CompoundKeepBuilder createIncomingReference(String ressourceName, String attrName) {
-		ClassResource classRessource = ClassResource.fromQualifiedName(ressourceName);
-		AttributePath attrPath = AttributePath.from(classRessource, attrName);
-		return incoming(attrPath).as(classRessource);
+	public CompoundKeepBuilder createIncomingReference(String fromRessource, String toRessource, String attrName) {
+		ClassResource toClassRes = ClassResource.fromQualifiedName(toRessource);
+		ClassResource fromClassRes = ClassResource.fromQualifiedName(fromRessource);
+		AttributePath attrPath = AttributePath.from(fromClassRes, attrName);
+		return incoming(attrPath).as(toClassRes);
 	}
 
 	public CompoundKeepBuilder createSubType(String ressourceName) {
@@ -79,10 +78,60 @@ public class ModelJoinCreator {
 		ClassResource classRessource = ClassResource.fromQualifiedName(ressourceName);
 		return supertype(classRessource).as(classRessource);
 	}
+	
+	public void addKeepExpression(Object o, KeepExpression ke) {
+		if (o instanceof AbstractJoinBuilder) {
+			((AbstractJoinBuilder) o).keep(ke);
+		}
+		if (o instanceof CompoundKeepBuilder) {
+			((CompoundKeepBuilder) o).keep(ke);
+		}
+	}
+	
+	public KeepExpression buildExpression(Object o) {
+		if (o instanceof CompoundKeepBuilder) {
+			return ((CompoundKeepBuilder) o).buildExpression();
+		}
+		return null;
+	}
+	
+	public JoinExpression done(Object o) {
+		if (o instanceof AbstractJoinBuilder) {
+			return ((AbstractJoinBuilder) o).done();
+		}
+		return null;
+	}
+	
+	public Object combine(Object current, Object added) {
+		JoinExpression realAdded = (JoinExpression)added;
+		if (current instanceof JoinExpression) {
+			JoinExpression realCurrent = (JoinExpression)current;
+			System.out.println("ClassName: " + realCurrent.getBaseModel().toString());
+			AbstractJoinBuilder ajb = createNaturalJoin(realCurrent.getBaseModel().toString());
+			for (KeepExpression ke : realCurrent.getKeepsList()) {
+				ajb.keep(ke);
+			}
+			for (KeepExpression ke : realAdded.getKeepsList()) {
+				ajb.keep(ke);
+			}
+			return ajb.done();
+		}
+		if (current instanceof CompoundKeepExpression) { //createOutgoingReference(String ressourceName, String attrName)
+			CompoundKeepExpression realCurrent = (CompoundKeepExpression)current;
+			for (KeepExpression ke : realAdded.getKeepsList()) {
+				if (!realCurrent.getKeeps().contains(ke)) {
+					realCurrent.addKeepExpression(ke);
+				}
+			}
+			return realCurrent;
+		}
+		return null;
+	}
 
-	public void createFile(String fileName) {
-		if (ajb != null) {
-			ModelJoinExpression modelJoin = ModelJoinBuilder.createNewModelJoin().add(ajb.done()).build();
+	public void createFile(Object joinExpression, String fileName) {
+		if (joinExpression instanceof JoinExpression) {
+			JoinExpression je = (JoinExpression) joinExpression;
+			ModelJoinExpression modelJoin = ModelJoinBuilder.createNewModelJoin().add(je).build();
 
 			File file = new File(fileName);
 
diff --git a/src/main/scala/org/rosi_project/example/ExampleAml.scala b/src/main/scala/org/rosi_project/example/ExampleAml.scala
index e56258a7ba4c4bc24cd5af367c4071e7f24a88ee..38f54195086aaea05ef6b17539650725f9bf0305 100644
--- a/src/main/scala/org/rosi_project/example/ExampleAml.scala
+++ b/src/main/scala/org/rosi_project/example/ExampleAml.scala
@@ -45,8 +45,7 @@ object ExampleAml extends App {
   //ieStack1.addInternalElements(ieSensor2)
   
   //runAllQueries()
-  //runAllViewQueries()
-  query_3()
+  runAllViewQueries()
   
   def runAllViewQueries() {
     //Query testing
@@ -77,7 +76,7 @@ object ExampleAml extends App {
    */
   def query1(): Unit = {
     //Query Objects
-    val q1 = new Query("Q1")
+    val q1 = new RsumQuery("Q1")
     val co = new HelperCAEXObject("", "") //laufe über alle naturals im RSUM und suche, die die davon instanzen sind
     
     //Query Roles & Settings
@@ -90,7 +89,7 @@ object ExampleAml extends App {
   
   def query1Dot1(): Unit = {
     //Query Objects
-    val q11 = new Query("Q1.1")
+    val q11 = new RsumQuery("Q1.1")
     val suc = new SystemUnitClass("SUC", "13")
     
     //Query Roles & Settings
@@ -106,7 +105,7 @@ object ExampleAml extends App {
    */
   def query2(): Unit = {
     //Query Objects
-    val q2 = new Query("Q2")
+    val q2 = new RsumQuery("Q2")
     val ie = new InternalElement("", "")
     val att = new Attribute("50", "weigth", "")
     val ieRatt = new SystemUnitClassAttributesAttribute(ie, att)
@@ -130,7 +129,7 @@ object ExampleAml extends App {
    */
   def query3(): Unit = {
     //Query Objects
-    val q3 = new Query("Q3")
+    val q3 = new RsumQuery("Q3")
     val ih = new InstanceHierarchy("PPU","")
     val ie = new InternalElement("", "")
     val ihRie = new InstanceHierarchyInternalElementsInternalElement(ih, ie)
@@ -154,7 +153,7 @@ object ExampleAml extends App {
    */
   def query4(): Unit = {
     //Query Objects
-    val q4 = new Query("Q4")
+    val q4 = new RsumQuery("Q4")
     val ih = new InstanceHierarchy("PPU","") //wie kann ich auf die eigenschaften und werte prüfen
     val ie1 = new InternalElement("", "")
     val ie2 = new InternalElement("", "")
@@ -185,7 +184,7 @@ object ExampleAml extends App {
    */
   def query5(): Unit = {
     //Query Objects
-    val q5 = new Query("Q5")
+    val q5 = new RsumQuery("Q5")
     val ih = new InstanceHierarchy("PPU","") //wie kann ich auf die eigenschaften und werte prüfen
     val ie1 = new InternalElement("", "")
     val ie2 = new InternalElement("", "")
@@ -216,7 +215,7 @@ object ExampleAml extends App {
    */
   def query6(): Unit = {
     //Query Objects
-    val q6 = new Query("Q6")
+    val q6 = new RsumQuery("Q6")
     val ie1 = new InternalElement("", "")
     val ie2 = new InternalElement("", "")
     val ieRie = new SystemUnitClassInternalElementsInternalElement(ie1, ie2)
@@ -240,7 +239,7 @@ object ExampleAml extends App {
    */
   def query7(): Unit = {
     //Query Objects
-    val q7 = new Query("Q7")
+    val q7 = new RsumQuery("Q7")
     val suc = new SystemUnitClass("Stack", "")
     val ie = new InternalElement("", "")
     val ieRsuc = new  InternalElementBaseSystemUnitSystemUnitClass(ie, suc)
@@ -265,7 +264,7 @@ object ExampleAml extends App {
    */
   def query8(): Unit = {
     //Query Objects
-    val q8 = new Query("Q8")
+    val q8 = new RsumQuery("Q8")
     val ie1 = new InternalElement("", "")
     val ie2 = new InternalElement("", "")
     val ieRie = new SystemUnitClassInternalElementsInternalElement(ie1, ie2)
@@ -293,6 +292,8 @@ object ExampleAml extends App {
         
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query1")
   }
   
   def query_2(): Unit = {
@@ -312,6 +313,8 @@ object ExampleAml extends App {
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query2")
   }
   
   def query_3(): Unit = {
@@ -331,7 +334,7 @@ object ExampleAml extends App {
     println(q.getQuery())
     println(q.getQuery().runQuery())
     println("+++++++++++ MJ ++++++++++++++++++++++")
-    q.getQuery().generateModelJoinFromQuery()
+    q.getQuery().generateModelJoinFromQuery("Query3")
   }  
   
   def query_4(): Unit = {
@@ -353,6 +356,8 @@ object ExampleAml extends App {
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query4")
   }
   
   def query_5(): Unit = {
@@ -375,6 +380,8 @@ object ExampleAml extends App {
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query5")
   }
   
   def query_6(): Unit = {
@@ -391,6 +398,8 @@ object ExampleAml extends App {
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query6")
   }
   
   def query_7(): Unit = {
@@ -409,6 +418,8 @@ object ExampleAml extends App {
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query7")
   }
   
   def query_8(): Unit = {
@@ -422,9 +433,12 @@ object ExampleAml extends App {
     ie1.getQueryObject.label = "IE1"
     ie2.getQueryObject.label = "IE2"
     ie2.getQueryObject.multi = 3 //means >= 3
+    ie2.getQueryObject.returned = false
     
     println(q.getQuery())
     println(q.getQuery().runQuery())
+    println("+++++++++++ MJ ++++++++++++++++++++++")
+    q.getQuery().generateModelJoinFromQuery("Query8")
   }
   
 }
\ No newline at end of file
diff --git a/src/main/scala/org/rosi_project/model_management/sum/query/AQuery.scala b/src/main/scala/org/rosi_project/model_management/sum/query/AQuery.scala
deleted file mode 100644
index 165cebcc276f8257703526c8ca8fc5d54c367da4..0000000000000000000000000000000000000000
--- a/src/main/scala/org/rosi_project/model_management/sum/query/AQuery.scala
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.rosi_project.model_management.sum.query
-
-import scroll.internal.Compartment
-
-/**
- * Describes the abstract query compartment with the roles that each query must implement.
- */
-abstract class AQuery(val name: String) extends Compartment {
-  
-  def deleteQueryResults(): Unit
-  def deleteQueryObjects(): Unit
-  
-  /**
-   * Create ModelJoin syntax for views.
-   */
-  def generateModelJoinFromQuery(): String
-  
-  /**
-   * Add a query role to the underlying object.
-   */
-  def addQueryRole(obj: Object): AQuery#QueryObject
-  
-  /**
-   * Remove a query role from the query.
-   */
-  def removeQueryRole(role: AQuery#QueryObject): Unit
-  
-  /**
-   * Proof if the query has a correct form.
-   * Not more than one connection island.
-   */
-  def isQueryCorrect(): Boolean
-  
-  /**
-   * Running the query and getting a set of sets of result objects.
-   */
-  def runQuery(): Set[Set[Object]]
-  
-  /**
-   * Abstract query object to create the query from example.
-   */
-  abstract class QueryObject() {
-    
-    /**
-     * Label to identify a query object.
-     */
-    var label: String = ""
-    
-    /**
-     * Describes is necessary to be in the results or to be not.
-     */
-    var negated: Boolean = false
-    
-    /**
-     * Important to describe if a transitive closure should be created.
-     */
-    var transitive: Boolean = false
-    
-    /**
-     * Describes how often a connection must exists.
-     */
-    var multi: Int = 1
-    
-    /**
-     * Describes if the elements should be returned in the results or not.
-     */
-    var returned: Boolean = true
-    
-    private var attributeFilters: Set[AttributeFilter] = Set.empty
-      
-    /**
-  	 * Create and add an attribute filter object to a query object.
-   	 */        
-    def addAttributeFilter(attributeName: String, value: String, bigger: CheckingOption.Value): Boolean = {
-      if (attributeName == null || attributeName == "" ||
-        bigger == null || value == null || value == "") {
-        return false
-      }
-      attributeFilters += new AttributeFilter(attributeName, value, bigger)
-      return true
-    }
-    
-    def getAttributeFilters(): Set[AttributeFilter] = attributeFilters
-    
-    def overallConnectionUnit(): Int
-    
-    override def toString(): String = "QO: " + label
-  }  
-  
-  /**
-   * Abstract query results that each element which matches the query gets.
-   */
-  abstract class QueryResult(val matchedQueryObject: QueryObject) {
-    
-    override def toString(): String = "QR: (" + this.player.right.get.toString() + " " + matchedQueryObject + ")"
-  }
-  
-  /**
-   * Should collect information about the attributes a query element must have
-   */
-  class AttributeFilter(val attributeName: String, val value: String, val checking: CheckingOption.Value) {}
-}
\ No newline at end of file
diff --git a/src/main/scala/org/rosi_project/model_management/sum/query/ModelJoinContainer.scala b/src/main/scala/org/rosi_project/model_management/sum/query/ModelJoinContainer.scala
index a53ad57170d624c6c7596cb3de5a757734aab348..c0bcefdef5cc642d53ec9003fcb53f344bbbbb1e 100644
--- a/src/main/scala/org/rosi_project/model_management/sum/query/ModelJoinContainer.scala
+++ b/src/main/scala/org/rosi_project/model_management/sum/query/ModelJoinContainer.scala
@@ -1,5 +1,42 @@
 package org.rosi_project.model_management.sum.query
 
-class ModelJoinContainer(val name: String, val source: String, val target: String) {
+import org.rosi_project.model_management.util.query.ModelJoinCreator
+
+class ModelJoinContainer(val name: String, val source: String) {
+
+  var connect: Map[String, Object] = Map()
+
+  def isComparable(mjc: ModelJoinContainer): Boolean = {
+    var result = false
+    val size = mjc.connect.keySet.filter(connect.keySet.contains(_)).size
+    if (size == 1) {
+      val s = mjc.connect.keySet.filter(connect.keySet.contains(_)).head
+      if (s == source || s == mjc.source) {
+        result = true
+      }
+    }
+    result
+  }
+
+  /**
+   * Return the container that is not needed anymore.
+   */
+  def concat(mjc: ModelJoinContainer): ModelJoinContainer = {
+    val creator = new ModelJoinCreator
+    val s: String = mjc.connect.keySet.filter(connect.keySet.contains(_)).head
+    if (s == mjc.source) {
+      val res = creator.combine(connect.get(s).get, mjc.connect.get(s).get)
+      connect += (s -> res)
+      return mjc
+    } else {
+      val res = creator.combine(mjc.connect.get(s).get, connect.get(s).get)
+      mjc.connect += (s -> res)
+      return this
+    }
+  }
   
+  override def toString(): String = {
+    "MJC:" + " source=" + source + " name=" + name + " map=" + connect
+  }
+
 }
\ No newline at end of file
diff --git a/src/main/scala/org/rosi_project/model_management/sum/query/Query.scala b/src/main/scala/org/rosi_project/model_management/sum/query/Query.scala
index dbb13dfda29f19212701b034823bf10de8de5915..d50547dee4c2c9729852c9a93178d607b674bfb4 100644
--- a/src/main/scala/org/rosi_project/model_management/sum/query/Query.scala
+++ b/src/main/scala/org/rosi_project/model_management/sum/query/Query.scala
@@ -1,624 +1,102 @@
 package org.rosi_project.model_management.sum.query
 
 import scroll.internal.Compartment
-import org.rosi_project.model_management.core.RsumCompartment
-import org.rosi_project.model_management.sum.compartments.IRelationCompartment
-import org.rosi_project.model_management.sum.roles.IRelationRole
-import org.rosi_project.model_management.util.query.ModelJoinCreator
-import org.rosi_project.model_sync.model_join.representation.grammar.CompoundKeepBuilder
 
 /**
- * Special query implementation for the query interface that works on the RSUM.
+ * Describes the abstract query compartment with the roles that each query must implement.
  */
-class Query(_name: String) extends AQuery(_name) {
+abstract class Query(val name: String) extends Compartment {
   
-  RsumCompartment.combine(this)
+  def deleteQueryResults(): Unit
+  def deleteQueryObjects(): Unit
   
-  private var queryRelRoles: Set[QueryRelObject] = Set.empty
-  private var queryNatRoles: Set[QueryNatObject] = Set.empty
-  
-  private var queryRelResults: Set[QueryRelResult] = Set.empty
-  private var queryNatResults: Set[QueryNatResult] = Set.empty
-    
-  private def getQueryNatRole(obj: Object): QueryNatObject = {
-    //queryNatRoles.filter(+_ == +obj).foreach(return _)
-    queryNatRoles.foreach(q => {
-      if (+obj == +q) {
-        return q
-      }
-    })
-    return null
-  }
-    
-  private def getQueryRelRole(obj: Object): QueryRelObject = {
-    //queryRelRoles.filter(+_ == +obj).foreach(return _)
-    queryRelRoles.foreach(q => {
-      if (+obj == +q) {
-        return q
-      }
-    })
-    return null
-  }
-  
-  private def getNatResultRole(player: Object, queryObject: QueryNatObject): QueryNatResult = {
-    //queryNatResults.filter(r => r.connectedQueryObject == queryObject && +player == +r).foreach(return _)
-    queryNatResults.foreach(r => {
-      if (r.connectedQueryObject == queryObject && +player == +r) {
-        return r
-      }
-    })
-    return null
-  }
-  
-  def generateModelJoinFromQuery(): String = {
-    val creator = new ModelJoinCreator
-    /*val start = queryNatRoles.head
-    val playerStart: Object = start.player.right.get
-    playerStart.getClass.getPackage.getName
-    playerStart.getClass.getSimpleName*/
-    var relHelper: Set[ModelJoinContainer] = Set.empty
-    var relNames: Set[String] = Set.empty
-    var sources: Set[String] = Set.empty
-    var targets: Set[String] = Set.empty
-    
-    var names: Set[String] = Set.empty 
-    var connected: Map[String, Object] = Map()
-    
-    queryNatRoles.foreach(q => {
-      val playerStart: Object = q.player.right.get
-      println(playerStart.getClass.getName)
-      names += playerStart.getClass.getName      
-    })
-    queryRelRoles.foreach(q => {
-      val playerStart: Object = q.player.right.get
-      val playerSource: Object = q.source.player.right.get
-      val playerTarget: Object = q.target.player.right.get
-      println("+" + playerStart.getClass.getName)
-      println(playerSource.getClass.getName)
-      println(playerTarget.getClass.getName)
-      if (!relNames.contains(playerStart.getClass.getName)) {
-        relNames += playerStart.getClass.getName
-        sources += playerSource.getClass.getName
-        targets += playerTarget.getClass.getName
-        relHelper += new ModelJoinContainer(playerStart.getClass.getName, playerSource.getClass.getName, playerTarget.getClass.getName)
-        if (!connected.contains(playerSource.getClass.getName)) {
-          connected += (playerSource.getClass.getName -> creator.createNaturalJoin(playerSource.getClass.getName))
-        }
-        connected += (playerTarget.getClass.getName -> creator.createOutgoingReference(playerTarget.getClass.getName, playerStart.getClass.getSimpleName).asInstanceOf[Object])
-      }
-    })
-    
-    val start = sources.filter(!targets.contains(_)).head
-    val builder = creator.createNaturalJoin(start)
-    relHelper.filter(_.source == start).foreach(r => {
-      
-    })
-    ""
-  }
-  
-  def deleteQueryResults(): Unit = {
-    queryRelResults.foreach(_.remove())
-    queryRelResults = Set.empty
-    queryNatResults.foreach(_.remove())
-    queryNatResults = Set.empty
-  }  
-    
-  def deleteQueryObjects(): Unit = {
-    queryRelRoles.foreach(_.remove())
-    queryRelRoles = Set.empty
-    queryNatRoles.foreach(_.remove())
-    queryNatRoles = Set.empty
-  }
-  
-  def isQueryCorrect(): Boolean = {
-    //check if the query is correct and does not contain more close islands
-    queryRelRoles.foreach(qo => {
-      return qo.overallConnectionUnit() == (queryRelRoles.size + queryNatRoles.size)
-    })
-    queryNatRoles.foreach(qo => {
-      return qo.overallConnectionUnit() == (queryRelRoles.size + queryNatRoles.size)
-    })
-    return true
-  }
-  
-  def removeQueryRole(role: AQuery#QueryObject): Unit = {
-    if (role.isInstanceOf[QueryNatObject]) {
-      queryNatRoles -= role.asInstanceOf[QueryNatObject]
-    }
-    if (role.isInstanceOf[QueryRelObject]) {
-      queryRelRoles -= role.asInstanceOf[QueryRelObject]
-    }
-  }
-  
-  def addQueryRole(obj: Object): AQuery#QueryObject = {
-    val relResult = getQueryRelRole(obj)
-    if (relResult != null) return relResult
-    val natResult = getQueryNatRole(obj)
-    if (natResult != null) return natResult
-    //get player
-    val playerObj = obj.player.getOrElse(obj)
-    //difference between relation and natural
-    if (playerObj.isInstanceOf[IRelationCompartment]) {
-      val refComp = playerObj.asInstanceOf[IRelationCompartment]
-      this.combine(refComp)
-      val sourceRole: QueryNatObject = getQueryNatRole(refComp.getSource())
-      val targetRole: QueryNatObject = getQueryNatRole(refComp.getTarget())
-      if (sourceRole == null || targetRole == null) {
-        println("--- Error: Relational compartment can only be added if source and target are added before")
-        return null
-      }
-      val newRole = new QueryRelObject(sourceRole, targetRole)
-      queryRelRoles += newRole    
-      playerObj play newRole
-      return newRole
-    } else {
-      val newRole = new QueryNatObject()
-      queryNatRoles += newRole    
-      playerObj play newRole
-      return newRole
-    }  
-  }  
+  /**
+   * Create ModelJoin syntax for views.
+   */
+  def generateModelJoinFromQuery(fileName: String): String
   
-  def runQuery(): Set[Set[Object]] = {
-    //delete at the end
-    var forDeletionQueryResults: Set[QueryNatResult] = Set.empty
-    //immediate values
-    var deleteNatResults: Set[QueryNatResult] = Set.empty   
-    var doSomething = true
-    //output value
-    var result: Set[Set[Object]] = Set.empty
-    
-    //###add query results to all elements that can be results because of connection properties
-    //...iterate over non negated query relations and add result roles if necessary 
-    queryRelRoles.filter(!_.isNegated()).foreach(queryRel => {
-      val playerQueryRel: IRelationCompartment = queryRel.player.right.get.asInstanceOf[IRelationCompartment]
-      RsumCompartment.getRelations().foreach(rsumRel => {
-        if (playerQueryRel.getClass.isInstance(rsumRel)) {
-          //search if their are existing results if not create new ones
-          val rsumNatSource: Object = rsumRel.getSource().player.right.get
-          val rsumNatTarget: Object = rsumRel.getTarget().player.right.get
-          var queryNatResultSource: QueryNatResult = getNatResultRole(rsumNatSource, queryRel.source)
-          if (queryNatResultSource == null) {
-            queryNatResultSource = new QueryNatResult(queryRel.source)  
-            rsumNatSource play queryNatResultSource
-            queryNatResults += queryNatResultSource
-          }          
-          var queryNatResultTarget: QueryNatResult = getNatResultRole(rsumNatTarget, queryRel.target)
-          if (queryNatResultTarget == null) {
-            queryNatResultTarget = new QueryNatResult(queryRel.target)  
-            rsumNatTarget play queryNatResultTarget
-            queryNatResults += queryNatResultTarget
-          }
-          //connect them in a new relation result
-          val queryRelResult: QueryRelResult = new QueryRelResult(queryRel, queryNatResultSource, queryNatResultTarget, false) 
-          rsumRel play queryRelResult     
-          queryRelResults += queryRelResult
-          
-          //if transitive add new relation to separate list to add them at the end
-          if (queryRel.isTransitive) {
-            //set only source new because target must be old one, transitive query means always target same
-            queryNatResultSource = getNatResultRole(rsumNatSource, queryRel.target)
-            if (queryNatResultSource == null) {
-              queryNatResultSource = new QueryNatResult(queryRel.target)  
-              rsumNatSource play queryNatResultSource
-              queryNatResults += queryNatResultSource
-            }
-            val transitiveQueryRelResult: QueryRelResult = new QueryRelResult(queryRel, queryNatResultSource, queryNatResultTarget, true) 
-            rsumRel play transitiveQueryRelResult     
-            queryRelResults += transitiveQueryRelResult
-          }
-        }
-      })      
-    })
-    
-    //...iterate over negated related roles and search all opposite naturals that do not implement this rel
-    queryRelRoles.filter(_.isNegated()).foreach(queryRel => {
-      val playerQueryRel: IRelationCompartment = queryRel.player.right.get.asInstanceOf[IRelationCompartment]
-      var playerQueryNat: Object = null
-      if (queryRel.source.negated) {
-        playerQueryNat = playerQueryRel.getSource.player.right.get 
-      } else {
-        playerQueryNat = playerQueryRel.getTarget.player.right.get 
-      }
-      //source or target negated, search for negated class
-      RsumCompartment.getNaturals().foreach(rsumNat => {
-        if (playerQueryNat.getClass.isInstance(rsumNat))
-        {
-          var goodElement: Boolean = true;
-          //filtered roles of the natural type
-          var roles: Set[IRelationRole] = Set.empty 
-          if (queryRel.source.negated) {
-            roles = rsumNat.roles().filter(_.isInstanceOf[IRelationCompartment#ITarget]).toSet.asInstanceOf[Set[IRelationRole]] 
-          } else {
-            roles = rsumNat.roles().filter(_.isInstanceOf[IRelationCompartment#ISource]).toSet.asInstanceOf[Set[IRelationRole]] 
-          }
-          //if we find a role that works than we can not add this natural to the results
-          roles.foreach(r => {            
-            val outerRelComp = r.getOuterCompartment()
-            //println("COMP: " + outerRelComp + " " + playerQueryRel + " " + playerQueryRel.getClass.isInstance(outerRelComp))
-            if (playerQueryRel.getClass.isInstance(outerRelComp)) {
-              //we can not use this element
-              goodElement = false
-            }
-          })
-          //if we do not find a compatible element in this natural role we can add it
-          if (goodElement) {
-            var queryNatRole: QueryNatObject = null
-            if (queryRel.source.negated) {
-              queryNatRole = queryRel.target            
-            } else {
-              queryNatRole = queryRel.source
-            }
-            var queryNatResult: QueryNatResult = getNatResultRole(rsumNat, queryNatRole)
-            if (queryNatResult == null) {
-              queryNatResult = new QueryNatResult(queryNatRole) 
-              rsumNat play queryNatResult
-              queryNatResults += queryNatResult
-            }
-            if (queryRel.source.negated) {
-              queryNatResult.increaseTargetNegated()
-            } else {
-              queryNatResult.increaseSourceNegated()
-            }          
-          }
-        }
-      })
-    })    
-    
-    //...iterate over all query naturals without a connection and add result roles if necessary
-    queryNatRoles.filter(_.connectionSize == 0).foreach(queryNat => {
-      //connected one are visited in the part before
-      val playerQueryNat: Object = queryNat.player.right.get
-      RsumCompartment.getNaturals().foreach(rsumNat => {
-        if (playerQueryNat.isInstanceOf[QueryHelper]) {
-          if (playerQueryNat.equals(rsumNat)) {
-            var queryNatResult: QueryNatResult = getNatResultRole(rsumNat, queryNat)
-            if (queryNatResult == null) {
-              queryNatResult = new QueryNatResult(queryNat)  
-              rsumNat play queryNatResult
-              queryNatResults += queryNatResult
-            }
-          }
-        } else {
-          if (playerQueryNat.getClass.isInstance(rsumNat)) {
-            var queryNatResult: QueryNatResult = getNatResultRole(rsumNat, queryNat)
-            if (queryNatResult == null) {
-              queryNatResult = new QueryNatResult(queryNat)  
-              rsumNat play queryNatResult
-              queryNatResults += queryNatResult
-            }
-          }
-        }        
-      })
-    })
-    
-    //###proof correctness of results
-    //...proof attribute correctness once
-    queryNatResults.filter(!_.proofAttributes).foreach(deleteNatResults += _)
-    //delete them
-    deleteNatResults.foreach(queryResultNat => {
-      queryNatResults -= queryResultNat
-      forDeletionQueryResults += queryResultNat
-      queryResultNat.removeConnections()
-    })
-    
-    //...proof the correctness of the query results and delete non correct ones
-    while (doSomething) {
-      deleteNatResults = Set.empty      
-      //proof the connection correctness
-      queryNatResults.filter(!_.proofConnections).foreach(deleteNatResults += _)
-      
-      //do as long as everything is correct
-      doSomething = !deleteNatResults.isEmpty
-      //delete them
-      deleteNatResults.foreach(queryResultNat => {
-        queryNatResults -= queryResultNat
-        forDeletionQueryResults += queryResultNat
-        queryResultNat.removeConnections()   
-      })
-    }
-    
-    //###make good outputs from the current query results
-    //...only correct elements should now play result roles and are in the list    
-    var combinedResult: Set[QueryCombinedResult] = queryRelResults.filter(!_.transitive).map(_.createCombinedResult())
-    
-    //...combine the result elements to good output units
-    doSomething = true
-    while (doSomething) {
-      doSomething = false
-      combinedResult.foreach(combined => {
-        queryRelResults.foreach(rel => {
-          if (rel.source == combined.target && !combined.contains(rel.target)) {
-            //add in the back
-            combined.addBack(rel.target)
-            doSomething = true
-          } else {
-            if (rel.target == combined.source && !combined.contains(rel.source)) {
-              //add in the front
-              combined.addFront(rel.source)
-              doSomething = true
-            }            
-          }
-        })    
-      })  
-      //delete duplicated elements
-      combinedResult = combinedResult.groupBy(_.getBetween).map(_._2.head).toSet
-      //combinedResult.distinct
-    }
-    
-    //create only results with tuples
-    /*queryRelResults.foreach(rel => {
-      var rSet: Set[Object] = Set.empty
-      if (rel.source.connectedQueryObject.returned) {
-        rSet += rel.source.player.right.get
-      }
-      if (rel.target.connectedQueryObject.returned) {
-        rSet += rel.target.player.right.get
-      }
-      result += rSet
-    })*/
-    
-    //...bring the output format to the reals one
-    combinedResult.foreach(combined => {
-      var rSet: Set[Object] = Set.empty
-      combined.getBetween.foreach(queryNat => {
-        if (queryNat.connectedQueryObject.returned) {
-          rSet += queryNat.player.right.get
-        }
-      })
-      result += rSet
-    })
-    
-    //...add also single results
-    queryNatResults.foreach(queryResultNat => {
-      if (!queryResultNat.isConnected() && queryResultNat.connectedQueryObject.returned) {
-        result += Set(queryResultNat.player.right.get)
-      }
-    })
-    
-    //...delete now really all not needed result roles 
-    forDeletionQueryResults.foreach(_.remove())
-    
-    return result
-  }
+  /**
+   * Add a query role to the underlying object.
+   */
+  def addQueryRole(obj: Object): Query#QueryObject
   
-  override def toString(): String = name + ": " + isQueryCorrect + " Rs: " + queryNatRoles + " " + queryRelRoles
+  /**
+   * Remove a query role from the query.
+   */
+  def removeQueryRole(role: Query#QueryObject): Unit
   
   /**
-   * Query object specialized for naturals in the RSUM.
+   * Proof if the query has a correct form.
+   * Not more than one connection island.
    */
-  class QueryNatObject() extends QueryObject() {
-    private var sourceRelations: Set[QueryRelObject] = Set.empty
-    private var targetRelations: Set[QueryRelObject] = Set.empty    
-    
-    def addSourceRelation(rel: QueryRelObject): Unit = {
-      sourceRelations += rel
-    }    
-    
-    def removeSourceRelation(rel: QueryRelObject): Unit = {
-      sourceRelations -= rel
-    }
-    
-    def getSourceRelationsSize(): Int = sourceRelations.filter(!_.isNegated()).map(_.multiTarget).sum //sum up multi value not use size
-    def getNegatedSourceRelationsSize(): Int = sourceRelations.filter(_.isNegated()).size
-    
-    def addTargetRelation(rel: QueryRelObject): Unit = {
-      targetRelations += rel
-    }
-    
-    def removeTargetRelation(rel: QueryRelObject): Unit = {
-      targetRelations -= rel
-    }
-    
-    def getTargetRelationsSize(): Int = targetRelations.filter(!_.isNegated()).map(_.multiSource).sum
-    def getNegatedTargetRelationsSize(): Int = targetRelations.filter(_.isNegated()).size
-    
-    def connectionSize(): Int = targetRelations.size + sourceRelations.size
-    
-    def overallConnectionUnit(): Int = {
-      var visitedRel: Set[QueryRelObject] = Set.empty
-      var visitedNat: Set[QueryNatObject] = Set(this)
-      var unVisitedRel: Set[QueryRelObject] = targetRelations ++ sourceRelations
-      var unVisitedNat: Set[QueryNatObject] = Set.empty
-      while (!unVisitedRel.isEmpty || !unVisitedNat.isEmpty) {
-        //run over all unvisited relations 
-        unVisitedRel.foreach(rel => {
-          if (!visitedNat.contains(rel.source))
-            unVisitedNat += rel.source 
-          if (!visitedNat.contains(rel.target))
-            unVisitedNat += rel.target
-        })
-        visitedRel ++= unVisitedRel
-        unVisitedRel = Set.empty
-        //run over all unvisited naturals 
-        unVisitedNat.foreach(nat => {
-          nat.sourceRelations.filter(!visitedRel.contains(_)).foreach(unVisitedRel += _)
-          nat.targetRelations.filter(!visitedRel.contains(_)).foreach(unVisitedRel += _)
-        })
-        visitedNat ++= unVisitedNat
-        unVisitedNat = Set.empty        
-      }
-      return visitedRel.size + visitedNat.size
-    }
-    
-    override def toString: String = "QON: " + label + " C: " + connectionSize
-  }
-    
+  def isQueryCorrect(): Boolean
+  
   /**
-   * Query object specialized for relational compartments in the RSUM.
+   * Running the query and getting a set of sets of result objects.
    */
-  class QueryRelObject(val source: QueryNatObject, val target: QueryNatObject) extends QueryObject() {
-
-    def isNegated(): Boolean = source.negated || target.negated
-    def isTransitive(): Boolean = target.transitive
-    def multiTarget(): Int = target.multi
-    def multiSource(): Int = source.multi
-    
-    source.addSourceRelation(this)
-    target.addTargetRelation(this)
-    
-    def overallConnectionUnit(): Int = source.overallConnectionUnit()
-    
-    override def toString: String = "QOR: " + source.label + "-" + target.label
-  }
-    
+  def runQuery(): Set[Set[Object]]
+  
   /**
-   * Query result roles for natural query roles.
+   * Abstract query object to create the query from example.
    */
-  class QueryNatResult(val connectedQueryObject: QueryNatObject) extends QueryResult(connectedQueryObject) {
-    private var sourceRelations: Set[QueryRelResult] = Set.empty
-    private var targetRelations: Set[QueryRelResult] = Set.empty
-    
-    private var negatedSources: Int = 0
-    private var negatedTargets: Int = 0
-    
-    def increaseSourceNegated(): Unit = { negatedSources += 1 }
-    def decreaseSourceNegated(): Unit = { negatedSources -= 1 }
-    
-    def increaseTargetNegated(): Unit = { negatedTargets += 1 }
-    def decreaseTargetNegated(): Unit = { negatedTargets -= 1 }
+  abstract class QueryObject() {
     
     /**
-     * Proof if the player has all the necessary attributes with its values.
+     * Label to identify a query object.
      */
-    def proofAttributes(): Boolean = {
-      val player: Object = this.player.right.get   
-      var returnValue = true 
-      connectedQueryObject.getAttributeFilters.foreach(a => {
-        try {
-          //player.getClass.getMethods.foreach(f => println(f.toString))
-          //println(player.getClass.getMethod("name").getReturnType) //getName
-          val met = player.getClass.getMethod(a.attributeName)        
-          val result: String = met.invoke(player).asInstanceOf[String]
-          a.checking match {
-            case CheckingOption.equalsCheck => if (result != a.value) returnValue = false
-            case CheckingOption.biggerThan => if (result <= a.value) returnValue = false
-            case CheckingOption.smallerThan => if (result >= a.value) returnValue = false
-            case _ =>
-          }
-        } catch {
-          case _: Throwable => { 
-            println("!!! No attribute with this name!!!") 
-            return false
-          }
-        }
-      })
-      return returnValue
-    }
+    var label: String = ""
     
     /**
-     * Proof if the number of connections is equals to the related query object.
+     * Describes is necessary to be in the results or to be not.
      */
-    def proofConnections(): Boolean = {
-      //TODO: proof also the number of types and not only the numbers
-      //println("S: " + _connectedQueryObject.getSourceRelationsSize() + " T: " + _connectedQueryObject.getTargetRelationsSize() + " NS: " + _connectedQueryObject.getNegatedSourceRelationsSize() + " NT: " + _connectedQueryObject.getNegatedTargetRelationsSize() + " Con: " + _connectedQueryObject)
-      //println("S: " + getSourceRelationsSize() + " T: " + getTargetRelationsSize() + " NS: " + negatedSources + " NT: " + negatedTargets + " This: " + this)
-      if (getSourceRelationsSize >= connectedQueryObject.getSourceRelationsSize() 
-          && getTargetRelationsSize >= connectedQueryObject.getTargetRelationsSize()
-          && negatedSources >= connectedQueryObject.getNegatedSourceRelationsSize()
-          && negatedTargets >= connectedQueryObject.getNegatedTargetRelationsSize()) {
-        return true
-      }
-      return false
-    }
+    var negated: Boolean = false
     
-    def addSourceRelation(rel: QueryRelResult): Unit = {
-      sourceRelations += rel
-    }
+    /**
+     * Important to describe if a transitive closure should be created.
+     */
+    var transitive: Boolean = false
     
-    def removeSourceRelation(rel: QueryRelResult): Unit = {
-      sourceRelations -= rel
-    }
+    /**
+     * Describes how often a connection must exists.
+     */
+    var multi: Int = 1
     
-    def getSourceRelationsSize(): Int = sourceRelations.size
+    /**
+     * Describes if the elements should be returned in the results or not.
+     */
+    var returned: Boolean = true
     
-    def addTargetRelation(rel: QueryRelResult): Unit = {
-      targetRelations += rel
+    private var attributeFilters: Set[AttributeFilter] = Set.empty
+      
+    /**
+  	 * Create and add an attribute filter object to a query object.
+   	 */        
+    def addAttributeFilter(attributeName: String, value: String, bigger: CheckingOption.Value): Boolean = {
+      if (attributeName == null || attributeName == "" ||
+        bigger == null || value == null || value == "") {
+        return false
+      }
+      attributeFilters += new AttributeFilter(attributeName, value, bigger)
+      return true
     }
     
-    def removeTargetRelation(rel: QueryRelResult): Unit = {
-      targetRelations -= rel
-    }
+    def getAttributeFilters(): Set[AttributeFilter] = attributeFilters
     
-    def getTargetRelationsSize(): Int = targetRelations.size
-        
-    def isConnected(): Boolean = (targetRelations.size + sourceRelations.size) > 0
+    def overallConnectionUnit(): Int
     
-    def removeConnections(): Unit = {
-      sourceRelations.foreach(rel => {        
-        rel.target.removeTargetRelation(rel)
-        queryRelResults -= rel
-        rel.remove()
-      })      
-      targetRelations.foreach(rel => {        
-        rel.source.removeSourceRelation(rel)
-        queryRelResults -= rel
-        rel.remove()
-      })
-      sourceRelations = Set.empty
-      targetRelations = Set.empty    
-      negatedSources = 0
-      negatedTargets = 0
-    }
-  }
+    override def toString(): String = "QO: " + label
+  }  
   
   /**
-   * Query result roles for relation query roles.
+   * Abstract query results that each element which matches the query gets.
    */
-  class QueryRelResult(val connectedQueryObject: QueryRelObject, val source: QueryNatResult, val target: QueryNatResult, val transitive: Boolean) extends QueryResult(connectedQueryObject) {
-    //only add this relation to the connect results if it is not transitive
-    if (!transitive) {
-      source.addSourceRelation(this)
-      target.addTargetRelation(this)
-    }
+  abstract class QueryResult(val matchedQueryObject: QueryObject) {
     
-    /**
-     * Create a new combined result which is a copy of this one.
-     */
-    def createCombinedResult(): QueryCombinedResult = new QueryCombinedResult(source, target)
+    override def toString(): String = "QR: (" + this.player.right.get.toString() + " " + matchedQueryObject + ")"
   }
   
   /**
-   * Helper class to connect the results to a chain.
+   * Should collect information about the attributes a query element must have
    */
-  class QueryCombinedResult(var source: QueryNatResult, var target: QueryNatResult) {
-    
-    //list of all query results that are connected
-    private var between: Seq[QueryNatResult] = Seq(source, target)
-    
-    def getBetween(): Seq[QueryNatResult] = between
-    
-    def addFront(newIn: QueryNatResult): Unit = {
-      between = newIn +: between
-      source = newIn
-    }
-    
-    def addBack(newIn: QueryNatResult): Unit = {
-      between = between :+ newIn
-      target = newIn
-    }
-    
-    def contains(result: QueryNatResult): Boolean = ( between.contains(result) )
-    
-    private def getSize(): Int = between.size    
-    
-    protected def canEqual(other: Any): Boolean = other.isInstanceOf[QueryCombinedResult]
-    
-    override def equals(other: Any): Boolean = other match {
-      case that: QueryCombinedResult => {
-        if (that canEqual this) {
-          between.foreach(b => {
-            if (!that.contains(b))
-              return false
-          })
-          return that.getSize == this.getSize()
-        } else {
-          return false
-        }
-      }
-      case _ => return false
-    }
-    
-    override def toString(): String = "QCR: (" + between + ")"
-  }  
+  class AttributeFilter(val attributeName: String, val value: String, val checking: CheckingOption.Value) {}
 }
\ No newline at end of file
diff --git a/src/main/scala/org/rosi_project/model_management/sum/query/IQueryViewCompartment.scala b/src/main/scala/org/rosi_project/model_management/sum/query/QueryFactory.scala
similarity index 75%
rename from src/main/scala/org/rosi_project/model_management/sum/query/IQueryViewCompartment.scala
rename to src/main/scala/org/rosi_project/model_management/sum/query/QueryFactory.scala
index 462693e2d5ad7b0d5cfb71ac15647523fed0130c..0f9b590c84b4561faf00283b33f5be099ca10e7d 100644
--- a/src/main/scala/org/rosi_project/model_management/sum/query/IQueryViewCompartment.scala
+++ b/src/main/scala/org/rosi_project/model_management/sum/query/QueryFactory.scala
@@ -6,20 +6,20 @@ import scala.collection.mutable.Set
 import org.rosi_project.model_management.core.RsumCompartment
 import org.rosi_project.model_management.sum.compartments.IRelationCompartment
 
-trait IQueryViewCompartment extends Compartment {
+trait QueryFactory extends Compartment {
   
   private var name: String = ""
-  private var query: Query = null
+  private var query: RsumQuery = null
   
   RsumCompartment.combine(this)
   
   protected def init(n: String): Unit = {
     name = n
-    query = new Query(n)
+    query = new RsumQuery(n)
   }
   
-  private var naturalRoles = Set[AQueryViewRole]()
-  private var relationalRoles = Set[AQueryViewRole]()
+  private var naturalRoles = Set[QueryFactoryElement]()
+  private var relationalRoles = Set[QueryFactoryElement]()
   
   def getName(): String = name
   
@@ -29,8 +29,8 @@ trait IQueryViewCompartment extends Compartment {
    * Get a map with the simple names of all elements 
    * and the connected elements in the view.
    */
-  def getMapOfElements(): Map[String, Set[AQueryViewRole]] = {
-    var result: Map[String, Set[AQueryViewRole]] = Map.empty
+  def getMapOfElements(): Map[String, Set[QueryFactoryElement]] = {
+    var result: Map[String, Set[QueryFactoryElement]] = Map.empty
     naturalRoles.foreach(n => {
       if (result.contains(n.getClass.getSimpleName)) {
         result(n.getClass.getSimpleName) += n
@@ -44,8 +44,8 @@ trait IQueryViewCompartment extends Compartment {
   /**
    * Get all elements with the specific simple name.
    */
-  def getElementsWithClassName(s: String): Set[AQueryViewRole] = {
-    var result: Set[AQueryViewRole] = Set.empty
+  def getElementsWithClassName(s: String): Set[QueryFactoryElement] = {
+    var result: Set[QueryFactoryElement] = Set.empty
     naturalRoles.foreach(n => {
       if (n.getClass.getSimpleName == s) {
         result += n
@@ -57,7 +57,7 @@ trait IQueryViewCompartment extends Compartment {
   /**
    * Get all elements with the same type from the view.
    */
-  def getElementsWithExample[A <: AQueryViewRole](a: A): Set[A] = {
+  def getElementsWithExample[A <: QueryFactoryElement](a: A): Set[A] = {
     var result: Set[A] = Set.empty
     naturalRoles.foreach(n => {
       if (n.getClass.getName == a.getClass.getName) {
@@ -67,7 +67,7 @@ trait IQueryViewCompartment extends Compartment {
     result
   }
   
-  protected def getRoleFromList(classname: Object): AQueryViewRole = {
+  protected def getRoleFromList(classname: Object): QueryFactoryElement = {
     relationalRoles.foreach { r =>
       if (+r == +classname) {
         return r
@@ -97,13 +97,13 @@ trait IQueryViewCompartment extends Compartment {
     println("-------------------------------------------------------------------")
   }
   
-  def getAllViewElements(): Set[AQueryViewRole] = naturalRoles
+  def getAllViewElements(): Set[QueryFactoryElement] = naturalRoles
   
-  def containsRole(role: AQueryViewRole): Boolean = naturalRoles.contains(role)
+  def containsRole(role: QueryFactoryElement): Boolean = naturalRoles.contains(role)
   
-  abstract class AQueryViewRole {  
+  abstract class QueryFactoryElement {  
     
-    protected var connected: AQuery#QueryObject = null 
+    protected var connected: Query#QueryObject = null 
     
     initializeElement()
     
@@ -111,7 +111,7 @@ trait IQueryViewCompartment extends Compartment {
     
     protected def getCreationObject(): Object
     
-    def getQueryObject: AQuery#QueryObject = connected  
+    def getQueryObject: Query#QueryObject = connected  
 
     private def initializeElement(): Unit = {
       val obj = getCreationObject
diff --git a/src/main/scala/org/rosi_project/model_management/sum/query/RsumQuery.scala b/src/main/scala/org/rosi_project/model_management/sum/query/RsumQuery.scala
new file mode 100644
index 0000000000000000000000000000000000000000..487b2eb94a7104f6e0493a928e9d87dd3bd05470
--- /dev/null
+++ b/src/main/scala/org/rosi_project/model_management/sum/query/RsumQuery.scala
@@ -0,0 +1,679 @@
+package org.rosi_project.model_management.sum.query
+
+import scroll.internal.Compartment
+import org.rosi_project.model_management.core.RsumCompartment
+import org.rosi_project.model_management.sum.compartments.IRelationCompartment
+import org.rosi_project.model_management.sum.roles.IRelationRole
+import org.rosi_project.model_management.util.query.ModelJoinCreator
+import org.rosi_project.model_sync.model_join.representation.grammar.CompoundKeepBuilder
+import util.control.Breaks._
+
+/**
+ * Special query implementation for the query interface that works on the RSUM.
+ */
+class RsumQuery(_name: String) extends Query(_name) {
+
+  RsumCompartment.combine(this)
+
+  private var queryRelRoles: Set[RelationalQueryObject] = Set.empty
+  private var queryNatRoles: Set[NaturalQueryObject] = Set.empty
+
+  private var queryRelResults: Set[RelationalQueryResult] = Set.empty
+  private var queryNatResults: Set[NaturalQueryResult] = Set.empty
+
+  private def getQueryNatRole(obj: Object): NaturalQueryObject = {
+    //queryNatRoles.filter(+_ == +obj).foreach(return _)
+    queryNatRoles.foreach(q => {
+      if (+obj == +q) {
+        return q
+      }
+    })
+    return null
+  }
+
+  private def getQueryRelRole(obj: Object): RelationalQueryObject = {
+    //queryRelRoles.filter(+_ == +obj).foreach(return _)
+    queryRelRoles.foreach(q => {
+      if (+obj == +q) {
+        return q
+      }
+    })
+    return null
+  }
+
+  private def getNatResultRole(player: Object, queryObject: NaturalQueryObject): NaturalQueryResult = {
+    //queryNatResults.filter(r => r.connectedQueryObject == queryObject && +player == +r).foreach(return _)
+    queryNatResults.foreach(r => {
+      if (r.connectedQueryObject == queryObject && +player == +r) {
+        return r
+      }
+    })
+    return null
+  }
+
+  def generateModelJoinFromQuery(fileName: String): String = {
+    val creator = new ModelJoinCreator
+    var relHelper: Set[ModelJoinContainer] = Set.empty
+    var relNames: Set[String] = Set.empty
+
+    queryRelRoles.filter(r => r.isReturned() && !r.isNegated).foreach(q => {
+      val playerStart: Object = q.player.right.get
+      val playerSource: Object = q.source.player.right.get
+      val playerTarget: Object = q.target.player.right.get
+      println("+" + playerStart.getClass.getName + " " + playerSource.getClass.getName + " " + playerTarget.getClass.getName)
+      if (!relNames.contains(playerStart.getClass.getName)) {
+        var nameChange = playerStart.getClass.getSimpleName
+        if (nameChange.startsWith(playerSource.getClass.getSimpleName)) {
+          nameChange = nameChange.replaceFirst(playerSource.getClass.getSimpleName, "")
+        }
+        if (nameChange.startsWith(playerSource.getClass.getSuperclass.getSimpleName)) {
+          nameChange = nameChange.replaceFirst(playerSource.getClass.getSuperclass.getSimpleName, "")
+        }
+        if (nameChange.startsWith(playerSource.getClass.getSuperclass.getSuperclass.getSimpleName)) {
+          nameChange = nameChange.replaceFirst(playerSource.getClass.getSuperclass.getSuperclass.getSimpleName, "")
+        }
+        nameChange = Character.toLowerCase(nameChange.charAt(0)) + nameChange.substring(1);
+        nameChange = nameChange.replaceFirst(playerTarget.getClass.getSimpleName, "")
+        //create join and reference builder
+        val sourceMj = creator.createNaturalJoin(playerSource.getClass.getName)
+        val targetMj = creator.createOutgoingReference(playerSource.getClass.getName, playerTarget.getClass.getName, nameChange)
+
+        val mjContainer = new ModelJoinContainer(nameChange, playerSource.getClass.getName)
+        playerSource.getClass.getMethods.filter(m => m.getParameterCount == 0 && m.getDeclaringClass.getName != "java.lang.Object")
+          .foreach(m => {
+            if (m.getName != "toString" && !m.getName.startsWith("get")) {
+              creator.createAttribute(sourceMj, playerSource.getClass.getName, m.getName)
+            }
+          })
+        if (playerSource.getClass.getName != playerTarget.getClass.getName) {
+          playerTarget.getClass.getMethods.filter(m => m.getParameterCount == 0 && m.getDeclaringClass.getName != "java.lang.Object")
+            .foreach(m => {
+              if (m.getName != "toString" && !m.getName.startsWith("get")) {
+                creator.createAttribute(targetMj, playerTarget.getClass.getName, m.getName)
+              }
+            })
+        }
+
+        //unbuild and undone target and source
+        val buildTarget = creator.buildExpression(targetMj)
+        creator.addKeepExpression(sourceMj, buildTarget)
+        val buildSource = creator.done(sourceMj)
+
+        mjContainer.connect += (playerSource.getClass.getName -> buildSource)
+        if (playerSource.getClass.getName != playerTarget.getClass.getName) {
+          mjContainer.connect += (playerTarget.getClass.getName -> buildTarget)
+        }
+        relHelper += mjContainer
+        relNames += playerStart.getClass.getName
+      }
+    })
+
+    if (relHelper.size > 0) {
+      var run = relHelper.size > 1
+      while (run) {
+        var other: ModelJoinContainer = null
+        breakable {
+          relHelper.foreach(a => {
+            relHelper.foreach(b => {
+              if (a != b && a.isComparable(b)) {
+                other = a.concat(b)
+                break
+              }
+            })
+          })
+        }
+        run = relHelper.size > 1 && other != null
+        if (other != null) {
+          relHelper -= other
+        }
+      }
+      relHelper.foreach(r => {
+        creator.createFile(r.connect.get(r.source).get, fileName + ".modeljoin")
+      })
+    } else {
+      queryNatRoles.filter(r => r.returned && !r.negated).foreach(q => {
+        val playerStart: Object = q.player.right.get
+        var clsName = playerStart.getClass.getName
+        if (playerStart.isInstanceOf[QueryHelper]) {
+          clsName = playerStart.getClass.getSuperclass.getName          
+        }
+        println("-" + clsName)
+        val nj = creator.createNaturalJoin(clsName)
+        playerStart.getClass.getMethods.filter(m => m.getParameterCount == 0 && m.getDeclaringClass.getName != "java.lang.Object")
+          .foreach(m => {
+            if (m.getName != "toString" && !m.getName.startsWith("get")) {
+              creator.createAttribute(nj, clsName, m.getName)
+            }
+          })
+        creator.createFile(creator.done(nj), fileName + ".modeljoin")
+      })
+    }
+    ""
+  }
+
+  def deleteQueryResults(): Unit = {
+    queryRelResults.foreach(_.remove())
+    queryRelResults = Set.empty
+    queryNatResults.foreach(_.remove())
+    queryNatResults = Set.empty
+  }
+
+  def deleteQueryObjects(): Unit = {
+    queryRelRoles.foreach(_.remove())
+    queryRelRoles = Set.empty
+    queryNatRoles.foreach(_.remove())
+    queryNatRoles = Set.empty
+  }
+
+  def isQueryCorrect(): Boolean = {
+    //check if the query is correct and does not contain more close islands
+    queryRelRoles.foreach(qo => {
+      return qo.overallConnectionUnit() == (queryRelRoles.size + queryNatRoles.size)
+    })
+    queryNatRoles.foreach(qo => {
+      return qo.overallConnectionUnit() == (queryRelRoles.size + queryNatRoles.size)
+    })
+    return true
+  }
+
+  def removeQueryRole(role: Query#QueryObject): Unit = {
+    if (role.isInstanceOf[NaturalQueryObject]) {
+      queryNatRoles -= role.asInstanceOf[NaturalQueryObject]
+    }
+    if (role.isInstanceOf[RelationalQueryObject]) {
+      queryRelRoles -= role.asInstanceOf[RelationalQueryObject]
+    }
+  }
+
+  def addQueryRole(obj: Object): Query#QueryObject = {
+    val relResult = getQueryRelRole(obj)
+    if (relResult != null) return relResult
+    val natResult = getQueryNatRole(obj)
+    if (natResult != null) return natResult
+    //get player
+    val playerObj = obj.player.getOrElse(obj)
+    //difference between relation and natural
+    if (playerObj.isInstanceOf[IRelationCompartment]) {
+      val refComp = playerObj.asInstanceOf[IRelationCompartment]
+      this.combine(refComp)
+      val sourceRole: NaturalQueryObject = getQueryNatRole(refComp.getSource())
+      val targetRole: NaturalQueryObject = getQueryNatRole(refComp.getTarget())
+      if (sourceRole == null || targetRole == null) {
+        println("--- Error: Relational compartment can only be added if source and target are added before")
+        return null
+      }
+      val newRole = new RelationalQueryObject(sourceRole, targetRole)
+      queryRelRoles += newRole
+      playerObj play newRole
+      return newRole
+    } else {
+      val newRole = new NaturalQueryObject()
+      queryNatRoles += newRole
+      playerObj play newRole
+      return newRole
+    }
+  }
+
+  def runQuery(): Set[Set[Object]] = {
+    //delete at the end
+    var forDeletionQueryResults: Set[NaturalQueryResult] = Set.empty
+    //immediate values
+    var deleteNatResults: Set[NaturalQueryResult] = Set.empty
+    var doSomething = true
+    //output value
+    var result: Set[Set[Object]] = Set.empty
+
+    //###add query results to all elements that can be results because of connection properties
+    //...iterate over non negated query relations and add result roles if necessary 
+    queryRelRoles.filter(!_.isNegated()).foreach(queryRel => {
+      val playerQueryRel: IRelationCompartment = queryRel.player.right.get.asInstanceOf[IRelationCompartment]
+      RsumCompartment.getRelations().foreach(rsumRel => {
+        if (playerQueryRel.getClass.isInstance(rsumRel)) {
+          //search if their are existing results if not create new ones
+          val rsumNatSource: Object = rsumRel.getSource().player.right.get
+          val rsumNatTarget: Object = rsumRel.getTarget().player.right.get
+          var queryNatResultSource: NaturalQueryResult = getNatResultRole(rsumNatSource, queryRel.source)
+          if (queryNatResultSource == null) {
+            queryNatResultSource = new NaturalQueryResult(queryRel.source)
+            rsumNatSource play queryNatResultSource
+            queryNatResults += queryNatResultSource
+          }
+          var queryNatResultTarget: NaturalQueryResult = getNatResultRole(rsumNatTarget, queryRel.target)
+          if (queryNatResultTarget == null) {
+            queryNatResultTarget = new NaturalQueryResult(queryRel.target)
+            rsumNatTarget play queryNatResultTarget
+            queryNatResults += queryNatResultTarget
+          }
+          //connect them in a new relation result
+          val queryRelResult: RelationalQueryResult = new RelationalQueryResult(queryRel, queryNatResultSource, queryNatResultTarget, false)
+          rsumRel play queryRelResult
+          queryRelResults += queryRelResult
+
+          //if transitive add new relation to separate list to add them at the end
+          if (queryRel.isTransitive) {
+            //set only source new because target must be old one, transitive query means always target same
+            queryNatResultSource = getNatResultRole(rsumNatSource, queryRel.target)
+            if (queryNatResultSource == null) {
+              queryNatResultSource = new NaturalQueryResult(queryRel.target)
+              rsumNatSource play queryNatResultSource
+              queryNatResults += queryNatResultSource
+            }
+            val transitiveQueryRelResult: RelationalQueryResult = new RelationalQueryResult(queryRel, queryNatResultSource, queryNatResultTarget, true)
+            rsumRel play transitiveQueryRelResult
+            queryRelResults += transitiveQueryRelResult
+          }
+        }
+      })
+    })
+
+    //...iterate over negated related roles and search all opposite naturals that do not implement this rel
+    queryRelRoles.filter(_.isNegated()).foreach(queryRel => {
+      val playerQueryRel: IRelationCompartment = queryRel.player.right.get.asInstanceOf[IRelationCompartment]
+      var playerQueryNat: Object = null
+      if (queryRel.source.negated) {
+        playerQueryNat = playerQueryRel.getSource.player.right.get
+      } else {
+        playerQueryNat = playerQueryRel.getTarget.player.right.get
+      }
+      //source or target negated, search for negated class
+      RsumCompartment.getNaturals().foreach(rsumNat => {
+        if (playerQueryNat.getClass.isInstance(rsumNat)) {
+          var goodElement: Boolean = true;
+          //filtered roles of the natural type
+          var roles: Set[IRelationRole] = Set.empty
+          if (queryRel.source.negated) {
+            roles = rsumNat.roles().filter(_.isInstanceOf[IRelationCompartment#ITarget]).toSet.asInstanceOf[Set[IRelationRole]]
+          } else {
+            roles = rsumNat.roles().filter(_.isInstanceOf[IRelationCompartment#ISource]).toSet.asInstanceOf[Set[IRelationRole]]
+          }
+          //if we find a role that works than we can not add this natural to the results
+          roles.foreach(r => {
+            val outerRelComp = r.getOuterCompartment()
+            //println("COMP: " + outerRelComp + " " + playerQueryRel + " " + playerQueryRel.getClass.isInstance(outerRelComp))
+            if (playerQueryRel.getClass.isInstance(outerRelComp)) {
+              //we can not use this element
+              goodElement = false
+            }
+          })
+          //if we do not find a compatible element in this natural role we can add it
+          if (goodElement) {
+            var queryNatRole: NaturalQueryObject = null
+            if (queryRel.source.negated) {
+              queryNatRole = queryRel.target
+            } else {
+              queryNatRole = queryRel.source
+            }
+            var queryNatResult: NaturalQueryResult = getNatResultRole(rsumNat, queryNatRole)
+            if (queryNatResult == null) {
+              queryNatResult = new NaturalQueryResult(queryNatRole)
+              rsumNat play queryNatResult
+              queryNatResults += queryNatResult
+            }
+            if (queryRel.source.negated) {
+              queryNatResult.increaseTargetNegated()
+            } else {
+              queryNatResult.increaseSourceNegated()
+            }
+          }
+        }
+      })
+    })
+
+    //...iterate over all query naturals without a connection and add result roles if necessary
+    queryNatRoles.filter(_.connectionSize == 0).foreach(queryNat => {
+      //connected one are visited in the part before
+      val playerQueryNat: Object = queryNat.player.right.get
+      RsumCompartment.getNaturals().foreach(rsumNat => {
+        if (playerQueryNat.isInstanceOf[QueryHelper]) {
+          if (playerQueryNat.equals(rsumNat)) {
+            var queryNatResult: NaturalQueryResult = getNatResultRole(rsumNat, queryNat)
+            if (queryNatResult == null) {
+              queryNatResult = new NaturalQueryResult(queryNat)
+              rsumNat play queryNatResult
+              queryNatResults += queryNatResult
+            }
+          }
+        } else {
+          if (playerQueryNat.getClass.isInstance(rsumNat)) {
+            var queryNatResult: NaturalQueryResult = getNatResultRole(rsumNat, queryNat)
+            if (queryNatResult == null) {
+              queryNatResult = new NaturalQueryResult(queryNat)
+              rsumNat play queryNatResult
+              queryNatResults += queryNatResult
+            }
+          }
+        }
+      })
+    })
+
+    //###proof correctness of results
+    //...proof attribute correctness once
+    queryNatResults.filter(!_.proofAttributes).foreach(deleteNatResults += _)
+    //delete them
+    deleteNatResults.foreach(queryResultNat => {
+      queryNatResults -= queryResultNat
+      forDeletionQueryResults += queryResultNat
+      queryResultNat.removeConnections()
+    })
+
+    //...proof the correctness of the query results and delete non correct ones
+    while (doSomething) {
+      deleteNatResults = Set.empty
+      //proof the connection correctness
+      queryNatResults.filter(!_.proofConnections).foreach(deleteNatResults += _)
+
+      //do as long as everything is correct
+      doSomething = !deleteNatResults.isEmpty
+      //delete them
+      deleteNatResults.foreach(queryResultNat => {
+        queryNatResults -= queryResultNat
+        forDeletionQueryResults += queryResultNat
+        queryResultNat.removeConnections()
+      })
+    }
+
+    //###make good outputs from the current query results
+    //...only correct elements should now play result roles and are in the list    
+    var combinedResult: Set[CombinedQueryResult] = queryRelResults.filter(!_.transitive).map(_.createCombinedResult())
+
+    //...combine the result elements to good output units
+    doSomething = true
+    while (doSomething) {
+      doSomething = false
+      combinedResult.foreach(combined => {
+        queryRelResults.foreach(rel => {
+          if (rel.source == combined.target && !combined.contains(rel.target)) {
+            //add in the back
+            combined.addBack(rel.target)
+            doSomething = true
+          } else {
+            if (rel.target == combined.source && !combined.contains(rel.source)) {
+              //add in the front
+              combined.addFront(rel.source)
+              doSomething = true
+            }
+          }
+        })
+      })
+      //delete duplicated elements
+      combinedResult = combinedResult.groupBy(_.getBetween).map(_._2.head).toSet
+      //combinedResult.distinct
+    }
+
+    //create only results with tuples
+    /*queryRelResults.foreach(rel => {
+      var rSet: Set[Object] = Set.empty
+      if (rel.source.connectedQueryObject.returned) {
+        rSet += rel.source.player.right.get
+      }
+      if (rel.target.connectedQueryObject.returned) {
+        rSet += rel.target.player.right.get
+      }
+      result += rSet
+    })*/
+
+    //...bring the output format to the reals one
+    combinedResult.foreach(combined => {
+      var rSet: Set[Object] = Set.empty
+      combined.getBetween.foreach(queryNat => {
+        if (queryNat.connectedQueryObject.returned) {
+          rSet += queryNat.player.right.get
+        }
+      })
+      result += rSet
+    })
+
+    //...add also single results
+    queryNatResults.foreach(queryResultNat => {
+      if (!queryResultNat.isConnected() && queryResultNat.connectedQueryObject.returned) {
+        result += Set(queryResultNat.player.right.get)
+      }
+    })
+
+    //...delete now really all not needed result roles 
+    forDeletionQueryResults.foreach(_.remove())
+
+    return result
+  }
+
+  override def toString(): String = name + ": " + isQueryCorrect + " Rs: " + queryNatRoles + " " + queryRelRoles
+
+  /**
+   * Query object specialized for naturals in the RSUM.
+   */
+  class NaturalQueryObject() extends QueryObject() {
+    private var sourceRelations: Set[RelationalQueryObject] = Set.empty
+    private var targetRelations: Set[RelationalQueryObject] = Set.empty
+
+    def addSourceRelation(rel: RelationalQueryObject): Unit = {
+      sourceRelations += rel
+    }
+
+    def removeSourceRelation(rel: RelationalQueryObject): Unit = {
+      sourceRelations -= rel
+    }
+
+    def getSourceRelationsSize(): Int = sourceRelations.filter(!_.isNegated()).map(_.multiTarget).sum //sum up multi value not use size
+    def getNegatedSourceRelationsSize(): Int = sourceRelations.filter(_.isNegated()).size
+
+    def addTargetRelation(rel: RelationalQueryObject): Unit = {
+      targetRelations += rel
+    }
+
+    def removeTargetRelation(rel: RelationalQueryObject): Unit = {
+      targetRelations -= rel
+    }
+
+    def getTargetRelationsSize(): Int = targetRelations.filter(!_.isNegated()).map(_.multiSource).sum
+    def getNegatedTargetRelationsSize(): Int = targetRelations.filter(_.isNegated()).size
+
+    def connectionSize(): Int = targetRelations.size + sourceRelations.size
+
+    def overallConnectionUnit(): Int = {
+      var visitedRel: Set[RelationalQueryObject] = Set.empty
+      var visitedNat: Set[NaturalQueryObject] = Set(this)
+      var unVisitedRel: Set[RelationalQueryObject] = targetRelations ++ sourceRelations
+      var unVisitedNat: Set[NaturalQueryObject] = Set.empty
+      while (!unVisitedRel.isEmpty || !unVisitedNat.isEmpty) {
+        //run over all unvisited relations 
+        unVisitedRel.foreach(rel => {
+          if (!visitedNat.contains(rel.source))
+            unVisitedNat += rel.source
+          if (!visitedNat.contains(rel.target))
+            unVisitedNat += rel.target
+        })
+        visitedRel ++= unVisitedRel
+        unVisitedRel = Set.empty
+        //run over all unvisited naturals 
+        unVisitedNat.foreach(nat => {
+          nat.sourceRelations.filter(!visitedRel.contains(_)).foreach(unVisitedRel += _)
+          nat.targetRelations.filter(!visitedRel.contains(_)).foreach(unVisitedRel += _)
+        })
+        visitedNat ++= unVisitedNat
+        unVisitedNat = Set.empty
+      }
+      return visitedRel.size + visitedNat.size
+    }
+
+    override def toString: String = "QON: " + label + " C: " + connectionSize
+  }
+
+  /**
+   * Query object specialized for relational compartments in the RSUM.
+   */
+  class RelationalQueryObject(val source: NaturalQueryObject, val target: NaturalQueryObject) extends QueryObject() {
+
+    def isReturned(): Boolean = source.returned && target.returned
+    def isNegated(): Boolean = source.negated || target.negated
+    def isTransitive(): Boolean = target.transitive
+    def multiTarget(): Int = target.multi
+    def multiSource(): Int = source.multi
+
+    source.addSourceRelation(this)
+    target.addTargetRelation(this)
+
+    def overallConnectionUnit(): Int = source.overallConnectionUnit()
+
+    override def toString: String = "QOR: " + source.label + "-" + target.label
+  }
+
+  /**
+   * Query result roles for natural query roles.
+   */
+  class NaturalQueryResult(val connectedQueryObject: NaturalQueryObject) extends QueryResult(connectedQueryObject) {
+    private var sourceRelations: Set[RelationalQueryResult] = Set.empty
+    private var targetRelations: Set[RelationalQueryResult] = Set.empty
+
+    private var negatedSources: Int = 0
+    private var negatedTargets: Int = 0
+
+    def increaseSourceNegated(): Unit = { negatedSources += 1 }
+    def decreaseSourceNegated(): Unit = { negatedSources -= 1 }
+
+    def increaseTargetNegated(): Unit = { negatedTargets += 1 }
+    def decreaseTargetNegated(): Unit = { negatedTargets -= 1 }
+
+    /**
+     * Proof if the player has all the necessary attributes with its values.
+     */
+    def proofAttributes(): Boolean = {
+      val player: Object = this.player.right.get
+      var returnValue = true
+      connectedQueryObject.getAttributeFilters.foreach(a => {
+        try {
+          //player.getClass.getMethods.foreach(f => println(f.toString))
+          //println(player.getClass.getMethod("name").getReturnType) //getName
+          val met = player.getClass.getMethod(a.attributeName)
+          val result: String = met.invoke(player).asInstanceOf[String]
+          a.checking match {
+            case CheckingOption.equalsCheck => if (result != a.value) returnValue = false
+            case CheckingOption.biggerThan  => if (result <= a.value) returnValue = false
+            case CheckingOption.smallerThan => if (result >= a.value) returnValue = false
+            case _                          =>
+          }
+        } catch {
+          case _: Throwable => {
+            println("!!! No attribute with this name!!!")
+            return false
+          }
+        }
+      })
+      return returnValue
+    }
+
+    /**
+     * Proof if the number of connections is equals to the related query object.
+     */
+    def proofConnections(): Boolean = {
+      //TODO: proof also the number of types and not only the numbers
+      //println("S: " + _connectedQueryObject.getSourceRelationsSize() + " T: " + _connectedQueryObject.getTargetRelationsSize() + " NS: " + _connectedQueryObject.getNegatedSourceRelationsSize() + " NT: " + _connectedQueryObject.getNegatedTargetRelationsSize() + " Con: " + _connectedQueryObject)
+      //println("S: " + getSourceRelationsSize() + " T: " + getTargetRelationsSize() + " NS: " + negatedSources + " NT: " + negatedTargets + " This: " + this)
+      if (getSourceRelationsSize >= connectedQueryObject.getSourceRelationsSize()
+        && getTargetRelationsSize >= connectedQueryObject.getTargetRelationsSize()
+        && negatedSources >= connectedQueryObject.getNegatedSourceRelationsSize()
+        && negatedTargets >= connectedQueryObject.getNegatedTargetRelationsSize()) {
+        return true
+      }
+      return false
+    }
+
+    def addSourceRelation(rel: RelationalQueryResult): Unit = {
+      sourceRelations += rel
+    }
+
+    def removeSourceRelation(rel: RelationalQueryResult): Unit = {
+      sourceRelations -= rel
+    }
+
+    def getSourceRelationsSize(): Int = sourceRelations.size
+
+    def addTargetRelation(rel: RelationalQueryResult): Unit = {
+      targetRelations += rel
+    }
+
+    def removeTargetRelation(rel: RelationalQueryResult): Unit = {
+      targetRelations -= rel
+    }
+
+    def getTargetRelationsSize(): Int = targetRelations.size
+
+    def isConnected(): Boolean = (targetRelations.size + sourceRelations.size) > 0
+
+    def removeConnections(): Unit = {
+      sourceRelations.foreach(rel => {
+        rel.target.removeTargetRelation(rel)
+        queryRelResults -= rel
+        rel.remove()
+      })
+      targetRelations.foreach(rel => {
+        rel.source.removeSourceRelation(rel)
+        queryRelResults -= rel
+        rel.remove()
+      })
+      sourceRelations = Set.empty
+      targetRelations = Set.empty
+      negatedSources = 0
+      negatedTargets = 0
+    }
+  }
+
+  /**
+   * Query result roles for relation query roles.
+   */
+  class RelationalQueryResult(val connectedQueryObject: RelationalQueryObject, val source: NaturalQueryResult, val target: NaturalQueryResult, val transitive: Boolean) extends QueryResult(connectedQueryObject) {
+    //only add this relation to the connect results if it is not transitive
+    if (!transitive) {
+      source.addSourceRelation(this)
+      target.addTargetRelation(this)
+    }
+
+    /**
+     * Create a new combined result which is a copy of this one.
+     */
+    def createCombinedResult(): CombinedQueryResult = new CombinedQueryResult(source, target)
+  }
+
+  /**
+   * Helper class to connect the results to a chain.
+   */
+  class CombinedQueryResult(var source: NaturalQueryResult, var target: NaturalQueryResult) {
+
+    //list of all query results that are connected
+    private var between: Seq[NaturalQueryResult] = Seq(source, target)
+
+    def getBetween(): Seq[NaturalQueryResult] = between
+
+    def addFront(newIn: NaturalQueryResult): Unit = {
+      between = newIn +: between
+      source = newIn
+    }
+
+    def addBack(newIn: NaturalQueryResult): Unit = {
+      between = between :+ newIn
+      target = newIn
+    }
+
+    def contains(result: NaturalQueryResult): Boolean = (between.contains(result))
+
+    private def getSize(): Int = between.size
+
+    protected def canEqual(other: Any): Boolean = other.isInstanceOf[CombinedQueryResult]
+
+    override def equals(other: Any): Boolean = other match {
+      case that: CombinedQueryResult => {
+        if (that canEqual this) {
+          between.foreach(b => {
+            if (!that.contains(b))
+              return false
+          })
+          return that.getSize == this.getSize()
+        } else {
+          return false
+        }
+      }
+      case _ => return false
+    }
+
+    override def toString(): String = "QCR: (" + between + ")"
+  }
+}
\ No newline at end of file
diff --git a/src/main/scala/query/AMLLanguageQuery.scala b/src/main/scala/query/AMLLanguageQuery.scala
index a13b9fb58753bb73668282ba75ab97b4aa802fdf..82595553c2a32951dbf9948dfa508b61e9685cad 100644
--- a/src/main/scala/query/AMLLanguageQuery.scala
+++ b/src/main/scala/query/AMLLanguageQuery.scala
@@ -5,7 +5,7 @@ import aml.InternalElement
 import aml.SystemUnitClassAttributesAttribute
 import aml.CAEXObject
 import aml.Attribute
-import org.rosi_project.model_management.sum.query.IQueryViewCompartment
+import org.rosi_project.model_management.sum.query.QueryFactory
 import aml.InstanceHierarchyInternalElementsInternalElement
 import aml.InternalElementBaseSystemUnitSystemUnitClass
 import aml.HelperCAEXObject
@@ -13,7 +13,7 @@ import aml.InstanceHierarchy
 import org.rosi_project.model_management.sum.query.CheckingOption
 import aml.SystemUnitClass
 
-class AMLLanguageQuery extends IQueryViewCompartment {
+class AMLLanguageQuery extends QueryFactory {
 
   init("AMLLanguageQuery")
 
@@ -79,7 +79,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
     }
 
     def addInternalElements(v: AMLLanguageQuery#InternalElementRole): Boolean = {
-      if (hasInternalElements(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasInternalElements(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new SystemUnitClassInternalElementsInternalElementRole(this, v)
       return true
     }
@@ -114,7 +114,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
     }
 
     def addAttributes(v: AMLLanguageQuery#AttributeRole): Boolean = {
-      if (hasAttributes(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasAttributes(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new SystemUnitClassAttributesAttributeRole(this, v)
       return true
     }
@@ -201,7 +201,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
     }
 
     def addInternalElements(v: AMLLanguageQuery#InternalElementRole): Boolean = {
-      if (hasInternalElements(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasInternalElements(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new InstanceHierarchyInternalElementsInternalElementRole(this, v)
       return true
     }
@@ -223,7 +223,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
   }
 
-  class CAEXObjectRole extends AQueryViewRole {
+  class CAEXObjectRole extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return false
@@ -292,7 +292,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
     def setBaseSystemUnit(v: AMLLanguageQuery#SystemUnitClassRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (baseSystemUnit != null) {
         if (baseSystemUnit.getTarget() == v) return false
         baseSystemUnit.deleteElement()
@@ -307,7 +307,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
   }
 
-  class SystemUnitClassInternalElementsInternalElementRole(private val source: AMLLanguageQuery#SystemUnitClassRole, private val target: AMLLanguageQuery#InternalElementRole) extends AQueryViewRole {
+  class SystemUnitClassInternalElementsInternalElementRole(private val source: AMLLanguageQuery#SystemUnitClassRole, private val target: AMLLanguageQuery#InternalElementRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -340,7 +340,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
   }
 
-  class SystemUnitClassAttributesAttributeRole(private val source: AMLLanguageQuery#SystemUnitClassRole, private val target: AMLLanguageQuery#AttributeRole) extends AQueryViewRole {
+  class SystemUnitClassAttributesAttributeRole(private val source: AMLLanguageQuery#SystemUnitClassRole, private val target: AMLLanguageQuery#AttributeRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -373,7 +373,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
   }
 
-  class InstanceHierarchyInternalElementsInternalElementRole(private val source: AMLLanguageQuery#InstanceHierarchyRole, private val target: AMLLanguageQuery#InternalElementRole) extends AQueryViewRole {
+  class InstanceHierarchyInternalElementsInternalElementRole(private val source: AMLLanguageQuery#InstanceHierarchyRole, private val target: AMLLanguageQuery#InternalElementRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -406,7 +406,7 @@ class AMLLanguageQuery extends IQueryViewCompartment {
 
   }
 
-  class InternalElementBaseSystemUnitSystemUnitClassRole(private val source: AMLLanguageQuery#InternalElementRole, private val target: AMLLanguageQuery#SystemUnitClassRole) extends AQueryViewRole {
+  class InternalElementBaseSystemUnitSystemUnitClassRole(private val source: AMLLanguageQuery#InternalElementRole, private val target: AMLLanguageQuery#SystemUnitClassRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
diff --git a/src/main/scala/query/EclipseLibraryQuery.scala b/src/main/scala/query/EclipseLibraryQuery.scala
index 344278b2a7816b09eac9556650287d0ade5b0392..a4bf962048928b8c9ae32faf0abb5d5fd21521c9 100644
--- a/src/main/scala/query/EclipseLibraryQuery.scala
+++ b/src/main/scala/query/EclipseLibraryQuery.scala
@@ -14,7 +14,7 @@ import elib.LibraryParentBranchLibrary
 import elib.Periodical
 import elib.Writer
 import elib.AudioVisualItem
-import org.rosi_project.model_management.sum.query.IQueryViewCompartment
+import org.rosi_project.model_management.sum.query.QueryFactory
 import elib.EmployeeManagerEmployee
 import elib.Person
 import java.util.Date
@@ -29,7 +29,7 @@ import elib.CirculatingItem
 import elib.Item
 import elib.LibraryStockItem
 
-class EclipseLibraryQuery extends IQueryViewCompartment {
+class EclipseLibraryQuery extends QueryFactory {
 
   init("EclipseLibraryQuery")
 
@@ -85,7 +85,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     "EclipseLibraryQuery:"
   }
 
-  class ItemRole extends AQueryViewRole {
+  class ItemRole extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return false
@@ -145,7 +145,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
     def setManager(v: EclipseLibraryQuery#EmployeeRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (manager != null) {
         if (manager.getTarget() == v) return false
         manager.deleteElement()
@@ -234,7 +234,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addCast(v: EclipseLibraryQuery#PersonRole): Boolean = {
-      if (hasCast(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasCast(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new VideoCassetteCastPersonRole(this, v)
       return true
     }
@@ -348,7 +348,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addBooks(v: EclipseLibraryQuery#BookRole): Boolean = {
-      if (hasBooks(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasBooks(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new BookAuthorWriterRole(v, this)
       return true
     }
@@ -428,7 +428,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
     def setAuthor(v: EclipseLibraryQuery#WriterRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (author != null) {
         if (author.getTarget() == v) return false
         author.deleteElement()
@@ -443,7 +443,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryRole extends AQueryViewRole {
+  class LibraryRole extends QueryFactoryElement {
 
     private var employees: Set[EclipseLibraryQuery#LibraryEmployeesEmployeeRole] = Set.empty
     private var parentBranch: EclipseLibraryQuery#LibraryParentBranchLibraryRole = null
@@ -500,7 +500,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addEmployees(v: EclipseLibraryQuery#EmployeeRole): Boolean = {
-      if (hasEmployees(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasEmployees(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryEmployeesEmployeeRole(this, v)
       return true
     }
@@ -530,7 +530,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
     def setParentBranch(v: EclipseLibraryQuery#LibraryRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (parentBranch != null) {
         if (parentBranch.getTarget() == v) return false
         parentBranch.deleteElement()
@@ -558,7 +558,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addWriters(v: EclipseLibraryQuery#WriterRole): Boolean = {
-      if (hasWriters(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasWriters(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryWritersWriterRole(this, v)
       return true
     }
@@ -593,7 +593,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addBorrowers(v: EclipseLibraryQuery#BorrowerRole): Boolean = {
-      if (hasBorrowers(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasBorrowers(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryBorrowersBorrowerRole(this, v)
       return true
     }
@@ -628,7 +628,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addStock(v: EclipseLibraryQuery#ItemRole): Boolean = {
-      if (hasStock(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasStock(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryStockItemRole(this, v)
       return true
     }
@@ -663,7 +663,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addBranches(v: EclipseLibraryQuery#LibraryRole): Boolean = {
-      if (hasBranches(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasBranches(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryBranchesLibraryRole(this, v)
       return true
     }
@@ -698,7 +698,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
     }
 
     def addBooks(v: EclipseLibraryQuery#BookRole): Boolean = {
-      if (hasBooks(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasBooks(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryBooksBookRole(this, v)
       return true
     }
@@ -753,7 +753,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
     def setAuthor(v: EclipseLibraryQuery#WriterRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (author != null) {
         if (author.getTarget() == v) return false
         author.deleteElement()
@@ -776,7 +776,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
     def setReader(v: EclipseLibraryQuery#PersonRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (reader != null) {
         if (reader.getTarget() == v) return false
         reader.deleteElement()
@@ -831,7 +831,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class PersonRole extends AQueryViewRole {
+  class PersonRole extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return false
@@ -869,7 +869,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryEmployeesEmployeeRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#EmployeeRole) extends AQueryViewRole {
+  class LibraryEmployeesEmployeeRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#EmployeeRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -902,7 +902,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryParentBranchLibraryRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#LibraryRole) extends AQueryViewRole {
+  class LibraryParentBranchLibraryRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#LibraryRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -935,7 +935,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryWritersWriterRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#WriterRole) extends AQueryViewRole {
+  class LibraryWritersWriterRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#WriterRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -968,7 +968,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class BookOnTapeAuthorWriterRole(private val source: EclipseLibraryQuery#BookOnTapeRole, private val target: EclipseLibraryQuery#WriterRole) extends AQueryViewRole {
+  class BookOnTapeAuthorWriterRole(private val source: EclipseLibraryQuery#BookOnTapeRole, private val target: EclipseLibraryQuery#WriterRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1001,7 +1001,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class BookOnTapeReaderPersonRole(private val source: EclipseLibraryQuery#BookOnTapeRole, private val target: EclipseLibraryQuery#PersonRole) extends AQueryViewRole {
+  class BookOnTapeReaderPersonRole(private val source: EclipseLibraryQuery#BookOnTapeRole, private val target: EclipseLibraryQuery#PersonRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1034,7 +1034,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryBorrowersBorrowerRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#BorrowerRole) extends AQueryViewRole {
+  class LibraryBorrowersBorrowerRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#BorrowerRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1067,7 +1067,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryStockItemRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#ItemRole) extends AQueryViewRole {
+  class LibraryStockItemRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#ItemRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1100,7 +1100,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class BookAuthorWriterRole(private val source: EclipseLibraryQuery#BookRole, private val target: EclipseLibraryQuery#WriterRole) extends AQueryViewRole {
+  class BookAuthorWriterRole(private val source: EclipseLibraryQuery#BookRole, private val target: EclipseLibraryQuery#WriterRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1135,7 +1135,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryBranchesLibraryRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#LibraryRole) extends AQueryViewRole {
+  class LibraryBranchesLibraryRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#LibraryRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1168,7 +1168,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class VideoCassetteCastPersonRole(private val source: EclipseLibraryQuery#VideoCassetteRole, private val target: EclipseLibraryQuery#PersonRole) extends AQueryViewRole {
+  class VideoCassetteCastPersonRole(private val source: EclipseLibraryQuery#VideoCassetteRole, private val target: EclipseLibraryQuery#PersonRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1201,7 +1201,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class EmployeeManagerEmployeeRole(private val source: EclipseLibraryQuery#EmployeeRole, private val target: EclipseLibraryQuery#EmployeeRole) extends AQueryViewRole {
+  class EmployeeManagerEmployeeRole(private val source: EclipseLibraryQuery#EmployeeRole, private val target: EclipseLibraryQuery#EmployeeRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -1234,7 +1234,7 @@ class EclipseLibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryBooksBookRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#BookRole) extends AQueryViewRole {
+  class LibraryBooksBookRole(private val source: EclipseLibraryQuery#LibraryRole, private val target: EclipseLibraryQuery#BookRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
diff --git a/src/main/scala/query/IMDBdatabaseQuery.scala b/src/main/scala/query/IMDBdatabaseQuery.scala
index 12c15eeb6de771f2d6aa8171d3ad013c55e75951..52acbe1ed6416766f48e54d47167e94972e8c403 100644
--- a/src/main/scala/query/IMDBdatabaseQuery.scala
+++ b/src/main/scala/query/IMDBdatabaseQuery.scala
@@ -9,7 +9,7 @@ import imdbdatabase.IMDBVotesVote
 import imdbdatabase.VoteUserUser
 import imdbdatabase.FigurePlayedByActor
 import imdbdatabase.Person
-import org.rosi_project.model_management.sum.query.IQueryViewCompartment
+import org.rosi_project.model_management.sum.query.QueryFactory
 import imdbdatabase.IMDB
 import imdbdatabase.Figure
 import imdbdatabase.Actor
@@ -18,7 +18,7 @@ import imdbdatabase.Vote
 import imdbdatabase.IMDBUsersUser
 import imdbdatabase.IMDBActorsActor
 
-class IMDBdatabaseQuery extends IQueryViewCompartment {
+class IMDBdatabaseQuery extends QueryFactory {
 
   init("IMDBdatabaseQuery")
 
@@ -54,7 +54,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     "IMDBdatabaseQuery:"
   }
 
-  class IMDBRole extends AQueryViewRole {
+  class IMDBRole extends QueryFactoryElement {
 
     private var users: Set[IMDBdatabaseQuery#IMDBUsersUserRole] = Set.empty
     private var votes: Set[IMDBdatabaseQuery#IMDBVotesVoteRole] = Set.empty
@@ -96,7 +96,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addUsers(v: IMDBdatabaseQuery#UserRole): Boolean = {
-      if (hasUsers(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasUsers(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new IMDBUsersUserRole(this, v)
       return true
     }
@@ -131,7 +131,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addVotes(v: IMDBdatabaseQuery#VoteRole): Boolean = {
-      if (hasVotes(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasVotes(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new IMDBVotesVoteRole(this, v)
       return true
     }
@@ -166,7 +166,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addActors(v: IMDBdatabaseQuery#ActorRole): Boolean = {
-      if (hasActors(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasActors(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new IMDBActorsActorRole(this, v)
       return true
     }
@@ -201,7 +201,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addFilms(v: IMDBdatabaseQuery#FilmRole): Boolean = {
-      if (hasFilms(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasFilms(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new IMDBFilmsFilmRole(this, v)
       return true
     }
@@ -223,7 +223,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class FilmRole extends AQueryViewRole {
+  class FilmRole extends QueryFactoryElement {
 
     private var library: IMDBdatabaseQuery#IMDBFilmsFilmRole = null
     private var votes: Set[IMDBdatabaseQuery#VoteFilmFilmRole] = Set.empty
@@ -276,7 +276,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setLibrary(v: IMDBdatabaseQuery#IMDBRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (library != null) {
         if (library.getSource() == v) return false
         library.deleteElement()
@@ -304,7 +304,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addVotes(v: IMDBdatabaseQuery#VoteRole): Boolean = {
-      if (hasVotes(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasVotes(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new VoteFilmFilmRole(v, this)
       return true
     }
@@ -339,7 +339,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addFigures(v: IMDBdatabaseQuery#FigureRole): Boolean = {
-      if (hasFigures(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasFigures(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new FilmFiguresFigureRole(this, v)
       return true
     }
@@ -361,7 +361,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class VoteRole extends AQueryViewRole {
+  class VoteRole extends QueryFactoryElement {
 
     private var user: IMDBdatabaseQuery#VoteUserUserRole = null
     private var library: IMDBdatabaseQuery#IMDBVotesVoteRole = null
@@ -405,7 +405,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setUser(v: IMDBdatabaseQuery#UserRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (user != null) {
         if (user.getTarget() == v) return false
         user.deleteElement()
@@ -428,7 +428,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setLibrary(v: IMDBdatabaseQuery#IMDBRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (library != null) {
         if (library.getSource() == v) return false
         library.deleteElement()
@@ -451,7 +451,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setFilm(v: IMDBdatabaseQuery#FilmRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (film != null) {
         if (film.getTarget() == v) return false
         film.deleteElement()
@@ -504,7 +504,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addPlays(v: IMDBdatabaseQuery#FigureRole): Boolean = {
-      if (hasPlays(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasPlays(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new FigurePlayedByActorRole(v, this)
       return true
     }
@@ -534,7 +534,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setLibrary(v: IMDBdatabaseQuery#IMDBRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (library != null) {
         if (library.getSource() == v) return false
         library.deleteElement()
@@ -549,7 +549,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class PersonRole extends AQueryViewRole {
+  class PersonRole extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return false
@@ -587,7 +587,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class FigureRole extends AQueryViewRole {
+  class FigureRole extends QueryFactoryElement {
 
     private var playedBy: Set[IMDBdatabaseQuery#FigurePlayedByActorRole] = Set.empty
     private var film: IMDBdatabaseQuery#FilmFiguresFigureRole = null
@@ -634,7 +634,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
     }
 
     def addPlayedBy(v: IMDBdatabaseQuery#ActorRole): Boolean = {
-      if (hasPlayedBy(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasPlayedBy(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new FigurePlayedByActorRole(this, v)
       return true
     }
@@ -664,7 +664,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setFilm(v: IMDBdatabaseQuery#FilmRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (film != null) {
         if (film.getSource() == v) return false
         film.deleteElement()
@@ -728,7 +728,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
     def setLibrary(v: IMDBdatabaseQuery#IMDBRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (library != null) {
         if (library.getSource() == v) return false
         library.deleteElement()
@@ -743,7 +743,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class FigurePlayedByActorRole(private val source: IMDBdatabaseQuery#FigureRole, private val target: IMDBdatabaseQuery#ActorRole) extends AQueryViewRole {
+  class FigurePlayedByActorRole(private val source: IMDBdatabaseQuery#FigureRole, private val target: IMDBdatabaseQuery#ActorRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -778,7 +778,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class VoteUserUserRole(private val source: IMDBdatabaseQuery#VoteRole, private val target: IMDBdatabaseQuery#UserRole) extends AQueryViewRole {
+  class VoteUserUserRole(private val source: IMDBdatabaseQuery#VoteRole, private val target: IMDBdatabaseQuery#UserRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -811,7 +811,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class IMDBUsersUserRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#UserRole) extends AQueryViewRole {
+  class IMDBUsersUserRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#UserRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -846,7 +846,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class IMDBVotesVoteRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#VoteRole) extends AQueryViewRole {
+  class IMDBVotesVoteRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#VoteRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -881,7 +881,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class IMDBActorsActorRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#ActorRole) extends AQueryViewRole {
+  class IMDBActorsActorRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#ActorRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -916,7 +916,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class IMDBFilmsFilmRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#FilmRole) extends AQueryViewRole {
+  class IMDBFilmsFilmRole(private val source: IMDBdatabaseQuery#IMDBRole, private val target: IMDBdatabaseQuery#FilmRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -951,7 +951,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class VoteFilmFilmRole(private val source: IMDBdatabaseQuery#VoteRole, private val target: IMDBdatabaseQuery#FilmRole) extends AQueryViewRole {
+  class VoteFilmFilmRole(private val source: IMDBdatabaseQuery#VoteRole, private val target: IMDBdatabaseQuery#FilmRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -986,7 +986,7 @@ class IMDBdatabaseQuery extends IQueryViewCompartment {
 
   }
 
-  class FilmFiguresFigureRole(private val source: IMDBdatabaseQuery#FilmRole, private val target: IMDBdatabaseQuery#FigureRole) extends AQueryViewRole {
+  class FilmFiguresFigureRole(private val source: IMDBdatabaseQuery#FilmRole, private val target: IMDBdatabaseQuery#FigureRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
diff --git a/src/main/scala/query/LibraryQuery.scala b/src/main/scala/query/LibraryQuery.scala
index 809b0f1b1bba06a2c67bc61e9bbade9585b86c9c..4de34bd4b74267b4916649124273123e053e3c4c 100644
--- a/src/main/scala/query/LibraryQuery.scala
+++ b/src/main/scala/query/LibraryQuery.scala
@@ -5,11 +5,11 @@ import lib.Library
 import lib.HelperPerson
 import lib.Person
 import lib.LibraryEmployeesEmployee
-import org.rosi_project.model_management.sum.query.IQueryViewCompartment
+import org.rosi_project.model_management.sum.query.QueryFactory
 import lib.Employee
 import org.rosi_project.model_management.sum.query.CheckingOption
 
-class LibraryQuery extends IQueryViewCompartment {
+class LibraryQuery extends QueryFactory {
 
   init("LibraryQuery")
 
@@ -29,7 +29,7 @@ class LibraryQuery extends IQueryViewCompartment {
     "LibraryQuery:"
   }
 
-  class LibraryRole extends AQueryViewRole {
+  class LibraryRole extends QueryFactoryElement {
 
     private var employees: Set[LibraryQuery#LibraryEmployeesEmployeeRole] = Set.empty
 
@@ -74,7 +74,7 @@ class LibraryQuery extends IQueryViewCompartment {
     }
 
     def addEmployees(v: LibraryQuery#EmployeeRole): Boolean = {
-      if (hasEmployees(v) || !containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (hasEmployees(v) || !containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       new LibraryEmployeesEmployeeRole(this, v)
       return true
     }
@@ -136,7 +136,7 @@ class LibraryQuery extends IQueryViewCompartment {
 
     def setManager(v: LibraryQuery#EmployeeRole): Boolean = {
       if (v == null) return false
-      if (!containsRole(v.asInstanceOf[AQueryViewRole])) return false
+      if (!containsRole(v.asInstanceOf[QueryFactoryElement])) return false
       if (manager != null) {
         if (manager.getTarget() == v) return false
         manager.deleteElement()
@@ -151,7 +151,7 @@ class LibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class PersonRole extends AQueryViewRole {
+  class PersonRole extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return false
@@ -180,7 +180,7 @@ class LibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class LibraryEmployeesEmployeeRole(private val source: LibraryQuery#LibraryRole, private val target: LibraryQuery#EmployeeRole) extends AQueryViewRole {
+  class LibraryEmployeesEmployeeRole(private val source: LibraryQuery#LibraryRole, private val target: LibraryQuery#EmployeeRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true
@@ -213,7 +213,7 @@ class LibraryQuery extends IQueryViewCompartment {
 
   }
 
-  class EmployeeManagerEmployeeRole(private val source: LibraryQuery#EmployeeRole, private val target: LibraryQuery#EmployeeRole) extends AQueryViewRole {
+  class EmployeeManagerEmployeeRole(private val source: LibraryQuery#EmployeeRole, private val target: LibraryQuery#EmployeeRole) extends QueryFactoryElement {
 
     override protected def isRelational(): Boolean = {
       return true