Index: gs2-extensions/tdb/trunk/src/java/org/greenstone/tdbjava/TDBJavaTest.java
===================================================================
--- gs2-extensions/tdb/trunk/src/java/org/greenstone/tdbjava/TDBJavaTest.java	(revision 30273)
+++ gs2-extensions/tdb/trunk/src/java/org/greenstone/tdbjava/TDBJavaTest.java	(revision 30274)
@@ -162,68 +162,89 @@
 
 	try {
-	// Create a simple database
-	TDBJava db = new TDBJava(db_path);
-	Test.ok(1, db != null);
-
-	// Check database is open
-	Test.ok(1.5, db.isOpen());
-
-	// Store some data in the file
-	db.store("mountain", "Kosciusko");
-	Test.ok(2, true);
-
-	// Store and read back data
-	db.store("abc", "ABC");
-	value = db.fetch("abc");
-	Test.ok(3, value.equals("ABC"));
-
-	// Check whether keys exist or not
-	Test.ok(4, db.exists("abc"));
-	Test.ok(5, !db.exists("jimmy"));
-	Test.ok(6, !db.exists("abc\0"));
-
-	// Delete those records
-	db.delete("mountain");
-	Test.ok(9, !db.exists("mountain"));
-	db.delete("abc");
-	Test.ok(10, !db.exists("abc"));
-
-	// Store a series of records in the file
-	for (int i = 100; i < 200; i++) {
-	    db.store(Integer.toString(i, Character.MAX_RADIX),
-		     Integer.toString(i, Character.MIN_RADIX));
-	}
-
-	// Enumerate keys and values out of the file
-	int count = 0;
-	Enumeration keys = db.keys();
-	while (keys.hasMoreElements()) {
-	    key = (String) keys.nextElement();
-	    // System.out.print(key + "=");
-	    // value = (String) db.fetch(key);
-	    // System.out.println(value);
-	    count++;
-	}
-	Test.ok(20, count==100);
-
-	// Delete all the records from the file
-	count = 0;
-	while ((key = (String) db.getFirstKey()) != null) {
-	    db.delete(key);
-	    count++;
-	}
-	Test.ok(30, count==100);
-
-	// Try to fetch a non-existent key
-	boolean caught = false;
-	try {
-	    db.fetch("larry!");
-	}
-	catch (Exception e) {
-	    // TODO: Check the exception was the one we expected?
-	    System.out.println("caught: " + e.toString());
-	    caught = true;
-	}
-	Test.ok(40, caught);
+	    // Create a simple database
+	    TDBJava db = TDBJava.getConnection(db_path);
+	    Test.ok(1, db != null);
+
+	    // Check database is open
+	    Test.ok(1.5, db.isOpen());
+
+	    // Store some data in the file
+	    db.store("mountain", "Kosciusko");
+	    Test.ok(2, true);
+
+	    // Store and read back data
+	    db.store("abc", "ABC");
+	    value = db.fetch("abc");
+	    Test.ok(3, value.equals("ABC"));
+
+	    // Check whether keys exist or not
+	    Test.ok(4, db.exists("abc"));
+	    Test.ok(5, !db.exists("jimmy"));
+	    Test.ok(6, !db.exists("abc\0"));
+
+	    // Open a second handle to the same database
+	    TDBJava db4 = TDBJava.getConnection(db_path);
+	    Test.ok(701, db4 != null);
+	    // read an existing key
+	    value = db4.fetch("abc");
+	    Test.ok(702, value.equals("ABC"));
+	    // write a new key
+	    db4.store("breakfast", "Bacon");
+	    Test.ok(703, true);
+	    // read it out
+	    value = db4.fetch("breakfast");
+	    Test.ok(704, value.equals("Bacon"));
+	    // delete a record
+	    db4.delete("mountain");
+	    Test.ok(705, !db4.exists("mountain"));
+	    // close it
+	    db4.close();
+	    // test added record still exists
+	    value = db.fetch("breakfast");
+	    Test.ok(706, value.equals("Bacon"));
+
+	    // Delete those records
+	    db.delete("breakfast");
+	    Test.ok(9, !db.exists("breakfast"));
+	    db.delete("abc");
+	    Test.ok(10, !db.exists("abc"));
+
+	    // Store a series of records in the file
+	    for (int i = 100; i < 200; i++) {
+		db.store(Integer.toString(i, Character.MAX_RADIX),
+			 Integer.toString(i, Character.MIN_RADIX));
+	    }
+
+	    // Enumerate keys and values out of the file
+	    int count = 0;
+	    Enumeration keys = db.keys();
+	    while (keys.hasMoreElements()) {
+		key = (String) keys.nextElement();
+		// System.out.print(key + "=");
+		// value = (String) db.fetch(key);
+		// System.out.println(value);
+		count++;
+	    }
+	    Test.ok(20, count==100);
+
+	    // Delete all the records from the file
+	    count = 0;
+	    while ((key = (String) db.getFirstKey()) != null) {
+		db.delete(key);
+		count++;
+	    }
+	    Test.ok(30, count==100);
+
+	    // Try to fetch a non-existent key
+	    boolean caught = false;
+	    try {
+		db.fetch("larry!");
+	    }
+	    catch (Exception e) {
+		// TODO: Check the exception was the one we expected?
+		///ystem.out.println("caught: " + e.toString());
+		caught = true;
+	    }
+	    Test.ok(40, caught);
 
 	// Store some very large data
@@ -248,9 +269,10 @@
 	}
 	catch (Exception e) {
-	    System.out.println("caught: " + e.toString());
+	    ///ystem.out.println("caught: " + e.toString());
 	    caught = true;
 	}
 	Test.ok(70, caught);
 
