Ignore:
Timestamp:
2010-09-28T10:18:57+13:00 (14 years ago)
Author:
davidb
Message:

Code changed to use Class.forName to dynamically load required database wrapper class (e.g. GDBMWrapper or JDBMWrapper). This is so the code can be compiled up with some of these database wrapper classes optionally switched out (e.g. name changed to .java.tmp). Additional routine also added to test is a database is open. In JDBMWrapper, the close routine was modified so it only closes the database one. Our code seems to call 'cleanup' more than once, and letting it close a JDBMWrapper class a second time throws an exception deep within JDBM implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/JDBMWrapper.java

    r21431 r22973  
    4343    static String TNAME = "greenstone";
    4444
    45     RecordManager  recman_;
     45    RecordManager  recman_ = null;
    4646    HTree          hashtable_;
     47
     48    String db_filename_;
    4749
    4850    static private PrintWriter utf8out = null;
     
    7476      // => assume the database must exist
    7577      boolean must_exist = true; // default
    76      
     78
     79      if (recman_ != null) {
     80      String message = "openDatabase() called when the class already has a database open\n";
     81      message += "  Use closeDatabase before opening the next one.\n";
     82      message += "  Existing database file: " + db_filename_ + "\n";
     83      message += "  New database file:      " + db_filename + "\n";
     84      logger.warn(message);
     85      // consider closing it automatically?
     86      }
     87
     88
    7789      try {
    7890      // create or open a record manager
     
    91103          if (must_exist) {
    92104          recman_.close();
     105          recman_ = null;
     106          db_filename_ = null;
     107
    93108          System.err.println("Database table '" + TNAME +"' does not exist.");
    94109          throw new IOException();
     
    106121      }
    107122
     123      db_filename_ = db_filename;
    108124
    109125      return true;
     
    114130  public void closeDatabase() {
    115131      try {
    116       recman_.close();
     132      if (recman_ != null) {
     133          recman_.close();
     134          recman_ = null;
     135          db_filename_ = null;
     136      }
    117137      }
    118138      catch (IOException e) {     
Note: See TracChangeset for help on using the changeset viewer.