Changeset 22973
- Timestamp:
- 2010-09-28T10:18:57+13:00 (13 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/JDBMWrapper.java
r21431 r22973 43 43 static String TNAME = "greenstone"; 44 44 45 RecordManager recman_ ;45 RecordManager recman_ = null; 46 46 HTree hashtable_; 47 48 String db_filename_; 47 49 48 50 static private PrintWriter utf8out = null; … … 74 76 // => assume the database must exist 75 77 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 77 89 try { 78 90 // create or open a record manager … … 91 103 if (must_exist) { 92 104 recman_.close(); 105 recman_ = null; 106 db_filename_ = null; 107 93 108 System.err.println("Database table '" + TNAME +"' does not exist."); 94 109 throw new IOException(); … … 106 121 } 107 122 123 db_filename_ = db_filename; 108 124 109 125 return true; … … 114 130 public void closeDatabase() { 115 131 try { 116 recman_.close(); 132 if (recman_ != null) { 133 recman_.close(); 134 recman_ = null; 135 db_filename_ = null; 136 } 117 137 } 118 138 catch (IOException e) { -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/SimpleCollectionDatabase.java
r22319 r22973 33 33 34 34 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 46 76 /** open the database filename, with mode mode - uses the FlatDatabaseWrapper modes */ 47 77 public boolean openDatabase(String filename, int mode){ … … 59 89 // logger.warn("All the entries of the db are:"); 60 90 // 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 } 61 98 62 99 String key_info = this.coll_db.getValue(main_key);
Note:
See TracChangeset
for help on using the changeset viewer.