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

    r21395 r21402  
    66 * University of Waikato, New Zealand.
    77 *
    8  * Copyright (C) 1999  The New Zealand Digital Library Project
     8 * Copyright (C) 2009  The New Zealand Digital Library Project
    99 *
    1010 * This program is free software; you can redistribute it and/or modify
     
    3838public class JdbDel
    3939{
    40     static String TNAME = "greenstone";
    41 
    42     RecordManager  recman_;
    43     HTree          hashtable_;
    44 
    45     public JdbDel(String db_filename)
    46     throws IOException
    47     {
    48         // create or open a record manager
    49         Properties props = new Properties();
    50         recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
    51 
    52         // load existing table (if exists) otherwise report error
    53         long recid = recman_.getNamedObject(TNAME);
    54 
    55     if (recid != 0) {
    56         System.out.println("Loading existing database table '" + TNAME +"' ...");
    57         hashtable_ = HTree.load(recman_, recid);
    58     }
    59     else {
    60         recman_.close();
    61         System.out.println("No database table '" + TNAME +"' to delete key from.");
    62         System.exit(-1);
    63     }
    64     }
    65    
    66 
    67     public void del(String key)
    68     throws IOException
    69     {
    70     hashtable_.remove(key);
    71     recman_.close();
    72     }
    73    
    74 
    7540    public static void print_usage()
    7641    {
     
    9156    try {
    9257        String dbname = args[0];
    93         JdbDel table = new JdbDel(dbname);
     58        JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
    9459       
    9560        String key = args[1];
    96         table.del(key);
     61
     62        jdbm_api.delete(key);
     63        jdbm_api.close();
    9764    }
    9865
Note: See TracChangeset for help on using the changeset viewer.