1 package org.simantics.datatypes.utils;
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;
16 final private BTreeUtils utils;
18 public BTree(WriteGraph graph, int t, Resource ownerRelation) throws DatabaseException {
19 this(graph, t, ownerRelation, false);
22 public BTree(WriteGraph graph, int t, Resource ownerRelation, boolean cached) throws DatabaseException {
23 utils = BTreeUtils.create(graph, ownerRelation, t, cached);
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);
30 public BTree(ReadGraph graph, Resource tree) throws DatabaseException {
31 this(graph, tree, false);
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);
42 public void flushCachedBTree(WriteGraph graph) throws DatabaseException {
43 utils.flushCache(graph);
46 public Resource rootOfBTree() {
47 return utils.getTree();
50 public void insertBTree(WriteGraph graph, Variant key, Resource value) throws DatabaseException {
51 utils.insert(graph, key, value);
54 public Resource searchBTree(ReadGraph graph, Variant key) throws DatabaseException {
55 return utils.search(graph, key);
58 public void removeBTree(WriteGraph graph, Variant key) throws DatabaseException {
59 utils.remove(graph, key);
62 public List<Tuple2> entriesOfBTree(ReadGraph graph) throws DatabaseException {
63 return utils.entries(graph);
66 public List<Tuple2> searchRangeBTree(ReadGraph graph, Variant min, Variant max) throws DatabaseException {
67 return utils.searchRange(graph, min, max);