Ignore:
Timestamp:
2008-05-29T13:29:54+12:00 (16 years ago)
Author:
oranfry
Message:

updating from trunk: brought in trunk changes from r15191 to r15785

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r14527 r15787  
    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);
     67    this.macro_resolver = new GS2MacroResolver();
    6968    }
    7069
    7170    public void cleanUp() {
    72     super.cleanUp();
    73     this.gdbm_src.closeDatabase();
     71        super.cleanUp();
     72        this.coll_db.closeDatabase();
    7473    }
    7574    /** configure this service */
     
    9392    }
    9493
    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!");
     94    // find out what kind of database we have
     95    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     96    String database_type = null;
     97    if (database_type_elem != null) {
     98      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     99    }
     100    if (database_type == null || database_type.equals("")) {
     101      database_type = "gdbm"; // the default
     102    }
     103    coll_db = new SimpleCollectionDatabase(database_type);
     104    if (coll_db == null) {
     105      logger.error("Couldn't create the collection database of type "+database_type);
     106      return false;
     107    }
     108   
     109    // Open database for querying
     110    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type);
     111    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     112        logger.error("Could not open collection database!");
    99113        return false;
    100114    }
     115
     116    // we need to set the database for our GS2 macro resolver
     117    GS2MacroResolver gs2_macro_resolver = (GS2MacroResolver)this.macro_resolver;
     118    gs2_macro_resolver.setDB(this.coll_db);
    101119
    102120    return true;
     
    105123    /** if id ends in .fc, .pc etc, then translate it to the correct id */
    106124    protected String translateId(String node_id) {
    107     return this.gdbm_src.translateOID(node_id);
     125    return this.coll_db.translateOID(node_id);
    108126    }
    109127   
     
    111129    it to a greenstone one*/
    112130    protected String translateExternalId(String node_id){
    113     return this.gdbm_src.externalId2OID(node_id);
     131    return this.coll_db.externalId2OID(node_id);
    114132    }
    115133
     
    120138    /** returns a list of the child ids in order, null if no children */
    121139    protected ArrayList getChildrenIds(String node_id) {
    122     DBInfo info = this.gdbm_src.getInfo(node_id);
     140    DBInfo info = this.coll_db.getInfo(node_id);
    123141    if (info == null) {
    124142        return null;
     
    156174    throws GSException {
    157175    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    158     DBInfo info = this.gdbm_src.getInfo(node_id);
     176    DBInfo info = this.coll_db.getInfo(node_id);
    159177    if (info == null) {
    160178        return null;
     
    211229        }
    212230       
    213         DBInfo info = this.gdbm_src.getInfo(parent_id);
     231        DBInfo info = this.coll_db.getInfo(parent_id);
    214232        if (info==null) {
    215233        return "-1";
     
    235253
    236254    protected int getNumChildren(String node_id) {
    237     DBInfo info = this.gdbm_src.getInfo(node_id);
     255    DBInfo info = this.coll_db.getInfo(node_id);
    238256    if (info == null) {
    239257        return 0;
     
    254272    */
    255273    protected String getDocType(String node_id) {
    256     DBInfo info = this.gdbm_src.getInfo(node_id);
     274    DBInfo info = this.coll_db.getInfo(node_id);
    257275    if (info == null) {
    258276        return GSXML.DOC_TYPE_SIMPLE;
     
    275293    // now we just check the top node
    276294    if (!is_top) { // we need to look at the top info
    277         info = this.gdbm_src.getInfo(top_id);
     295        info = this.coll_db.getInfo(top_id);
    278296    }
    279297    if (info == null) {
     
    337355   
    338356    // now check for relational info
    339     if (temp.equals("parent") || temp.equals("root") || temp.equals( "ancestors")) { // "current" "siblings" "children" "descendents"
     357    if (temp.equals("parent") || temp.equals("root") || temp.equals( "ancestors")) { // "current" "siblings" "children" "descendants"
    340358        relation = temp;
    341359        pos = metadata.indexOf(GSConstants.META_RELATION_SEP);
     
    370388        relation_info = info;
    371389    } else {
    372         relation_info = this.gdbm_src.getInfo(relation_id);
     390        relation_info = this.coll_db.getInfo(relation_id);
    373391    }
    374392    if (relation_info == null) {
     
    405423    relation_id = OID.getParent(current_id);
    406424    while (!relation_id.equals(current_id)) {
    407         relation_info = this.gdbm_src.getInfo(relation_id);
     425        relation_info = this.coll_db.getInfo(relation_id);
    408426        if (relation_info == null) return result.toString();
    409427        if (!multiple) {
     
    427445   
    428446
    429     /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
     447    /** needs to get info from collection database - if the calling code gets it already it may pay to pass it in instead */
    430448    protected String resolveTextMacros(String doc_content, String doc_id, String lang)
    431449    {
     
    452470        value="-1";
    453471        } else {
    454         DBInfo info = this.gdbm_src.getInfo(parent_id);
     472        DBInfo info = this.coll_db.getInfo(parent_id);
    455473        if (info==null) {
    456474            value ="-1";
     
    478496
    479497    protected String getHrefOID(String href_url){
    480         return this.gdbm_src.docnum2OID(href_url);
     498        return this.coll_db.docnum2OID(href_url);
    481499    }
    482500
Note: See TracChangeset for help on using the changeset viewer.