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/SimpleCollectionDatabase.java

    r22319 r22973  
    3333 
    3434  public SimpleCollectionDatabase(String db_type) {
    35     if (db_type.equalsIgnoreCase("gdbm")) {
    36       this.coll_db = new GDBMWrapper();
    37     }
    38     else if (db_type.equalsIgnoreCase("jdbm")) {
    39       this.coll_db = new JDBMWrapper();
    40     }
    41     else {
    42       logger.error("Couldn't create SimpleCollectionDatabase of type "+db_type);
    43     }   
    44   }
    45  
     35
     36      // Access databaseWrapper through reflection (forName) so code
     37      // can be more dynamic as to the database backends that are
     38      // supported for this installation of Greenstone
     39
     40      String dbwrap_name = db_type.toUpperCase() + "Wrapper";
     41      Class dbwrap_class = null;
     42
     43      try {
     44      String full_dbwrap_name = "org.greenstone.gsdl3.util."+dbwrap_name;
     45      dbwrap_class = Class.forName(full_dbwrap_name);
     46      }
     47      catch(ClassNotFoundException e) {
     48      try {
     49          //try the dbwrap_name alone in case the package name is
     50          //already specified
     51          dbwrap_class = Class.forName(dbwrap_name);
     52      }
     53      catch(ClassNotFoundException ae) {
     54          logger.error("Couldn't create SimpleCollectionDatabase of type "+db_type);
     55          logger.info(ae.getMessage());
     56      }
     57      }
     58
     59      try {
     60      this.coll_db = (FlatDatabaseWrapper)dbwrap_class.newInstance();
     61      }
     62      catch(Exception e) {
     63          logger.error("Failed to call the constructor "+dbwrap_name+"()");
     64      }
     65
     66
     67  }
     68 
     69  public boolean databaseOK() {
     70      // Previously failed to open database
     71      // Most likely cause is that this installation of Greenstone3 has not
     72      // been compiled with support for this database type
     73      return coll_db != null;
     74  }
     75
    4676  /** open the database filename, with mode mode - uses the FlatDatabaseWrapper modes */
    4777  public boolean openDatabase(String filename, int mode){
     
    5989      //   logger.warn("All the entries of the db are:");
    6090      //   this.coll_db.displayAllEntries();
     91
     92     
     93    if (this.coll_db==null) {
     94    // Most likely cause is that this installation of Greenstone3 has not
     95    // been compiled with support for this database type
     96    return null;
     97    }
    6198
    6299    String key_info = this.coll_db.getValue(main_key);
Note: See TracChangeset for help on using the changeset viewer.