]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/LinkedFrom.java
possibleObjectForType utility
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / LinkedFrom.java
1 package org.simantics.db.layer0.request;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.layer0.Layer0;
12
13 /**
14  * @author Tuukka Lehtonen
15  * @since 1.25.0
16  */
17 public class LinkedFrom extends ResourceRead<Set<Resource>> {
18
19     public LinkedFrom(Resource resource) {
20         super(resource);
21     }
22
23     @Override
24     public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
25         Layer0 L0 = Layer0.getInstance(graph);
26         HashSet<Resource> result = new HashSet<>();
27         Collection<Resource> linkees = graph.getObjects(resource, L0.IsLinkedTo_Inverse);
28         result.addAll(linkees);
29         for (Resource linkee : linkees) {
30             Set<Resource> deep = graph.sync(new LinkedFrom(linkee));
31             result.addAll(deep);
32         }
33         return result;
34     }
35
36 }