Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java	(revision 15326)
@@ -725,29 +725,4 @@
      */
     abstract protected String getStructureInfo(String node_id, String info_type);    
-//      /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
-//     protected String resolveTextMacros(String doc_content, String doc_id, String lang)
-//     {
-// 	DBInfo info = null;
-// 	if (doc_content.indexOf("_httpdocimg_")!=-1) {
-// 	    String top_doc_id = OID.getTop(doc_id);
-// 	    info = this.gdbm_src.getInfo(top_doc_id);
-// 	    if (info == null) {
-// 		// perhaps we had per.iods in the ids - just try the current id
-// 		top_doc_id = doc_id;
-// 		info = this.gdbm_src.getInfo(top_doc_id);
-// 	    }
-// 	    if (info != null) {
-// 		String archivedir = info.getInfo("archivedir");
-// 		String image_dir  = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir;
-		
-// 		// Resolve all "_httpdocimg_"s
-// 		doc_content = doc_content.replaceAll("_httpdocimg_", image_dir);
-// 	    }
-// 	}
-// 	// resolve any collection specific macros
-// 	doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id, info);
-// 	return doc_content;
-//     }
-
    
 }   
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java	(revision 15326)
@@ -22,5 +22,4 @@
 
 // Greenstone classes
-//import org.greenstone.gdbm.*;
 import org.greenstone.gsdl3.core.GSException;
 import org.greenstone.gsdl3.util.GSXML;
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java	(revision 15326)
@@ -27,5 +27,5 @@
 import org.greenstone.gsdl3.util.GS2MacroResolver;
 import org.greenstone.gsdl3.util.GSConstants;
-import org.greenstone.gsdl3.util.GDBMWrapper;
+import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
 import org.greenstone.gsdl3.util.DBInfo;
 // XML classes
@@ -59,5 +59,5 @@
     protected String index_stem = null;
 
-    protected GDBMWrapper gdbm_src = null;
+    protected SimpleCollectionDatabase coll_db = null;
 
 
@@ -65,11 +65,9 @@
     protected AbstractGS2DocumentRetrieve()
     {
-	this.gdbm_src = new GDBMWrapper();
-	this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
     }
 
     public void cleanUp() {
-	super.cleanUp();
-	this.gdbm_src.closeDatabase();
+        super.cleanUp();
+        this.coll_db.closeDatabase();
     }
     /** configure this service */
@@ -93,10 +91,26 @@
 	}
 
-	// Open GDBM database for querying
-	String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
-	if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
-	    logger.error("Could not open GDBM database!");
+	// find out what kind of database we have
+	Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
+	String database_type = null;
+	if (database_type_elem != null) {
+	  database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
+	}
+	if (database_type == null || database_type.equals("")) {
+	  database_type = "gdbm"; // the default
+	}
+	coll_db = new SimpleCollectionDatabase(database_type);
+	if (coll_db == null) {
+	  logger.error("Couldn't create the collection database of type "+database_type);
+	  return false;
+	}
+	
+	// Open database for querying
+	String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type);
+	if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
+	    logger.error("Could not open collection database!");
 	    return false;
 	}
+	this.macro_resolver = new GS2MacroResolver(this.coll_db);
 
 	return true;
@@ -105,5 +119,5 @@
     /** if id ends in .fc, .pc etc, then translate it to the correct id */
     protected String translateId(String node_id) {
-	return this.gdbm_src.translateOID(node_id);
+	return this.coll_db.translateOID(node_id);
     }
     
@@ -111,5 +125,5 @@
 	it to a greenstone one*/
     protected String translateExternalId(String node_id){
-	return this.gdbm_src.externalId2OID(node_id);
+	return this.coll_db.externalId2OID(node_id);
     }
 
