source: main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java@ 21400

Last change on this file since 21400 was 21395, checked in by davidb, 14 years ago

Initial implementation based on JDBM rather than GDBM to allow (one day) for Java-only based database to complement Java-based Lucene indexing

File size: 2.7 KB
Line 
1/**********************************************************************
2 *
3 * JdbKeys.java --
4 * A component of the Greenstone digital library software
5 * from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Copyright (C) 1999 The New Zealand Digital Library Project
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 **********************************************************************/
25
26import jdbm.RecordManager;
27import jdbm.RecordManagerFactory;
28import jdbm.helper.FastIterator;
29import jdbm.htree.HTree;
30
31import java.io.IOException;
32import java.util.Properties;
33
34
35public class JdbKeys
36{
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
80 public static void print_usage()
81 {
82 System.err.println("Usage: java JdbKeys database-name");
83 System.exit(-1);
84 }
85
86
87 public static void main(String[] args)
88 {
89 if (args.length != 1) {
90 print_usage();
91 }
92
93 String dbname = args[0];
94
95 try {
96
97 JdbKeys table = new JdbKeys(dbname);
98 table.get_keys();
99 }
100 catch (IOException e) {
101 e.printStackTrace();
102 }
103 }
104
105}
Note: See TracBrowser for help on using the repository browser.