| BTree | |||||
| Home | BTree Guide | BTree Performance | Sample Applications | BTree Roadmap | Other Products |
This
code is designed to show you how easy it is to use the Virtual Machinery implementation of the BTree classes for the Java platform. It shows you all the basic operations including opening and closing a BTree, adding, fetching and deleting data and closing the BTree.
Creating
a new BTree
Obviously
the first time you use this software you will be creating a new BTree so
lets do that -
The message protocol follows that of the Java Hashtable classes - put(index,data) adds data to the BTree, get(index) retrieves it and remove(index) removes it. In the standard access methods both data and index must implement the BTreeRecordInterface interface but convenience methods which use the String class are also provided and these are used in the examples here. As you can see nothing was output for the second attempt to get the data at 'MYINDEX' since we had deleted the data. If you are using the BTreeRecordInterface you can use the createRecord(String) or createRecord(byte[]) methods implemented by the BTree class. e.g.
Since all the data within the BTree is held in variables that satisfy the BTreeRecordInterface interface it is possible to use both styles (String and BTreeRecordInterface) to add, access and remove data in the tree.
Opening
an existing Btree
You
can also open an existing tree - so lets re-open the we created above
- as you can see we can still access the data at 'MYNEXTINDEX' -
myTree = BTree.openExistingTree("MYTREE");
These
are the basics of using the BTree in your code - for more details of the
other options including page sizes , cacheing
and commit and rollback see the programmers
guide .
BTree myTree = BTree.createNewTree("MYTREE");
myTree.put("MYINDEX", "MYDATA");
System.out.println(myTree.get("MYINDEX"));
myTree.put("MYNEXTINDEX", "MYNEXTPIECEOFDATA");
myTree.remove("MYINDEX");
System.out.println(myTree.get("MYINDEX"));
myTree.closeBTree();
myTree.get(myTree.createRecord("MYNEXTINDEX"))
System.out.println(myTree.get("MYNEXTINDEX"));
myTree.closeBTree();