@@ -120,5 +134,5 @@
     /** returns a list of the child ids in order, null if no children */
     protected ArrayList getChildrenIds(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return null;
@@ -156,5 +170,5 @@
 	throws GSException {
 	Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return null;
@@ -211,5 +225,5 @@
 	    }
 	    
-	    DBInfo info = this.gdbm_src.getInfo(parent_id);
+	    DBInfo info = this.coll_db.getInfo(parent_id);
 	    if (info==null) {
 		return "-1";
@@ -235,5 +249,5 @@
 
     protected int getNumChildren(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return 0;
@@ -254,5 +268,5 @@
     */
     protected String getDocType(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return GSXML.DOC_TYPE_SIMPLE;
@@ -275,5 +289,5 @@
 	// now we just check the top node
 	if (!is_top) { // we need to look at the top info
-	    info = this.gdbm_src.getInfo(top_id);
+	    info = this.coll_db.getInfo(top_id);
 	}
 	if (info == null) {
@@ -370,5 +384,5 @@
 	    relation_info = info;
 	} else {
-	    relation_info = this.gdbm_src.getInfo(relation_id);
+	    relation_info = this.coll_db.getInfo(relation_id);
 	}
 	if (relation_info == null) {
@@ -405,5 +419,5 @@
 	relation_id = OID.getParent(current_id);
 	while (!relation_id.equals(current_id)) {
-	    relation_info = this.gdbm_src.getInfo(relation_id);
+	    relation_info = this.coll_db.getInfo(relation_id);
 	    if (relation_info == null) return result.toString();
 	    if (!multiple) {
@@ -427,5 +441,5 @@
     
 
-    /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
+    /** needs to get info from collection database - if the calling code gets it already it may pay to pass it in instead */
     protected String resolveTextMacros(String doc_content, String doc_id, String lang)
     {
@@ -452,5 +466,5 @@
 		value="-1";
 	    } else {
-		DBInfo info = this.gdbm_src.getInfo(parent_id);
+		DBInfo info = this.coll_db.getInfo(parent_id);
 		if (info==null) {
 		    value ="-1";
@@ -478,5 +492,5 @@
 
     protected String getHrefOID(String href_url){
-        return this.gdbm_src.docnum2OID(href_url);
+        return this.coll_db.docnum2OID(href_url);
     }
 
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 15326)
@@ -75,5 +75,5 @@
 
     protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
-    protected static final String DEFAULT_GDBM_LEVEL_ELEM = "defaultGDBMLevel";
+    protected static final String DEFAULT_DB_LEVEL_ELEM = "defaultDBLevel";
     protected static final String LEVEL_ELEM = "level";
     protected static final String FIELD_ATT = "field";
@@ -90,6 +90,6 @@
    // the default level for searching
     protected String default_level=null;
-    // default level for gdbm db
-    protected String default_gdbm_level = null;
+    // default level for collection db
+    protected String default_db_level = null;
     // which search services will we offer??
     protected boolean plain_search = false;
@@ -162,12 +162,12 @@
 	}
 
-	// Get the default GDBM level
-	def = (Element) GSXML.getChildByTagName(info, DEFAULT_GDBM_LEVEL_ELEM);
+	// Get the default DB level
+	def = (Element) GSXML.getChildByTagName(info, DEFAULT_DB_LEVEL_ELEM);
 	if (def != null) {
-	    this.default_gdbm_level = def.getAttribute(GSXML.SHORTNAME_ATT);
-	}
-	if (this.default_gdbm_level == null || this.default_gdbm_level.equals("")) {
-	    logger.error("default gdbm level not specified!, assuming Sec");
-	    this.default_gdbm_level = "Sec";
+	    this.default_db_level = def.getAttribute(GSXML.SHORTNAME_ATT);
+	}
+	if (this.default_db_level == null || this.default_db_level.equals("")) {
+	    logger.error("default database level (defaultDBLevel) not specified!, assuming Sec");
+	    this.default_db_level = "Sec";
 	}
 	
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2Search.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2Search.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2Search.java	(revision 15326)
@@ -20,6 +20,9 @@
 
 // Greenstone classes
-import org.greenstone.mg.*;
-import org.greenstone.gsdl3.util.*;
+import org.greenstone.gsdl3.util.OID;
+import org.greenstone.gsdl3.util.DBInfo;
+import org.greenstone.gsdl3.util.GSXML;
+import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
+import org.greenstone.gsdl3.util.GSFile;
 
 // XML classes
@@ -74,7 +77,8 @@
     protected int maxnumeric = 4;
 
-    protected GDBMWrapper gdbm_src = null;
-
-    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGSearch.class.getName());
+    // collection database
+    protected SimpleCollectionDatabase coll_db = null;
+
+    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2Search.class.getName());
 
 
@@ -82,9 +86,9 @@
     public AbstractGS2Search()
     {
-	this.gdbm_src = new GDBMWrapper();
+	
     }
     public void cleanUp() {
 	super.cleanUp();
-	this.gdbm_src.closeDatabase();
+	this.coll_db.closeDatabase();
     }
 
@@ -93,4 +97,36 @@
     {
 	if (!super.configure(info, extra_info)){
+	    return false;
+	}
+
+	// find out what kind of database we have
+	Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
+	String database_type = null;
+	if (database_type_elem != null) {
+	  database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
+	}
+	if (database_type == null || database_type.equals("")) {
+	  database_type = "gdbm"; // the default
+	}
+	coll_db = new SimpleCollectionDatabase(database_type);
+	if (coll_db == null) {
+	  logger.error("Couldn't create the collection database of type "+database_type);
+	  return false;
+	}
+	
+	// the index stem is either the collection name or is specified in the config file
+	Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
+	if (index_stem_elem != null) {
+	    this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
+	}
+	if (this.index_stem == null || this.index_stem.equals("")) {
+	    logger.warn("indexStem element not found, stem will default to collection name");
+	    this.index_stem = this.cluster_name;
+	}
+
+	// Open database for querying
+	String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type);
+	if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
+	    logger.error("Could not open collection database!");
 	    return false;
 	}
@@ -116,16 +152,5 @@
 	    this.default_index_language = defLang.getAttribute(GSXML.SHORTNAME_ATT);
 	} //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage
-     
-
-	// the index stem is either the collection name or is specified in the config file
-	Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
-	if (index_stem_elem != null) {
-	    this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
-	}
-	if (this.index_stem == null || this.index_stem.equals("")) {
-	    logger.warn("indexStem element not found, stem will default to collection name");
-	    this.index_stem = this.cluster_name;
-	}
-	
+     	
 	// get index options
 	Element index_option_list = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_OPTION_ELEM + GSXML.LIST_MODIFIER);
@@ -187,10 +212,4 @@
 	    } // for each index
 	}
