Changeset 15326


Ignore:
Timestamp:
2008-05-01T13:59:09+12:00 (14 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

Location:
greenstone3/trunk/src/java/org/greenstone/gsdl3/service
Files:
12 edited

Legend:

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

    r14526 r15326  
    725725     */
    726726    abstract protected String getStructureInfo(String node_id, String info_type);   
    727 //      /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
    728 //     protected String resolveTextMacros(String doc_content, String doc_id, String lang)
    729 //     {
    730 //  DBInfo info = null;
    731 //  if (doc_content.indexOf("_httpdocimg_")!=-1) {
    732 //      String top_doc_id = OID.getTop(doc_id);
    733 //      info = this.gdbm_src.getInfo(top_doc_id);
    734 //      if (info == null) {
    735 //      // perhaps we had per.iods in the ids - just try the current id
    736 //      top_doc_id = doc_id;
    737 //      info = this.gdbm_src.getInfo(top_doc_id);
    738 //      }
    739 //      if (info != null) {
    740 //      String archivedir = info.getInfo("archivedir");
    741 //      String image_dir  = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir;
    742        
    743 //      // Resolve all "_httpdocimg_"s
    744 //      doc_content = doc_content.replaceAll("_httpdocimg_", image_dir);
    745 //      }
    746 //  }
    747 //  // resolve any collection specific macros
    748 //  doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id, info);
    749 //  return doc_content;
    750 //     }
    751 
    752727   
    753728}   
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java

    r14552 r15326  
    2222
    2323// Greenstone classes
    24 //import org.greenstone.gdbm.*;
    2524import org.greenstone.gsdl3.core.GSException;
    2625import org.greenstone.gsdl3.util.GSXML;
  • 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
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java

    r15041 r15326  
    7575
    7676    protected static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
    77     protected static final String DEFAULT_GDBM_LEVEL_ELEM = "defaultGDBMLevel";
     77    protected static final String DEFAULT_DB_LEVEL_ELEM = "defaultDBLevel";
    7878    protected static final String LEVEL_ELEM = "level";
    7979    protected static final String FIELD_ATT = "field";
     
    9090   // the default level for searching
    9191    protected String default_level=null;
    92     // default level for gdbm db
    93     protected String default_gdbm_level = null;
     92    // default level for collection db
     93    protected String default_db_level = null;
    9494    // which search services will we offer??
    9595    protected boolean plain_search = false;
     
    162162    }
    163163
    164     // Get the default GDBM level
    165     def = (Element) GSXML.getChildByTagName(info, DEFAULT_GDBM_LEVEL_ELEM);
     164    // Get the default DB level
     165    def = (Element) GSXML.getChildByTagName(info, DEFAULT_DB_LEVEL_ELEM);
    166166    if (def != null) {
    167         this.default_gdbm_level = def.getAttribute(GSXML.SHORTNAME_ATT);
    168     }
    169     if (this.default_gdbm_level == null || this.default_gdbm_level.equals("")) {
    170         logger.error("default gdbm level not specified!, assuming Sec");
    171         this.default_gdbm_level = "Sec";
     167        this.default_db_level = def.getAttribute(GSXML.SHORTNAME_ATT);
     168    }
     169    if (this.default_db_level == null || this.default_db_level.equals("")) {
     170        logger.error("default database level (defaultDBLevel) not specified!, assuming Sec");
     171        this.default_db_level = "Sec";
    172172    }
    173173   
  • 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    }
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r13962 r15326  
    2525import org.greenstone.gsdl3.util.MacroResolver;
    2626import org.greenstone.gsdl3.util.GS2MacroResolver;
    27 import org.greenstone.gsdl3.util.GDBMWrapper;
     27import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
    2828import org.greenstone.gsdl3.util.DBInfo;
    2929// XML classes
     
    5252     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2Browse.class.getName());
    5353
    54     protected GDBMWrapper gdbm_src = null;
     54    protected SimpleCollectionDatabase coll_db = null;
    5555
    5656    public GS2Browse()
    5757    {
    58     this.gdbm_src = new GDBMWrapper();
    59     this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
    6058    }
    6159
    6260    public void cleanUp() {
    6361    super.cleanUp();
    64     this.gdbm_src.closeDatabase();
     62    this.coll_db.closeDatabase();
    6563    }
    6664
     
    8280    }
    8381   
    84     // Open GDBM database for querying
    85     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, index_stem);
    86     if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    87         logger.error("Could not open GDBM database!");
     82    // find out what kind of database we have
     83    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     84    String database_type = null;
     85    if (database_type_elem != null) {
     86      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     87    }
     88    if (database_type == null || database_type.equals("")) {
     89      database_type = "gdbm"; // the default
     90    }
     91    coll_db = new SimpleCollectionDatabase(database_type);
     92    if (coll_db == null) {
     93      logger.error("Couldn't create the collection database of type "+database_type);
     94      return false;
     95    }
     96   
     97    // Open database for querying
     98    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
     99    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     100        logger.error("Could not open collection database!");
    88101        return false;
    89102    }
     103    this.macro_resolver = new GS2MacroResolver(this.coll_db);
    90104    return true;
    91105    }
     
    93107    /** if id ends in .fc, .pc etc, then translate it to the correct id */
    94108    protected String translateId(String node_id) {
    95     return this.gdbm_src.translateOID(node_id);
     109    return this.coll_db.translateOID(node_id);
    96110    }
    97111
     
    103117    */
    104118    protected String getDocType(String node_id) {
    105     DBInfo info = this.gdbm_src.getInfo(node_id);
     119    DBInfo info = this.coll_db.getInfo(node_id);
    106120    if (info == null) {
    107121        return GSXML.DOC_TYPE_SIMPLE;
     
    124138    // now we just check the top node
    125139    if (!is_top) { // we need to look at the top info
    126         info = this.gdbm_src.getInfo(top_id);
     140        info = this.coll_db.getInfo(top_id);
    127141    }
    128142    if (info == null) {
     
    144158    /** returns a list of the child ids in order, null if no children */
    145159    protected ArrayList getChildrenIds(String node_id) {
    146     DBInfo info = this.gdbm_src.getInfo(node_id);
     160    DBInfo info = this.coll_db.getInfo(node_id);
    147161    if (info == null) {
    148162        return null;
     
    170184
    171185    protected String getMetadata(String node_id, String key){
    172     DBInfo info = this.gdbm_src.getInfo(node_id);
     186    DBInfo info = this.coll_db.getInfo(node_id);
    173187    if (info == null) {
    174188        return "";
     
    200214    String lang = "en";
    201215    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    202     DBInfo info = this.gdbm_src.getInfo(node_id);
     216    DBInfo info = this.coll_db.getInfo(node_id);
    203217    if (info == null) {
    204218        return null;
     
    251265        }
    252266       
    253         DBInfo info = this.gdbm_src.getInfo(parent_id);
     267        DBInfo info = this.coll_db.getInfo(parent_id);
    254268        if (info==null) {
    255269        return "-1";
     
    275289
    276290    protected int getNumChildren(String node_id) {
    277     DBInfo info = this.gdbm_src.getInfo(node_id);
     291    DBInfo info = this.coll_db.getInfo(node_id);
    278292    if (info == null) {
    279293        return 0;
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2LuceneRetrieve.java

    r13916 r15326  
    2323import org.greenstone.gsdl3.util.GSFile;
    2424import org.greenstone.gsdl3.util.GSXML;
    25 import org.greenstone.gsdl3.util.GDBMWrapper;
    2625import org.greenstone.gsdl3.util.DBInfo;
    2726import org.greenstone.gsdl3.util.GSHTML;
     
    109108        }
    110109       
    111         long doc_num = this.gdbm_src.OID2Docnum(doc_id);
    112         if (doc_num == -1) {
     110        String doc_num = this.coll_db.OID2Docnum(doc_id);
     111        if (doc_num == null || doc_num.equals("")) {
    113112        throw new Exception("OID "+doc_id +" couldn't be converted to lucene doc num");
    114113        }
    115114   
    116         DBInfo info=this.gdbm_src.getInfo(OID.getTop(doc_id));
     115        DBInfo info=this.coll_db.getInfo(OID.getTop(doc_id));
    117116        if (info == null) {
    118         throw new Exception("Couldn't get GDBM database entry for "+OID.getTop(doc_id));
     117        throw new Exception("Couldn't get database entry for "+OID.getTop(doc_id));
    119118        }
    120119       
     
    136135        current_section = full_document;
    137136        } else {
    138         current_section = GSXML.getNamedElement(full_document, SEC_LEVEL, ID_ATT, String.valueOf(doc_num));
     137        current_section = GSXML.getNamedElement(full_document, SEC_LEVEL, ID_ATT, doc_num);
    139138        }
    140139        if (current_section == null) {
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java

    r14441 r15326  
    9393   */
    9494  protected Element getNodeContent(String doc_id, String lang) throws GSException {
    95     long doc_num = this.gdbm_src.OID2Docnum(doc_id);
     95    long doc_num = this.coll_db.OID2DocnumLong(doc_id);
    9696    if (doc_num == -1) {
    9797      logger.error("OID "+doc_id +" couldn't be converted to mgpp num");
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java

    r14752 r15326  
    2020
    2121// Greenstone classes
    22 import org.greenstone.mgpp.*;
    23 import org.greenstone.gsdl3.util.*;
     22import org.greenstone.mgpp.MGPPSearchWrapper;
     23import org.greenstone.mgpp.MGPPTermInfo;
     24import org.greenstone.mgpp.MGPPQueryResult;
     25import org.greenstone.mgpp.MGPPDocInfo;
     26
     27import org.greenstone.gsdl3.util.GSFile;
     28import org.greenstone.gsdl3.util.GSXML;
     29
    2430
    2531// XML classes
     
    6672  /** process a  query */
    6773  protected Element processAnyQuery(Element request, int query_type) {
    68       synchronized (mgpp_src) {
    69           return super.processAnyQuery(request, query_type);
    70       }
     74    synchronized (mgpp_src) {
     75      return super.processAnyQuery(request, query_type);
     76    }
    7177  }
    7278  /** configure this service */
     
    7682    }
    7783   
    78     // the default level is also the level which gdbm is expecting
     84    // the default level is also the level which the database is expecting
    7985    // this must not be overwritten
    80     mgpp_src.setReturnLevel(this.default_gdbm_level);
     86    mgpp_src.setReturnLevel(this.default_db_level);
    8187    // return term info
    8288    mgpp_src.setReturnTerms(true);
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java

    r14936 r15326  
    2020
    2121// Greenstone classes
    22 import org.greenstone.mg.*;
     22import org.greenstone.mg.MGRetrieveWrapper;
    2323import org.greenstone.gsdl3.core.GSException;
    2424import org.greenstone.gsdl3.util.GSFile;
     
    113113     */
    114114    protected Element getNodeContent (String doc_id, String lang) throws GSException {
    115         long doc_num = this.gdbm_src.OID2Docnum (doc_id);
     115        long doc_num = this.coll_db.OID2DocnumLong (doc_id);
    116116        if (doc_num == -1) {
    117117            logger.error ("OID "+doc_id +" couldn't be converted to mg num");
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java

    r15123 r15326  
    3737  extends GS2MGPPSearch {
    3838   static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
    39    protected GDBMWrapper gdbm_src = null;
    4039 
    4140    /** constructor */
    4241    public GoogleNgramMGPPSearch(){
    43     super();
    44     gdbm_src = new GDBMWrapper();
    45    
     42    super();   
    4643    }
    4744   
     
    5249    }
    5350
    54     // Open GDBM database for querying
    55     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
    56         if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    57         logger.error("Could not open GDBM database!");
    58         return false;
    59     }
    6051    this.default_max_docs = "-1";
    6152    this.default_hits_per_page = "30";
     
    7869          String num = Long.toString((((MGPPDocInfo) docs.elementAt(d)).num_));
    7970          String doc_id = internalNum2OID(num);
    80           DBInfo gdbmInfo = this.gdbm_src.getInfo(doc_id);
    81           String fre = (String)gdbmInfo.getInfo("Frequency");
    82           String tense = (String)gdbmInfo.getInfo("Tense");
     71          DBInfo dbInfo = this.coll_db.getInfo(doc_id);
     72          String fre = (String)dbInfo.getInfo("Frequency");
     73          String tense = (String)dbInfo.getInfo("Tense");
    8374         
    8475          if(!fre.equals("")){
  • 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:xiao@cs.waikato.ac.nz">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.