Ignore:
Timestamp:
2008-05-01T13:59:09+12:00 (16 years ago)
Author:
kjdon
Message:

added support for JDBM (or other) in place of GDBM: use SimpleCollectionDatabase instead of GDBMWrapper. new Element in buildConfig file: databaseType, set to gdbm or jdbm. If not present, assume gdbm. Also may be some small style changes to some files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2Search.java

    r13999 r15326  
    2020
    2121// Greenstone classes
    22 import org.greenstone.mg.*;
    23 import org.greenstone.gsdl3.util.*;
     22import org.greenstone.gsdl3.util.OID;
     23import org.greenstone.gsdl3.util.DBInfo;
     24import org.greenstone.gsdl3.util.GSXML;
     25import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
     26import org.greenstone.gsdl3.util.GSFile;
    2427
    2528// XML classes
     
    7477    protected int maxnumeric = 4;
    7578
    76     protected GDBMWrapper gdbm_src = null;
    77 
    78     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGSearch.class.getName());
     79    // collection database
     80    protected SimpleCollectionDatabase coll_db = null;
     81
     82    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2Search.class.getName());
    7983
    8084
     
    8286    public AbstractGS2Search()
    8387    {
    84     this.gdbm_src = new GDBMWrapper();
     88   
    8589    }
    8690    public void cleanUp() {
    8791    super.cleanUp();
    88     this.gdbm_src.closeDatabase();
     92    this.coll_db.closeDatabase();
    8993    }
    9094
     
    9397    {
    9498    if (!super.configure(info, extra_info)){
     99        return false;
     100    }
     101
     102    // find out what kind of database we have
     103    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     104    String database_type = null;
     105    if (database_type_elem != null) {
     106      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     107    }
     108    if (database_type == null || database_type.equals("")) {
     109      database_type = "gdbm"; // the default
     110    }
     111    coll_db = new SimpleCollectionDatabase(database_type);
     112    if (coll_db == null) {
     113      logger.error("Couldn't create the collection database of type "+database_type);
     114      return false;
     115    }
     116   
     117    // the index stem is either the collection name or is specified in the config file
     118    Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
     119    if (index_stem_elem != null) {
     120        this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
     121    }
     122    if (this.index_stem == null || this.index_stem.equals("")) {
     123        logger.warn("indexStem element not found, stem will default to collection name");
     124        this.index_stem = this.cluster_name;
     125    }
     126
     127    // Open database for querying
     128    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type);
     129    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     130        logger.error("Could not open collection database!");
    95131        return false;
    96132    }
     
    116152        this.default_index_language = defLang.getAttribute(GSXML.SHORTNAME_ATT);
    117153    } //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage
    118      
    119 
    120     // the index stem is either the collection name or is specified in the config file
    121     Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
    122     if (index_stem_elem != null) {
    123         this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
    124     }
    125     if (this.index_stem == null || this.index_stem.equals("")) {
    126         logger.warn("indexStem element not found, stem will default to collection name");
    127         this.index_stem = this.cluster_name;
    128     }
    129    
     154       
    130155    // get index options
    131156    Element index_option_list = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_OPTION_ELEM + GSXML.LIST_MODIFIER);
     
    187212        } // for each index
    188213    }
    189         // Open GDBM database for querying
    190     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
    191     if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    192         logger.error(" Could not open GDBM database!");
    193         return false;
    194     }
    195214    return true;
    196215    }
     
    294313    */
    295314    protected String getDocType(String node_id){
    296     DBInfo info = this.gdbm_src.getInfo(node_id);
     315    DBInfo info = this.coll_db.getInfo(node_id);
    297316    if (info == null) {
    298317        return GSXML.DOC_TYPE_SIMPLE;
     
    315334    // now we just check the top node
    316335    if (!is_top) { // we need to look at the top info
    317         info = this.gdbm_src.getInfo(top_id);
     336        info = this.coll_db.getInfo(top_id);
    318337    }
    319338    if (info == null) {
     
    331350    /** returns true if the node has child nodes */
    332351    protected boolean hasChildren(String node_id){
    333     DBInfo info = this.gdbm_src.getInfo(node_id);
     352    DBInfo info = this.coll_db.getInfo(node_id);
    334353    if (info == null) {
    335354        return false;
     
    351370    }
    352371   
    353    /** convert MG internal id to Greenstone oid */
     372   /** convert indexer internal id to Greenstone oid */
    354373    protected String internalNum2OID(long docnum)
    355374    {
    356     return this.gdbm_src.docnum2OID(docnum);
     375    return this.coll_db.docnum2OID(docnum);
    357376   
    358377    }
    359378    protected String internalNum2OID(String docnum)
    360379    {
    361     return this.gdbm_src.docnum2OID(docnum);
     380    return this.coll_db.docnum2OID(docnum);
    362381   
    363382    }
Note: See TracChangeset for help on using the changeset viewer.