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