]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.db.common.request;\r
2 \r
3 import java.util.Collection;\r
4 import java.util.Collections;\r
5 \r
6 import org.simantics.db.ReadGraph;\r
7 import org.simantics.db.Resource;\r
8 import org.simantics.db.ResourceSet;\r
9 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 import org.simantics.db.service.CollectionSupport;\r
12 import org.simantics.layer0.Layer0;\r
13 \r
14 public class IndexRoots extends ResourceRead<Collection<Resource>> {\r
15 \r
16         public IndexRoots(Resource r) {\r
17                 super(r);\r
18         }\r
19 \r
20         @Override\r
21         public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
22                 Layer0 L0 = Layer0.getInstance(graph);\r
23                 if (graph.isInstanceOf(resource, L0.IndexRoot))\r
24                         return Collections.singletonList(resource);\r
25                 CollectionSupport cs = graph.getService(CollectionSupport.class);\r
26                 ResourceSet types = cs.getResourceSet(graph, L0.IndexRoot);\r
27                 ResourceSetGraph rsg = graph.syncRequest(new DependentInstances3(resource), TransientCacheAsyncListener.<ResourceSetGraph>instance());\r
28                 return rsg.resolve(graph, types);\r
29         }\r
30 \r
31 }