-    	// Open GDBM database for querying
-	String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
-	if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
-	    logger.error(" Could not open GDBM database!");
-	    return false;
-	}
 	return true;
     }
@@ -294,5 +313,5 @@
     */
     protected String getDocType(String node_id){
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return GSXML.DOC_TYPE_SIMPLE;
@@ -315,5 +334,5 @@
 	// now we just check the top node
 	if (!is_top) { // we need to look at the top info
-	    info = this.gdbm_src.getInfo(top_id);
+	    info = this.coll_db.getInfo(top_id);
 	}
 	if (info == null) {
@@ -331,5 +350,5 @@
     /** returns true if the node has child nodes */
     protected boolean hasChildren(String node_id){
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return false;
@@ -351,13 +370,13 @@
     }
     
-   /** convert MG internal id to Greenstone oid */
+   /** convert indexer internal id to Greenstone oid */
     protected String internalNum2OID(long docnum)
     {
-	return this.gdbm_src.docnum2OID(docnum);
+	return this.coll_db.docnum2OID(docnum);
 	
     }
     protected String internalNum2OID(String docnum)
     {
-	return this.gdbm_src.docnum2OID(docnum);
+	return this.coll_db.docnum2OID(docnum);
 	
     }
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2Browse.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2Browse.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2Browse.java	(revision 15326)
@@ -25,5 +25,5 @@
 import org.greenstone.gsdl3.util.MacroResolver;
 import org.greenstone.gsdl3.util.GS2MacroResolver;
-import org.greenstone.gsdl3.util.GDBMWrapper;
+import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
 import org.greenstone.gsdl3.util.DBInfo;
 // XML classes
@@ -52,15 +52,13 @@
      static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2Browse.class.getName());
 
-    protected GDBMWrapper gdbm_src = null;
+    protected SimpleCollectionDatabase coll_db = null;
 
     public GS2Browse() 
     {
-	this.gdbm_src = new GDBMWrapper();
-	this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
     }
 
     public void cleanUp() {
 	super.cleanUp();
-	this.gdbm_src.closeDatabase();
+	this.coll_db.closeDatabase();
     }
 
@@ -82,10 +80,26 @@
 	}
 	
