Ignore:
Timestamp:
2010-01-01T23:35:24+13:00 (14 years ago)
Author:
davidb
Message:

Refactoring of class to use API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/jdbmedit/JdbmAPI.java

    r21401 r21402  
    4545    HTree          hashtable_;
    4646
    47     public JdbmAPI(String db_filename)
     47    public JdbmAPI(String db_filename,boolean must_exist)
    4848    throws IOException
    4949    {
     
    5656
    5757    if (recid != 0) {
    58         System.out.println("Loading existing database table '" + TNAME +"' ...");
     58        System.err.println("# Loading existing database table '" + TNAME +"' ...");
    5959        hashtable_ = HTree.load(recman_, recid);
    6060    }
    6161    else {
    62         System.out.println("No database table '" + TNAME +"' to set.  Creating new one");
    63         hashtable_ = HTree.createInstance(recman_);
    64         recman_.setNamedObject(TNAME, hashtable_.getRecid());
    65     }
     62
     63        if (must_exist) {
     64        recman_.close();
     65        System.err.println("Database table '" + TNAME +"' does not exist.");
     66        throw new IOException();
     67        }
     68        else {
     69        System.err.println("# No database table '" + TNAME +"' to set.  Creating new one");
     70        hashtable_ = HTree.createInstance(recman_);
     71        recman_.setNamedObject(TNAME, hashtable_.getRecid());
     72        }
     73    }
     74    }
     75
     76    public JdbmAPI(String db_filename)
     77    throws IOException
     78    {
     79    // default is that database does not have to exist
     80    this(db_filename,false);
    6681    }
    6782   
    6883    public void append(String key, String val)
    6984    throws IOException
    70     {
    71            
     85    {           
    7286    String orig_val = (String)hashtable_.get(key);           
    7387    String new_val = orig_val + val;
     
    127141    {
    128142    recman_.close();
     143    System.err.println("# Done");
    129144    }
    130145
Note: See TracChangeset for help on using the changeset viewer.