]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Entry.java
Added new field TypeId to dependency index for exact type searching
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / Entry.java
1 package org.simantics.db.layer0.genericrelation;
2
3 import java.util.Set;
4
5 import org.simantics.databoard.Bindings;
6 import org.simantics.datatypes.literal.GUID;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.TypeString;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.layer0.Layer0;
12
13 class Entry implements Comparable<Entry> {
14
15         Entry(Resource parent, Resource resource, String name, String types, String id) {
16                 this.parent = parent;
17                 this.resource = resource;
18                 this.name = name;
19                 this.types = types;
20                 this.id = id;
21         }
22
23         Entry(ReadGraph graph, Layer0 L0, Resource resource) throws DatabaseException {
24                 this.parent = graph.getPossibleObject(resource, L0.PartOf);
25                 this.resource = resource;
26                 this.name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
27                 Set<Resource> typeSet = graph.getTypes(resource);
28                 this.types = graph.syncRequest(new TypeString(L0, typeSet));
29                 this.id = IndexQueries.idFromGUID(graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING));
30                 this.typeId = IndexQueries.toResourceIdString(typeSet);
31         }
32
33         Entry(ReadGraph graph, Resource resource) throws DatabaseException {
34                 this(graph, Layer0.getInstance(graph), resource);
35         }
36
37         final Resource parent;
38         final Resource resource;
39
40         String types;
41         String name;
42         String id;
43         String typeId;
44         Resource principalType;
45
46         @Override
47         public int compareTo(Entry o) {
48                 int names = name.compareTo(o.name);
49                 if(names != 0) return names;
50                 int resources = resource.compareTo(o.resource);
51                 if(resources != 0) return resources;
52                 return id.compareTo(o.id);
53         }
54
55         @Override
56         public int hashCode() {
57                 return resource.hashCode();
58         }
59
60         @Override
61         public boolean equals(Object obj) {
62                 Entry other = (Entry)obj;
63                 return resource.equals(other.resource);
64         }
65
66 }