1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * JdbSet.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) 2009 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 |
|
---|
26 | import java.io.BufferedInputStream;
|
---|
27 | import java.io.InputStream;
|
---|
28 | import java.io.IOException;
|
---|
29 |
|
---|
30 | import java.util.Properties;
|
---|
31 |
|
---|
32 | import jdbm.RecordManager;
|
---|
33 | import jdbm.RecordManagerFactory;
|
---|
34 | import jdbm.helper.FastIterator;
|
---|
35 | import jdbm.htree.HTree;
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | public class JdbSet
|
---|
40 | {
|
---|
41 | public static void print_usage()
|
---|
42 | {
|
---|
43 | System.err.println("Usage: java JdbSet database-name key [value] [append]");
|
---|
44 | System.err.println(" - if no value is given then the lexicon indicated by the key is removed");
|
---|
45 | System.err.println(" - if a value is given followed by 'append' then the value is ");
|
---|
46 | System.err.println(" added to the existing entry rather than overwriting it");
|
---|
47 | System.exit(-1);
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | public static void main(String[] args)
|
---|
52 | {
|
---|
53 | int argc = args.length;
|
---|
54 |
|
---|
55 | // sanity check
|
---|
56 | if ((argc < 2) || (argc>4)) {
|
---|
57 | print_usage();
|
---|
58 | }
|
---|
59 |
|
---|
60 | try {
|
---|
61 | String dbname = args[0];
|
---|
62 | JdbmAPI jdbm_api = new JdbmAPI(dbname);
|
---|
63 |
|
---|
64 | if (argc == 4) {
|
---|
65 |
|
---|
66 | if (args[3].equals("append")) {
|
---|
67 | String key = args[1];
|
---|
68 | String val = args[2];
|
---|
69 |
|
---|
70 | jdbm_api.append(key,val);
|
---|
71 | }
|
---|
72 | else {
|
---|
73 | System.err.println("Error: Unrecognised option " + args[3]);
|
---|
74 | print_usage();
|
---|
75 | }
|
---|
76 | }
|
---|
77 | else if (argc == 3) {
|
---|
78 | String key = args[1];
|
---|
79 | String val = args[2];
|
---|
80 | jdbm_api.set(key,val);
|
---|
81 | }
|
---|
82 | else {
|
---|
83 | String key = args[1];
|
---|
84 | jdbm_api.delete(key);
|
---|
85 | }
|
---|
86 |
|
---|
87 | jdbm_api.close();
|
---|
88 | }
|
---|
89 |
|
---|
90 | catch (IOException e) {
|
---|
91 | e.printStackTrace();
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|