]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/IndexRoots.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / IndexRoots.java
diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/IndexRoots.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/IndexRoots.java
new file mode 100644 (file)
index 0000000..e7ea43a
--- /dev/null
@@ -0,0 +1,31 @@
+package org.simantics.db.common.request;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ResourceSet;\r
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.CollectionSupport;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class IndexRoots extends ResourceRead<Collection<Resource>> {\r
+\r
+       public IndexRoots(Resource r) {\r
+               super(r);\r
+       }\r
+\r
+       @Override\r
+       public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+               Layer0 L0 = Layer0.getInstance(graph);\r
+               if (graph.isInstanceOf(resource, L0.IndexRoot))\r
+                       return Collections.singletonList(resource);\r
+               CollectionSupport cs = graph.getService(CollectionSupport.class);\r
+               ResourceSet types = cs.getResourceSet(graph, L0.IndexRoot);\r
+               ResourceSetGraph rsg = graph.syncRequest(new DependentInstances3(resource), TransientCacheAsyncListener.<ResourceSetGraph>instance());\r
+               return rsg.resolve(graph, types);\r
+       }\r
+\r
+}
\ No newline at end of file