]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixes to variable implementations 68/568/2
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 29 May 2017 12:04:37 +0000 (15:04 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Tue, 30 May 2017 05:02:50 +0000 (08:02 +0300)
refs #7251

Change-Id: Ideebcc4caca35339544554c287cccb2107caced3

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantPropertyVariable.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java

index b3eaf7e21de713826d2f08ffc1ac83899ded1638..14db2cbfed491e3209e14aceaa33d75717c44469 100644 (file)
@@ -12,6 +12,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.function.All;
 import org.simantics.utils.ObjectUtils;
 
 public class ConstantPropertyVariable extends AbstractPropertyVariable {
@@ -21,26 +22,32 @@ public class ConstantPropertyVariable extends AbstractPropertyVariable {
     final Object value;
     final Binding binding;
     final Map<String, Variable> properties;
+    final private Resource predicate;
 
-    public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
+    public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Resource predicate, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
         assert parent != null;
         assert name != null;
         this.parent = parent;
         this.name = name;
         this.value = value;
         this.binding = binding;
+        this.predicate = predicate;
         this.properties = new HashMap<String, Variable>(propertyBuilders.size());
         for(ConstantPropertyVariableBuilder builder : propertyBuilders) {
-               properties.put(builder.getName(), builder.build(this));
+            properties.put(builder.getName(), builder.build(this));
         }
         if(!classifications.isEmpty())
-               properties.put(Variables.CLASSIFICATIONS, new ConstantPropertyVariable(this, Variables.CLASSIFICATIONS, classifications, null));
+            properties.put(Variables.CLASSIFICATIONS, new ConstantPropertyVariable(this, Variables.CLASSIFICATIONS, classifications, null));
     }
 
-    public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding) {
-       this(parent, name, value, binding, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
+    public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection<ConstantPropertyVariableBuilder> propertyBuilders, Set<String> classifications) {
+        this(parent, name, value, binding, null, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
     }
 
+    public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding) {
+        this(parent, name, value, binding, Collections.<ConstantPropertyVariableBuilder>emptyList(), Collections.<String>emptySet());
+    }
+  
     @Override
     public <T> T getValue(ReadGraph graph) throws DatabaseException {
         return (T)value;
@@ -105,7 +112,7 @@ public class ConstantPropertyVariable extends AbstractPropertyVariable {
     
     @Override
     public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {
-       return null;
+       return predicate;
     }
 
     @Override
@@ -121,7 +128,14 @@ public class ConstantPropertyVariable extends AbstractPropertyVariable {
     @Override
     protected Variable getPossibleDomainProperty(ReadGraph graph, String name)
                throws DatabaseException {
-       return properties.get(name);
+       Variable result = properties.get(name);
+       if(result != null) return result;
+       if(predicate != null) {
+               HashMap<String,Variable> ps = new HashMap<String,Variable>();
+               All.collectPropertiesFromContext(graph, this, predicate, ps);
+               return ps.get(name);
+       }
+       return null; 
     }
 
     @Override
@@ -131,6 +145,7 @@ public class ConstantPropertyVariable extends AbstractPropertyVariable {
                if(properties == null) properties = new HashMap<String,Variable>(this.properties.size());
                properties.putAll(this.properties);
        }
+       if(predicate != null) All.collectPropertiesFromContext(graph, this, predicate, properties);
        return properties;
     }
     
index af8f75c494dd242534373523bbdfb45d0b6f664f..17fc21ebb911bb2130ff3cd10c662f9a083b9162 100644 (file)
@@ -255,10 +255,12 @@ public class StandardGraphChildVariable extends AbstractChildVariable {
        return getClass().getSimpleName() + "[" + resource + "]";
     }
        
-       protected VariableMap getPossiblePropertyVariableMap(ReadGraph graph) throws DatabaseException {
+    protected VariableMap getPossiblePropertyVariableMap(ReadGraph graph) throws DatabaseException {
         if(resource == null) return All.standardChildDomainProperties;
-               return graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).domainProperties, this);
-       }
+        Resource domainProperties = Layer0.getInstance(graph).domainProperties; 
+        return graph.getPossibleRelatedValue2(resource, domainProperties, 
+            new StandardGraphPropertyVariable(graph, this, domainProperties));
+    }
 
        protected VariableMap getPossibleChildVariableMap(ReadGraph graph) throws DatabaseException {
            if(resource == null) return All.standardChildDomainChildren;