-	// Open GDBM database for querying
-	String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, index_stem);
-	if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
-	    logger.error("Could not open GDBM database!");
+	// find out what kind of database we have
+	Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
+	String database_type = null;
+	if (database_type_elem != null) {
+	  database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
+	}
+	if (database_type == null || database_type.equals("")) {
+	  database_type = "gdbm"; // the default
+	}
+	coll_db = new SimpleCollectionDatabase(database_type);
+	if (coll_db == null) {
+	  logger.error("Couldn't create the collection database of type "+database_type);
+	  return false;
+	}
+	
+	// Open database for querying
+	String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
+	if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
+	    logger.error("Could not open collection database!");
 	    return false;
 	}
+	this.macro_resolver = new GS2MacroResolver(this.coll_db);
 	return true;
     }
@@ -93,5 +107,5 @@
     /** if id ends in .fc, .pc etc, then translate it to the correct id */
     protected String translateId(String node_id) {
-	return this.gdbm_src.translateOID(node_id);
+	return this.coll_db.translateOID(node_id);
     }
 
@@ -103,5 +117,5 @@
     */
     protected String getDocType(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return GSXML.DOC_TYPE_SIMPLE;
@@ -124,5 +138,5 @@
 	// now we just check the top node
 	if (!is_top) { // we need to look at the top info
-	    info = this.gdbm_src.getInfo(top_id);
+	    info = this.coll_db.getInfo(top_id);
 	}
 	if (info == null) {
@@ -144,5 +158,5 @@
     /** returns a list of the child ids in order, null if no children */
     protected ArrayList getChildrenIds(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return null;
@@ -170,5 +184,5 @@
 
     protected String getMetadata(String node_id, String key){
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return "";
@@ -200,5 +214,5 @@
 	String lang = "en";
 	Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return null;
@@ -251,5 +265,5 @@
 	    }
 	    
-	    DBInfo info = this.gdbm_src.getInfo(parent_id);
+	    DBInfo info = this.coll_db.getInfo(parent_id);
 	    if (info==null) {
 		return "-1";
@@ -275,5 +289,5 @@
 
     protected int getNumChildren(String node_id) {
-	DBInfo info = this.gdbm_src.getInfo(node_id);
+	DBInfo info = this.coll_db.getInfo(node_id);
 	if (info == null) {
 	    return 0;
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2LuceneRetrieve.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2LuceneRetrieve.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2LuceneRetrieve.java	(revision 15326)
@@ -23,5 +23,4 @@
 import org.greenstone.gsdl3.util.GSFile;
 import org.greenstone.gsdl3.util.GSXML;
-import org.greenstone.gsdl3.util.GDBMWrapper;
 import org.greenstone.gsdl3.util.DBInfo;
 import org.greenstone.gsdl3.util.GSHTML;
@@ -109,12 +108,12 @@
 	    }
 	    
-	    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
-	    if (doc_num == -1) {
+	    String doc_num = this.coll_db.OID2Docnum(doc_id);
+	    if (doc_num == null || doc_num.equals("")) {
 		throw new Exception("OID "+doc_id +" couldn't be converted to lucene doc num");
 	    }
 	
-	    DBInfo info=this.gdbm_src.getInfo(OID.getTop(doc_id));
+	    DBInfo info=this.coll_db.getInfo(OID.getTop(doc_id));
 	    if (info == null) {
-		throw new Exception("Couldn't get GDBM database entry for "+OID.getTop(doc_id));
+		throw new Exception("Couldn't get database entry for "+OID.getTop(doc_id));
 	    }
 	    
@@ -136,5 +135,5 @@
 		current_section = full_document;
 	    } else {
-		current_section = GSXML.getNamedElement(full_document, SEC_LEVEL, ID_ATT, String.valueOf(doc_num));
+		current_section = GSXML.getNamedElement(full_document, SEC_LEVEL, ID_ATT, doc_num);
 	    }
 	    if (current_section == null) {
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java	(revision 15326)
@@ -93,5 +93,5 @@
    */
   protected Element getNodeContent(String doc_id, String lang) throws GSException {
-    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
+    long doc_num = this.coll_db.OID2DocnumLong(doc_id);
     if (doc_num == -1) {
       logger.error("OID "+doc_id +" couldn't be converted to mgpp num");
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 15326)
@@ -20,6 +20,12 @@
 
 // Greenstone classes
-import org.greenstone.mgpp.*;
-import org.greenstone.gsdl3.util.*;
+import org.greenstone.mgpp.MGPPSearchWrapper;
+import org.greenstone.mgpp.MGPPTermInfo;
+import org.greenstone.mgpp.MGPPQueryResult;
+import org.greenstone.mgpp.MGPPDocInfo;
+
+import org.greenstone.gsdl3.util.GSFile;
+import org.greenstone.gsdl3.util.GSXML;
+
 
 // XML classes
@@ -66,7 +72,7 @@
   /** process a  query */
   protected Element processAnyQuery(Element request, int query_type) {
-	  synchronized (mgpp_src) {
-		  return super.processAnyQuery(request, query_type);
-	  }
+    synchronized (mgpp_src) {
+      return super.processAnyQuery(request, query_type);
+    }
   }
   /** configure this service */
@@ -76,7 +82,7 @@
     }
     
-    // the default level is also the level which gdbm is expecting
+    // the default level is also the level which the database is expecting
     // this must not be overwritten
-    mgpp_src.setReturnLevel(this.default_gdbm_level);
+    mgpp_src.setReturnLevel(this.default_db_level);
     // return term info
     mgpp_src.setReturnTerms(true);
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java	(revision 15326)
@@ -20,5 +20,5 @@
 
 // Greenstone classes
-import org.greenstone.mg.*;
+import org.greenstone.mg.MGRetrieveWrapper;
 import org.greenstone.gsdl3.core.GSException;
 import org.greenstone.gsdl3.util.GSFile;
@@ -113,5 +113,5 @@
      */
     protected Element getNodeContent (String doc_id, String lang) throws GSException {
-        long doc_num = this.gdbm_src.OID2Docnum (doc_id);
+        long doc_num = this.coll_db.OID2DocnumLong (doc_id);
         if (doc_num == -1) {
             logger.error ("OID "+doc_id +" couldn't be converted to mg num");
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 15326)
@@ -37,11 +37,8 @@
   extends GS2MGPPSearch {
    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
-   protected GDBMWrapper gdbm_src = null;
   
     /** constructor */
     public GoogleNgramMGPPSearch(){
-	super();
-	gdbm_src = new GDBMWrapper();
-	
+	super();	
     }
     
@@ -52,10 +49,4 @@
 	}
 
-	// Open GDBM database for querying
-	String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
-       	if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
-	    logger.error("Could not open GDBM database!");
-	    return false;
-	}
 	this.default_max_docs = "-1";
 	this.default_hits_per_page = "30";
@@ -78,7 +69,7 @@
 	      String num = Long.toString((((MGPPDocInfo) docs.elementAt(d)).num_));
 	      String doc_id = internalNum2OID(num);
-	      DBInfo gdbmInfo = this.gdbm_src.getInfo(doc_id);
-	      String fre = (String)gdbmInfo.getInfo("Frequency");
-	      String tense = (String)gdbmInfo.getInfo("Tense");
+	      DBInfo dbInfo = this.coll_db.getInfo(doc_id);
+	      String fre = (String)dbInfo.getInfo("Frequency");
+	      String tense = (String)dbInfo.getInfo("Tense");
 	     
 	      if(!fre.equals("")){
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/OAIPMH.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 15325)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 15326)
@@ -27,5 +27,5 @@
 import org.greenstone.gsdl3.util.XMLConverter;
 
-import org.greenstone.gsdl3.util.GDBMWrapper;
+import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
 import org.greenstone.gsdl3.util.DBInfo;
 // XML classes
@@ -45,8 +45,8 @@
 import java.util.Map.Entry;
 
-import org.apache.log4j.*;
+import org.apache.log4j.Logger;
 
 /** Implements the oai metadata retrieval service for GS3 collections.
- *  Dig into each collection's gdbm database and retrieve the metadata
+ *  Dig into each collection's database and retrieve the metadata
  *
  * @author <a href="mailto:xiao@cs.waikato.ac.nz">Xiao</a>
@@ -57,5 +57,5 @@
   static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.OAIPMH.class.getName());
   
-  protected GDBMWrapper gdbm_src = null;
+  protected SimpleCollectionDatabase coll_db = null;
   
   protected String site_name = "";
@@ -65,10 +65,10 @@
   /** constructor */
   public OAIPMH() {
-    this.gdbm_src = new GDBMWrapper();
+
   }
   
   public void cleanUp() {
     super.cleanUp();//??
-    this.gdbm_src.closeDatabase();
+    this.coll_db.closeDatabase();
   }
   /** configure this service */
@@ -89,21 +89,36 @@
     this.config_info = info;
     
-	// the index stem is either specified in the buildConfig.xml file or uses the collection name
-	Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM);
-	String index_stem = null;
-	if (index_stem_elem != null) {
-	    index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
-	}
-	if (index_stem == null || index_stem.equals("")) {
-	    index_stem = this.cluster_name;
-	}
+    // the index stem is either specified in the buildConfig.xml file or uses the collection name
+    Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM);
+    String index_stem = null;
+    if (index_stem_elem != null) {
+      index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
+    }
+    if (index_stem == null || index_stem.equals("")) {
+      index_stem = this.cluster_name;
+    }
   
-    // Open GDBM database for querying
-    String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, index_stem);
-    if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
-      logger.error("Could not open GDBM database!");
+    // find out what kind of database we have
+    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
+    String database_type = null;
+    if (database_type_elem != null) {
+      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
+    }
+    if (database_type == null || database_type.equals("")) {
+      database_type = "gdbm"; // the default
+    }
+    coll_db = new SimpleCollectionDatabase(database_type);
+    if (coll_db == null) {
+      logger.error("Couldn't create the collection database of type "+database_type);
       return false;
     }
-
+    
+    // Open database for querying
+    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
+    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
+      logger.error("Could not open collection database!");
+      return false;
+    }
+    
     // the short_service_info is used by the message router to find the method names, 
     //so we just use the doc variable in class ServiceRack to create the xml; but
@@ -214,5 +229,5 @@
     //get a DBInfo object of the identifier; if this identifier is not present in the database,
     // null is returned.
-    DBInfo info = this.gdbm_src.getInfo(oid);
+    DBInfo info = this.coll_db.getInfo(oid);
     if (info == null) {
       logger.error("OID: " + oid + " is not present in the database.");
@@ -294,5 +309,5 @@
     for(int i=0; i<oid_list.size(); i++) {
       String oid = (String)oid_list.get(i);
-      DBInfo info = this.gdbm_src.getInfo(oid);
+      DBInfo info = this.coll_db.getInfo(oid);
       if (info == null) {
         logger.error("Database does not contains information about oid: " +oid);
@@ -386,5 +401,5 @@
     for(int i=0; i<oid_list.size(); i++) {
       String oid = (String)oid_list.get(i);
-      DBInfo info = this.gdbm_src.getInfo(oid);
+      DBInfo info = this.coll_db.getInfo(oid);
       if (info == null) {
         logger.error("Database does not contains information about oid: " +oid);
@@ -506,5 +521,5 @@
     
     DBInfo info = null;    
-    info = this.gdbm_src.getInfo(oid);
+    info = this.coll_db.getInfo(oid);
     if (info == null) { //just double check
       return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.OAI_SERVICE_UNAVAILABLE, ""));
@@ -577,5 +592,5 @@
   /** returns a list of the child ids in order, null if no children */
   protected ArrayList getChildrenIds(String node_id) {
-    DBInfo info = this.gdbm_src.getInfo(node_id);
+    DBInfo info = this.coll_db.getInfo(node_id);
     if (info == null) {
       return null;
@@ -614,5 +629,5 @@
   }  
     /** @param keys - contains a list of keys in string format.
-     * Here is a typical record in the gdbm database, 'keys' contains the values in <...>:
+     * Here is a typical record in the collection database, 'keys' contains the values in <...>:
      *----------------------------------------------------------------------
 [HASH01a84acb0f1aad2380493b3a]
