import java.util.Properties; import jdbm.RecordManager; import jdbm.RecordManagerFactory; import jdbm.helper.Tuple; import jdbm.helper.TupleBrowser; import jdbm.helper.StringComparator; import jdbm.btree.BTree; /** * Famous People example. *
* Demonstrates the use of B+Tree data structure to manage a list of
* people and their occupation. The example covers insertion,
* ordered traversal, reverse traversal and range lookup of records.
*
* @author Alex Boisvert
*/
public class FamousPeople {
static String DATABASE = "people";
static String BTREE_NAME = "FamousPeople";
static String[] people =
{ "Greenspan, Alan",
"Williams-Byrd, Julie",
"Picasso, Pablo",
"Stallman, Richard",
"Fort, Paul",
"S�ndergaard, Ole",
"Schwarzenegger, Arnold",
"Dulkinys, Susanna" };
static String[] occupations =
{ "Federal Reserve Board Chairman",
"Engineer",
"Painter",
"Programmer",
"Poet",
"Typographer",
"Actor",
"Designer" };
static String PREFIX = "S";
/**
* Example main entrypoint.
*/
public static void main( String[] args ) {
RecordManager recman;
long recid;
Tuple tuple = new Tuple();
TupleBrowser browser;
BTree tree;
Properties props;
props = new Properties();
try {
// open database and setup an object cache
recman = RecordManagerFactory.createRecordManager( DATABASE, props );
// try to reload an existing B+Tree
recid = recman.getNamedObject( BTREE_NAME );
if ( recid != 0 ) {
tree = BTree.load( recman, recid );
System.out.println( "Reloaded existing BTree with " + tree.size()
+ " famous people." );
} else {
// create a new B+Tree data structure and use a StringComparator
// to order the records based on people's name.
tree = BTree.createInstance( recman, new StringComparator() );
recman.setNamedObject( BTREE_NAME, tree.getRecid() );
System.out.println( "Created a new empty BTree" );
}
// insert people with their respective occupation
System.out.println();
for ( int i=0; i