]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/IsLinkedTo.java
Merge "Allow loading databoard serialized files with type adapting" into release...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / IsLinkedTo.java
1 package org.simantics.db.layer0.request;
2
3 import java.util.Collection;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.common.request.ResourceRead2;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.layer0.Layer0;
10
11 public class IsLinkedTo extends ResourceRead2<Boolean> {
12
13         public IsLinkedTo(Resource resource, Resource resource2) {
14                 super(resource, resource2);
15         }
16
17         @Override
18         public Boolean perform(ReadGraph graph) throws DatabaseException {
19                 if(resource.equals(resource2)) return true;
20                 Layer0 L0 = Layer0.getInstance(graph);
21                 Collection<Resource> links = graph.getObjects(resource, L0.IsLinkedTo);
22                 for(Resource link : links) {
23                         if(link.equals(resource2)) return true;
24                 }
25                 for(Resource link : links) {
26                         if(graph.syncRequest(new IsLinkedTo(link, resource2))) return true;
27                 }
28                 return false;
29         }
30
31 }