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

    r14209 r15326  
    2727import org.greenstone.gsdl3.util.XMLConverter;
    2828
    29 import org.greenstone.gsdl3.util.GDBMWrapper;
     29import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
    3030import org.greenstone.gsdl3.util.DBInfo;
    3131// XML classes
     
    4545import java.util.Map.Entry;
    4646
    47 import org.apache.log4j.*;
     47import org.apache.log4j.Logger;
    4848
    4949/** Implements the oai metadata retrieval service for GS3 collections.
    50  *  Dig into each collection's gdbm database and retrieve the metadata
     50 *  Dig into each collection's database and retrieve the metadata
    5151 *
    5252 * @author <a href="mailto:[email protected]">Xiao</a>
     
    5757  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.OAIPMH.class.getName());
    5858 
    59   protected GDBMWrapper gdbm_src = null;
     59  protected SimpleCollectionDatabase coll_db = null;
    6060 
    6161  protected String site_name = "";
     
    6565  /** constructor */
    6666  public OAIPMH() {
    67     this.gdbm_src = new GDBMWrapper();
     67
    6868  }
    6969 
    7070  public void cleanUp() {
    7171    super.cleanUp();//??
    72     this.gdbm_src.closeDatabase();
     72    this.coll_db.closeDatabase();
    7373  }
    7474  /** configure this service */
     
    8989    this.config_info = info;
    9090   
    91     // the index stem is either specified in the buildConfig.xml file or uses the collection name
    92     Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM);
    93     String index_stem = null;
    94     if (index_stem_elem != null) {
    95         index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
    96     }
    97     if (index_stem == null || index_stem.equals("")) {
    98         index_stem = this.cluster_name;
    99     }
     91    // the index stem is either specified in the buildConfig.xml file or uses the collection name
     92    Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM);
     93    String index_stem = null;
     94    if (index_stem_elem != null) {
     95      index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
     96    }
     97    if (index_stem == null || index_stem.equals("")) {
     98      index_stem = this.cluster_name;
     99    }
    100100 
    101     // Open GDBM database for querying
    102     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, index_stem);
    103     if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    104       logger.error("Could not open GDBM database!");
     101    // find out what kind of database we have
     102    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     103    String database_type = null;
     104    if (database_type_elem != null) {
     105      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     106    }
     107    if (database_type == null || database_type.equals("")) {
     108      database_type = "gdbm"; // the default
     109    }
     110    coll_db = new SimpleCollectionDatabase(database_type);
     111    if (coll_db == null) {
     112      logger.error("Couldn't create the collection database of type "+database_type);
    105113      return false;
    106114    }
    107 
     115   
     116    // Open database for querying
     117    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
     118    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     119      logger.error("Could not open collection database!");
     120      return false;
     121    }
     122   
    108123    // the short_service_info is used by the message router to find the method names,
    109124    //so we just use the doc variable in class ServiceRack to create the xml; but
     
    214229    //get a DBInfo object of the identifier; if this identifier is not present in the database,
    215230    // null is returned.
    216     DBInfo info = this.gdbm_src.getInfo(oid);
     231    DBInfo info = this.coll_db.getInfo(oid);
    217232    if (info == null) {
    218233      logger.error("OID: " + oid + " is not present in the database.");
     
    294309    for(int i=0; i<oid_list.size(); i++) {
    295310      String oid = (String)oid_list.get(i);
    296       DBInfo info = this.gdbm_src.getInfo(oid);
     311      DBInfo info = this.coll_db.getInfo(oid);
    297312      if (info == null) {
    298313        logger.error("Database does not contains information about oid: " +oid);
     
    386401    for(int i=0; i<oid_list.size(); i++) {
    387402      String oid = (String)oid_list.get(i);
    388       DBInfo info = this.gdbm_src.getInfo(oid);
     403      DBInfo info = this.coll_db.getInfo(oid);
    389404      if (info == null) {
    390405        logger.error("Database does not contains information about oid: " +oid);
     
    506521   
    507522    DBInfo info = null;   
    508     info = this.gdbm_src.getInfo(oid);
     523    info = this.coll_db.getInfo(oid);
    509524    if (info == null) { //just double check
    510525      return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.OAI_SERVICE_UNAVAILABLE, ""));
     
    577592  /** returns a list of the child ids in order, null if no children */
    578593  protected ArrayList getChildrenIds(String node_id) {
    579     DBInfo info = this.gdbm_src.getInfo(node_id);
     594    DBInfo info = this.coll_db.getInfo(node_id);
    580595    if (info == null) {
    581596      return null;
     
    614629  } 
    615630    /** @param keys - contains a list of keys in string format.
    616      * Here is a typical record in the gdbm database, 'keys' contains the values in <...>:
     631     * Here is a typical record in the collection database, 'keys' contains the values in <...>:
    617632     *----------------------------------------------------------------------
    618633[HASH01a84acb0f1aad2380493b3a]
Note: See TracChangeset for help on using the changeset viewer.