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/JdbKeys.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
     
    2424 **********************************************************************/
    2525
     26import java.io.IOException;
     27import java.util.Properties;
     28import java.util.ArrayList;
     29
    2630import jdbm.RecordManager;
    2731import jdbm.RecordManagerFactory;
     
    2933import jdbm.htree.HTree;
    3034
    31 import java.io.IOException;
    32 import java.util.Properties;
    33 
    34 
    3535public class JdbKeys
    3636{
    37     static String TNAME = "greenstone";
    38 
    39     RecordManager  recman_;
    40     HTree          hashtable_;
    41 
    42 
    43     public JdbKeys(String db_filename)
    44     throws IOException
    45     {
    46         // create or open a record manager
    47         Properties props = new Properties();
    48         recman_ = RecordManagerFactory.createRecordManager(db_filename, props);
    49 
    50         // create or load table
    51         long recid = recman_.getNamedObject(TNAME);
    52         if (recid != 0) {
    53             hashtable_ = HTree.load(recman_, recid);
    54         }
    55     else {
    56             System.err.println("Failed to find database table '" + TNAME +"' ...");
    57         System.exit(-1);
    58         }
    59     }
    60 
    61 
    62     public void get_keys()
    63         throws IOException
    64     {
    65     FastIterator   iter;
    66     String         key;
    67     String         val;
    68 
    69         iter = hashtable_.keys();
    70         key = (String) iter.next();
    71         while (key != null) {
    72             System.out.println(key);
    73             key = (String) iter.next();
    74         }
    75        
    76         recman_.close();
    77     }
    78 
    79 
    8037    public static void print_usage()
    8138    {
     
    9552        try {
    9653
    97             JdbKeys table = new JdbKeys(dbname);
    98             table.get_keys();
     54            JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
     55
     56        ArrayList keys = jdbm_api.get_keys();
     57           
     58        int keys_len = keys.size();
     59        for (int i=0; i<keys_len; i++) {
     60        String key = (String) keys.get(i);
     61        System.out.println(key);
     62        }
     63
     64        jdbm_api.close();
    9965        }
    10066    catch (IOException e) {
Note: See TracChangeset for help on using the changeset viewer.