source: main/trunk/greenstone2/common-src/src/jdbmedit/JdbDel.java@ 21395

Last change on this file since 21395 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.6 KB
RevLine 
[21395]1/**********************************************************************
2 *
3 * JdbDel.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 java.io.BufferedInputStream;
27import java.io.InputStream;
28
29import jdbm.RecordManager;
30import jdbm.RecordManagerFactory;
31import jdbm.helper.FastIterator;
32import jdbm.htree.HTree;
33
34import java.io.IOException;
35import java.util.Properties;
36
37
38public class JdbDel
39{
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
75 public static void print_usage()
76 {
77 System.err.println("Usage: java JdbDel database-name key");
78 System.exit(-1);
79 }
80
81
82 public static void main(String[] args)
83 {
84 int argc = args.length;
85
86 // sanity check
87 if (argc!=2) {
88 print_usage();
89 }
90
91 try {
92 String dbname = args[0];
93 JdbDel table = new JdbDel(dbname);
94
95 String key = args[1];
96 table.del(key);
97 }
98
99 catch (IOException e) {
100 e.printStackTrace();
101 }
102
103 }
104
105}
106
107
Note: See TracBrowser for help on using the repository browser.