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/AbstractGS2DocumentRetrieve.java

    r15208 r15326  
    2727import org.greenstone.gsdl3.util.GS2MacroResolver;
    2828import org.greenstone.gsdl3.util.GSConstants;
    29 import org.greenstone.gsdl3.util.GDBMWrapper;
     29import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
    3030import org.greenstone.gsdl3.util.DBInfo;
    3131// XML classes
     
    5959    protected String index_stem = null;
    6060
    61     protected GDBMWrapper gdbm_src = null;
     61    protected SimpleCollectionDatabase coll_db = null;
    6262
    6363
     
    6565    protected AbstractGS2DocumentRetrieve()
    6666    {
    67     this.gdbm_src = new GDBMWrapper();
    68     this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
    6967    }
    7068
    7169    public void cleanUp() {
    72     super.cleanUp();
    73     this.gdbm_src.closeDatabase();
     70        super.cleanUp();
     71        this.coll_db.closeDatabase();
    7472    }
    7573    /** configure this service */
     
    9391    }
    9492
    95     // Open GDBM database for querying
    96     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
    97     if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    98         logger.error("Could not open GDBM database!");
     93    // find out what kind of database we have
     94    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     95    String database_type = null;
     96    if (database_type_elem != null) {
     97      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     98    }
     99    if (database_type == null || database_type.equals("")) {
     100      database_type = "gdbm"; // the default
     101    }
     102    coll_db = new SimpleCollectionDatabase(database_type);
     103    if (coll_db == null) {
     104      logger.error("Couldn't create the collection database of type "+database_type);
     105      return false;
     106    }
     107   
     108    // Open database for querying
     109    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type);
     110    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     111        logger.error("Could not open collection database!");
    99112        return false;
    100113    }
     114    this.macro_resolver = new GS2MacroResolver(this.coll_db);
    101115
    102116    return true;
     
    105119    /** if id ends in .fc, .pc etc, then translate it to the correct id */
    106120    protected String translateId(String node_id) {
    107     return this.gdbm_src.translateOID(node_id);
     121    return this.coll_db.translateOID(node_id);
    108122    }
    109123   
     
    111125    it to a greenstone one*/
    112126    protected String translateExternalId(String node_id){
    113     return this.gdbm_src.externalId2OID(node_id);
     127    return this.coll_db.externalId2OID(node_id);
    114128    }
    115129
     
    120134    /** returns a list of the child ids in order, null if no children */
    121135    protected ArrayList getChildrenIds(String node_id) {
    122     DBInfo info = this.gdbm_src.getInfo(node_id);
     136    DBInfo info = this.coll_db.getInfo(node_id);
    123137    if (info == null) {
    124138        return null;
     
    156170    throws GSException {
    157171    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    158     DBInfo info = this.gdbm_src.getInfo(node_id);
     172    DBInfo info = this.coll_db.getInfo(node_id);
    159173    if (info == null) {
    160174        return null;
     
    211225        }
    212226       
    213         DBInfo info = this.gdbm_src.getInfo(parent_id);
     227        DBInfo info = this.coll_db.getInfo(parent_id);
    214228        if (info==null) {
    215229        return "-1";
     
    235249
    236250    protected int getNumChildren(String node_id) {
    237     DBInfo info = this.gdbm_src.getInfo(node_id);
     251    DBInfo info = this.coll_db.getInfo(node_id);
    238252    if (info == null) {
    239253        return 0;
     
    254268    */
    255269    protected String getDocType(String node_id) {
    256     DBInfo info = this.gdbm_src.getInfo(node_id);
     270    DBInfo info = this.coll_db.getInfo(node_id);
    257271    if (info == null) {
    258272        return GSXML.DOC_TYPE_SIMPLE;
     
    275289    // now we just check the top node
    276290    if (!is_top) { // we need to look at the top info
    277         info = this.gdbm_src.getInfo(top_id);
     291        info = this.coll_db.getInfo(top_id);
    278292    }
    279293    if (info == null) {
     
    370384        relation_info = info;
    371385    } else {
    372         relation_info = this.gdbm_src.getInfo(relation_id);
     386        relation_info = this.coll_db.getInfo(relation_id);
    373387    }
    374388    if (relation_info == null) {
     
    405419    relation_id = OID.getParent(current_id);
    406420    while (!relation_id.equals(current_id)) {
    407         relation_info = this.gdbm_src.getInfo(relation_id);
     421        relation_info = this.coll_db.getInfo(relation_id);
    408422        if (relation_info == null) return result.toString();
    409423        if (!multiple) {
     
    427441   
    428442
    429     /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
     443    /** needs to get info from collection database - if the calling code gets it already it may pay to pass it in instead */
    430444    protected String resolveTextMacros(String doc_content, String doc_id, String lang)
    431445    {
     
    452466        value="-1";
    453467        } else {
    454         DBInfo info = this.gdbm_src.getInfo(parent_id);
     468        DBInfo info = this.coll_db.getInfo(parent_id);
    455469        if (info==null) {
    456470            value ="-1";
     
    478492
    479493    protected String getHrefOID(String href_url){
    480         return this.gdbm_src.docnum2OID(href_url);
     494        return this.coll_db.docnum2OID(href_url);
    481495    }
    482496
Note: See TracChangeset for help on using the changeset viewer.