]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.datatypes/src/org/simantics/datatypes/utils/BTree.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.datatypes / src / org / simantics / datatypes / utils / BTree.java
1 package org.simantics.datatypes.utils;\r
2 \r
3 import java.util.List;\r
4 \r
5 import org.simantics.databoard.Bindings;\r
6 import org.simantics.databoard.binding.mutable.Variant;\r
7 import org.simantics.datatypes.DatatypeResource;\r
8 import org.simantics.db.ReadGraph;\r
9 import org.simantics.db.Resource;\r
10 import org.simantics.db.WriteGraph;\r
11 import org.simantics.db.exception.DatabaseException;\r
12 import org.simantics.scl.runtime.tuple.Tuple2;\r
13 \r
14 public class BTree {\r
15         \r
16         final private BTreeUtils utils;\r
17         \r
18         public BTree(WriteGraph graph, int t, Resource ownerRelation) throws DatabaseException {\r
19                 this(graph, t, ownerRelation, false);\r
20         }\r
21         \r
22         public BTree(WriteGraph graph, int t, Resource ownerRelation, boolean cached) throws DatabaseException {\r
23                 utils = BTreeUtils.create(graph, ownerRelation, t, cached);\r
24         }\r
25         \r
26         public BTree(WriteGraph graph, int t, Resource type, Resource nodeType, Resource ownerRelation, boolean cached) throws DatabaseException {\r
27                 utils = BTreeUtils.create(graph, type, nodeType, ownerRelation, t, cached);\r
28         }\r
29 \r
30         public BTree(ReadGraph graph, Resource tree) throws DatabaseException {\r
31                 this(graph, tree, false);\r
32         }\r
33         \r
34         public BTree(ReadGraph graph, Resource tree, boolean cached) throws DatabaseException {\r
35                 DatatypeResource DATA = DatatypeResource.getInstance(graph);\r
36                 int t = graph.getRelatedValue(tree, DATA.BTree_t, Bindings.INTEGER);\r
37                 Resource ownerRelation = graph.getPossibleObject(tree, DATA.BTree_HasOwnerRelation);\r
38                 Resource nodeType = graph.getPossibleObject(tree, DATA.BTree_HasNodeType);\r
39                 utils = new BTreeUtils(graph, tree, t, nodeType, ownerRelation, cached);\r
40         }\r
41         \r
42         public void flushCachedBTree(WriteGraph graph) throws DatabaseException {\r
43                 utils.flushCache(graph);\r
44         }\r
45         \r
46         public Resource rootOfBTree() {\r
47                 return utils.getTree();\r
48         }\r
49         \r
50         public void insertBTree(WriteGraph graph, Variant key, Resource value) throws DatabaseException {\r
51                 utils.insert(graph, key, value);\r
52         }\r
53         \r
54         public Resource searchBTree(ReadGraph graph, Variant key) throws DatabaseException {\r
55                 return utils.search(graph, key);\r
56         }\r
57 \r
58         public void removeBTree(WriteGraph graph, Variant key) throws DatabaseException {\r
59                 utils.remove(graph, key);\r
60         }\r
61         \r
62         public List<Tuple2> entriesOfBTree(ReadGraph graph) throws DatabaseException {\r
63                 return utils.entries(graph);\r
64         }\r
65         \r
66         public List<Tuple2> searchRangeBTree(ReadGraph graph, Variant min, Variant max) throws DatabaseException {\r
67                 return utils.searchRange(graph, min, max);\r
68         }\r
69 }\r