+	/* No longer applicable
 	// Try to open a non-existent database
 	String bogus_db_path = "/tmp/somenonexistentdatabase.tdb";
@@ -258,5 +280,20 @@
 	caught = false;
 	try {
-	    db = new TDBJava(bogus_db_path, TDBJava.TDB_DEFAULT, TDBJava.O_READONLY);
+	    db = TDBJava.getConnection(bogus_db_path, TDBJava.TDB_DEFAULT, TDBJava.O_READONLY);
+	}
+	catch (Exception e) {
+	    ///ystem.out.println("caught: " + e.toString());
+	    caught = true;
+	}
+	Test.ok(80, caught);
+
+	// Open a database read-only
+	db = TDBJava.getConnection(db_path, TDBJava.TDB_DEFAULT, TDBJava.O_READONLY);
+	Test.ok(90);
+
+	// Try to insert
+	caught = false;
+	try {
+	    db.store("apple", "crumble");
 	}
 	catch (Exception e) {
@@ -264,25 +301,11 @@
 	    caught = true;
 	}
-	Test.ok(80, caught);
-
-	// Open a database read-only
-	db = new TDBJava(db_path, TDBJava.TDB_DEFAULT, TDBJava.O_READONLY);
-	Test.ok(90);
-
-	// Try to insert
-	caught = false;
-	try {
-	    db.store("apple", "crumble");
-	}
-	catch (Exception e) {
-	    System.out.println("caught: " + e.toString());
-	    caught = true;
-	}
 	Test.ok(91, caught);
 
 	db.close();
+	*/
 
 	// Replace an existing database
-	db = new TDBJava(db_path, TDBJava.TDB_CLEAR_IF_FIRST);
+	db = TDBJava.newConnection(db_path);
 	Test.ok(100, !db.exists("mountain"));
 
@@ -290,8 +313,8 @@
 	final String db_path2 = "/tmp/java2.tdb";
 	ensureNoDatabase(db_path2);
-	TDBJava db2 = new TDBJava(db_path2);
+	TDBJava db2 = TDBJava.getConnection(db_path2);
 	final String db_path3 = "/tmp/java3.tdb";
 	ensureNoDatabase(db_path3);
-	TDBJava db3 = new TDBJava(db_path3);
+	TDBJava db3 = TDBJava.getConnection(db_path3);
 	Test.ok(110, true);
 
