Index: main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java
===================================================================
--- main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java	(revision 21401)
+++ main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java	(revision 21402)
@@ -6,5 +6,5 @@
  * University of Waikato, New Zealand.
  *
- * Copyright (C) 1999  The New Zealand Digital Library Project
+ * Copyright (C) 2009  The New Zealand Digital Library Project
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -38,39 +38,4 @@
 public class JdbDel
 {
-    static String TNAME = "greenstone";
-
-    RecordManager  recman_;
-    HTree          hashtable_;
-
-    public JdbDel(String db_filename)
-	throws IOException
-    {
-        // create or open a record manager
-        Properties props = new Properties();
-        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
-
-        // load existing table (if exists) otherwise report error
-        long recid = recman_.getNamedObject(TNAME);
-
-	if (recid != 0) {
-	    System.out.println("Loading existing database table '" + TNAME +"' ...");
-	    hashtable_ = HTree.load(recman_, recid);
-	}
-	else {
-	    recman_.close();
-	    System.out.println("No database table '" + TNAME +"' to delete key from.");
-	    System.exit(-1);
-	}
-    }
-    
-
-    public void del(String key)
-	throws IOException
-    {
-	hashtable_.remove(key);
-	recman_.close();
-    }
-    
-
     public static void print_usage()
     {
@@ -91,8 +56,10 @@
 	try {
 	    String dbname = args[0];
-	    JdbDel table = new JdbDel(dbname);
+	    JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
 	    
 	    String key = args[1];
-	    table.del(key);
+
+	    jdbm_api.delete(key);
+	    jdbm_api.close();
 	}
 
Index: main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java
===================================================================
--- main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java	(revision 21401)
+++ main/trunk/greenstone2/common-src/src/jdbmedit/JdbGet.java	(revision 21402)
@@ -6,5 +6,5 @@
  * University of Waikato, New Zealand.
  *
- * Copyright (C) 1999  The New Zealand Digital Library Project
+ * Copyright (C) 2009  The New Zealand Digital Library Project
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -35,41 +35,4 @@
 public class JdbGet
 {
-    static String TNAME = "greenstone";
-
-    RecordManager  recman_;
-    HTree          hashtable_;
-
-
-    public JdbGet(String db_filename)
-	throws IOException
-    {
-        // create or open a record manager
-        Properties props = new Properties();
-        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
-
-        // create or load table
-        long recid = recman_.getNamedObject(TNAME);
-        if (recid != 0) {
-            hashtable_ = HTree.load(recman_, recid);
-        } 
-	else {
-            System.err.println("Failed to find database table '" + TNAME +"' ...");
-	    System.exit(-1);
-        }
-    }
-
-
-    public void get(String key)
-        throws IOException
-    {
-	FastIterator   iter;
-	String         val;
-
-	val = (String) hashtable_.get(key);
-	System.out.println(val);
-        
-        recman_.close();
-    }
-
 
     public static void print_usage()
@@ -91,6 +54,9 @@
         try {
 
-            JdbGet table = new JdbGet(dbname);
-            table.get(key);
+            JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
+            String val = jdbm_api.get(key);
+	    System.out.println(val);
+
+	    jdbm_api.close();
         } 
 	catch (IOException e) {
Index: main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java
===================================================================
--- main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java	(revision 21401)
+++ main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java	(revision 21402)
@@ -6,5 +6,5 @@
  * University of Waikato, New Zealand.
  *
- * Copyright (C) 1999  The New Zealand Digital Library Project
+ * Copyright (C) 2009  The New Zealand Digital Library Project
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -24,4 +24,8 @@
  **********************************************************************/
 
+import java.io.IOException;
+import java.util.Properties;
+import java.util.ArrayList;
+
 import jdbm.RecordManager;
 import jdbm.RecordManagerFactory;
@@ -29,53 +33,6 @@
 import jdbm.htree.HTree;
 
-import java.io.IOException;
-import java.util.Properties;
-
-
 public class JdbKeys
 {
-    static String TNAME = "greenstone";
-
-    RecordManager  recman_;
-    HTree          hashtable_;
-
-
-    public JdbKeys(String db_filename)
-	throws IOException
-    {
-        // create or open a record manager
-        Properties props = new Properties();
-        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
-
-        // create or load table
-        long recid = recman_.getNamedObject(TNAME);
-        if (recid != 0) {
-            hashtable_ = HTree.load(recman_, recid);
-        } 
-	else {
-            System.err.println("Failed to find database table '" + TNAME +"' ...");
-	    System.exit(-1);
-        }
-    }
-
-
-    public void get_keys()
-        throws IOException
-    {
-	FastIterator   iter;
-	String         key;
-	String         val;
-
-        iter = hashtable_.keys();
-        key = (String) iter.next();
-        while (key != null) {
-            System.out.println(key);
-            key = (String) iter.next();
-        }
-        
-        recman_.close();
-    }
-
-
     public static void print_usage()
     {
@@ -95,6 +52,15 @@
         try {
 
-            JdbKeys table = new JdbKeys(dbname);
-            table.get_keys();
+            JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
+
+	    ArrayList keys = jdbm_api.get_keys();
+		    
+	    int keys_len = keys.size();
+	    for (int i=0; i<keys_len; i++) {
+		String key = (String) keys.get(i);
+		System.out.println(key);
+	    }
+
+	    jdbm_api.close();
         } 
 	catch (IOException e) {
Index: main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java
===================================================================
--- main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java	(revision 21401)
+++ main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java	(revision 21402)
@@ -6,5 +6,5 @@
  * University of Waikato, New Zealand.
  *
- * Copyright (C) 1999  The New Zealand Digital Library Project
+ * Copyright (C) 2009  The New Zealand Digital Library Project
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -26,4 +26,7 @@
 import java.io.BufferedInputStream;
 import java.io.InputStream;
+import java.io.IOException;
+
+import java.util.Properties;
 
 import jdbm.RecordManager;
@@ -32,69 +35,14 @@
 import jdbm.htree.HTree;
 
-import java.io.IOException;
-import java.util.Properties;
 
 
 public class JdbSet
 {
-    static String TNAME = "greenstone";
-
-    RecordManager  recman_;
-    HTree          hashtable_;
-
-    public JdbSet(String db_filename)
-	throws IOException
-    {
-        // create or open a record manager
-        Properties props = new Properties();
-        recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
-
-        // load existing table (if exists) otherwise create new one
-        long recid = recman_.getNamedObject(TNAME);
-
-	if (recid != 0) {
-	    System.out.println("Loading existing database table '" + TNAME +"' ...");
-	    hashtable_ = HTree.load(recman_, recid);
-	}
-	else {
-	    System.out.println("No database table '" + TNAME +"' to set.  Creating new one");
-	    hashtable_ = HTree.createInstance(recman_);
-	    recman_.setNamedObject(TNAME, hashtable_.getRecid());
-	}
-    }
-    
-    public void append(String key, String val)
-	throws IOException
-    {
-    	    
-	String orig_val = (String)hashtable_.get(key);           
-	String new_val = orig_val + val;
-
-	hashtable_.put(key,new_val);
-	recman_.close();
-    }
-
-    public void set(String key, String val)
-	throws IOException
-	       
-    {
-	hashtable_.put(key,val);
-	recman_.close();
-    }
-
-    public void del(String key)
-	throws IOException
-    {
-	hashtable_.remove(key);
-	recman_.close();
-    }
-    
-
     public static void print_usage()
     {
 	System.err.println("Usage: java JdbSet database-name key [value] [append]");
-	System.err.println("\t- if no value is given then the lexicon indicated by the key is removed");
-	System.err.println("\t- if a value is given followed by 'append' then the value is ");
-	System.err.println("\t  added to the existing entry rather than overwriting it");
+	System.err.println("  - if no value is given then the lexicon indicated by the key is removed");
+	System.err.println("  - if a value is given followed by 'append' then the value is ");
+	System.err.println("    added to the existing entry rather than overwriting it");
 	System.exit(-1);
     }
@@ -112,5 +60,5 @@
 	try {
 	    String dbname = args[0];
-	    JdbSet table = new JdbSet(dbname);
+	    JdbmAPI jdbm_api = new JdbmAPI(dbname);
 	    
 	    if (argc == 4) {
@@ -120,5 +68,5 @@
 		    String val = args[2];
 		    
-		    table.append(key,val);
+		    jdbm_api.append(key,val);
 		}
 		else {
@@ -130,10 +78,12 @@
 		String key = args[1];
 		String val = args[2];
-		table.set(key,val);
+		jdbm_api.set(key,val);
 	    }
 	    else {
 		String key = args[1];
-		table.del(key);
+		jdbm_api.delete(key);
 	    }
+
+	    jdbm_api.close();
 	}
 
Index: main/trunk/greenstone2/common-src/src/jdbmedit/JdbmAPI.java
===================================================================
--- main/trunk/greenstone2/common-src/src/jdbmedit/JdbmAPI.java	(revision 21401)
+++ main/trunk/greenstone2/common-src/src/jdbmedit/JdbmAPI.java	(revision 21402)
@@ -45,5 +45,5 @@
     HTree          hashtable_;
 
-    public JdbmAPI(String db_filename)
+    public JdbmAPI(String db_filename,boolean must_exist)
 	throws IOException
     {
@@ -56,18 +56,32 @@
 
 	if (recid != 0) {
-	    System.out.println("Loading existing database table '" + TNAME +"' ...");
+	    System.err.println("# Loading existing database table '" + TNAME +"' ...");
 	    hashtable_ = HTree.load(recman_, recid);
 	}
 	else {
-	    System.out.println("No database table '" + TNAME +"' to set.  Creating new one");
-	    hashtable_ = HTree.createInstance(recman_);
-	    recman_.setNamedObject(TNAME, hashtable_.getRecid());
-	}
+
+	    if (must_exist) {
+		recman_.close();
+		System.err.println("Database table '" + TNAME +"' does not exist.");
+		throw new IOException();
+	    }
+	    else {
+		System.err.println("# No database table '" + TNAME +"' to set.  Creating new one");
+		hashtable_ = HTree.createInstance(recman_);
+		recman_.setNamedObject(TNAME, hashtable_.getRecid());
+	    }
+	}
+    }
+
+    public JdbmAPI(String db_filename)
+	throws IOException
+    {
+	// default is that database does not have to exist
+	this(db_filename,false);
     }
     
     public void append(String key, String val)
 	throws IOException
-    {
-    	    
+    {    	    
 	String orig_val = (String)hashtable_.get(key);           
 	String new_val = orig_val + val;
@@ -127,4 +141,5 @@
     {
 	recman_.close();
+	System.err.println("# Done");
     }
 
