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