- Timestamp:
- 2010-01-01T23:35:24+13:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java
r21395 r21402 6 6 * University of Waikato, New Zealand. 7 7 * 8 * Copyright (C) 1999 The New Zealand Digital Library Project8 * Copyright (C) 2009 The New Zealand Digital Library Project 9 9 * 10 10 * This program is free software; you can redistribute it and/or modify … … 26 26 import java.io.BufferedInputStream; 27 27 import java.io.InputStream; 28 import java.io.IOException; 29 30 import java.util.Properties; 28 31 29 32 import jdbm.RecordManager; … … 32 35 import jdbm.htree.HTree; 33 36 34 import java.io.IOException;35 import java.util.Properties;36 37 37 38 38 39 public class JdbSet 39 40 { 40 static String TNAME = "greenstone";41 42 RecordManager recman_;43 HTree hashtable_;44 45 public JdbSet(String db_filename)46 throws IOException47 {48 // create or open a record manager49 Properties props = new Properties();50 recman_ = RecordManagerFactory.createRecordManager(db_filename, props);51 52 // load existing table (if exists) otherwise create new one53 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 System.out.println("No database table '" + TNAME +"' to set. Creating new one");61 hashtable_ = HTree.createInstance(recman_);62 recman_.setNamedObject(TNAME, hashtable_.getRecid());63 }64 }65 66 public void append(String key, String val)67 throws IOException68 {69 70 String orig_val = (String)hashtable_.get(key);71 String new_val = orig_val + val;72 73 hashtable_.put(key,new_val);74 recman_.close();75 }76 77 public void set(String key, String val)78 throws IOException79 80 {81 hashtable_.put(key,val);82 recman_.close();83 }84 85 public void del(String key)86 throws IOException87 {88 hashtable_.remove(key);89 recman_.close();90 }91 92 93 41 public static void print_usage() 94 42 { 95 43 System.err.println("Usage: java JdbSet database-name key [value] [append]"); 96 System.err.println(" \t- if no value is given then the lexicon indicated by the key is removed");97 System.err.println(" \t- if a value is given followed by 'append' then the value is ");98 System.err.println(" \tadded to the existing entry rather than overwriting it");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"); 99 47 System.exit(-1); 100 48 } … … 112 60 try { 113 61 String dbname = args[0]; 114 Jdb Set table = new JdbSet(dbname);62 JdbmAPI jdbm_api = new JdbmAPI(dbname); 115 63 116 64 if (argc == 4) { … … 120 68 String val = args[2]; 121 69 122 table.append(key,val);70 jdbm_api.append(key,val); 123 71 } 124 72 else { … … 130 78 String key = args[1]; 131 79 String val = args[2]; 132 table.set(key,val);80 jdbm_api.set(key,val); 133 81 } 134 82 else { 135 83 String key = args[1]; 136 table.del(key);84 jdbm_api.delete(key); 137 85 } 86 87 jdbm_api.close(); 138 88 } 139 89
Note:
See TracChangeset
for help on using the changeset viewer.