From e40def60eec1abd0a3a9382b3b0b3d64723fee74 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Mon, 29 May 2017 15:04:37 +0300 Subject: [PATCH] Fixes to variable implementations refs #7251 Change-Id: Ideebcc4caca35339544554c287cccb2107caced3 --- .../variable/ConstantPropertyVariable.java | 29 ++++++++++++++----- .../variable/StandardGraphChildVariable.java | 8 +++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantPropertyVariable.java index b3eaf7e21..14db2cbfe 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantPropertyVariable.java @@ -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 properties; + final private Resource predicate; - public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection propertyBuilders, Set classifications) { + public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Resource predicate, Collection propertyBuilders, Set 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(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.emptyList(), Collections.emptySet()); + public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding, Collection propertyBuilders, Set classifications) { + this(parent, name, value, binding, null, Collections.emptyList(), Collections.emptySet()); } + public ConstantPropertyVariable(Variable parent, String name, Object value, Binding binding) { + this(parent, name, value, binding, Collections.emptyList(), Collections.emptySet()); + } + @Override public 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 ps = new HashMap(); + 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(this.properties.size()); properties.putAll(this.properties); } + if(predicate != null) All.collectPropertiesFromContext(graph, this, predicate, properties); return properties; } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java index af8f75c49..17fc21ebb 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java @@ -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; -- 2.47.1