X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FIndexedInstances.java;h=57aefa5197798d3a8a2be227dc197c8a8999d6fb;hb=refs%2Fchanges%2F58%2F3758%2F1;hp=1177f3a30f984881b1bef0398687bf6802662850;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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..57aefa519 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,23 @@ -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.HashSet; +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.QueryIndexUtils; + +public class IndexedInstances extends ResourceRead2> { + + public IndexedInstances(Resource type, Resource indexRoot) { + super(type, indexRoot); + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + return new HashSet<>(QueryIndexUtils.searchByTypeShallow(graph, resource2, resource)); + } + +}