X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FIndexedInstances.java;h=09a1fc9021c77ee6440e93aeb84c87a68baf175d;hp=1177f3a30f984881b1bef0398687bf6802662850;hb=a52f0324c9435755d3da3f053794c077f7d58213;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/IndexedInstances.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/IndexedInstances.java index 1177f3a30..09a1fc902 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/IndexedInstances.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/IndexedInstances.java @@ -1,49 +1,50 @@ -package org.simantics.db.layer0.request; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceRead2; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.operation.Layer0X; -import org.simantics.scl.runtime.function.Function; - -public class IndexedInstances extends ResourceRead2> { - - public IndexedInstances(Resource type, Resource indexRoot) { - super(type, indexRoot); - } - - @Override - public Set perform(ReadGraph graph) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - - String typeName = graph.getRelatedValue(resource, L0.HasName); - - Function dependencies = graph.adapt(L0X.Dependencies, Function.class); - - Collection> results = (Collection>)dependencies.apply(graph, resource2, "Types:*" + typeName); - if (results == null) - return Collections.emptySet(); - - HashSet result = new HashSet(results.size()); - for(Map entry : results) { - Resource res = (Resource)entry.get("Resource"); - if(res != null) { - if (graph.isInstanceOf(res, resource)) - result.add(res); - } - } - return result; - - } - -} +package org.simantics.db.layer0.request; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.IndexQueries; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.scl.runtime.function.Function; + +public class IndexedInstances extends ResourceRead2> { + + public IndexedInstances(Resource type, Resource indexRoot) { + super(type, indexRoot); + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + + String typeName = graph.getRelatedValue(resource, L0.HasName); + + Function dependencies = graph.adapt(L0X.Dependencies, Function.class); + + Collection> results = (Collection>)dependencies.apply(graph, resource2, "Types:" + IndexQueries.quoteTerm(typeName)); + if (results == null) + return Collections.emptySet(); + + HashSet result = new HashSet(results.size()); + for(Map entry : results) { + Resource res = (Resource)entry.get("Resource"); + if(res != null) { + if (graph.isInstanceOf(res, resource)) + result.add(res); + } + } + return result; + + } + +}