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