Changeset 30260

Show
Ignore:
Timestamp:
28.09.2015 10:37:36 (4 years ago)
Author:
jmt12
Message:

Replacing hardcoded database file extensions with call to DBHelper (which keeps track of registered dbtypes and their extensions). This also required a slight reordering of the code to ensure the static constructor for the dbtype had been called prior to asking for the extension

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ArchiveRetrieve.java

    r28966 r30260  
    2121package org.greenstone.gsdl3.service; 
    2222 
     23import org.greenstone.gsdl3.util.DBHelper; 
    2324import org.greenstone.gsdl3.util.DBInfo; 
    2425import org.greenstone.gsdl3.util.GSPath; 
     
    139140        return result; 
    140141    } 
    141      
     142 
     143 
     144     /** @function processSourceFileOIDRetrieveService(Element) 
     145     *  @brief 
     146     *  @param request 
     147     *  @return Element 
     148     */ 
    142149    protected Element processSourceFileOIDRetrieveService(Element request) 
    143150    { 
     
    168175            databaseType = "gdbm"; // the default 
    169176        } 
    170          
    171         String dbExt = null; 
    172         if (databaseType.equalsIgnoreCase("jdbm"))  
    173         { 
    174             dbExt = ".jdb"; 
    175         }  
    176         else  
    177         { 
    178             dbExt = ".gdb"; // assume gdbm 
    179         } 
    180          
     177 
    181178        coll_db = new SimpleCollectionDatabase(databaseType); 
    182179        if (!coll_db.databaseOK())  
     
    185182            return null; 
    186183        } 
     184 
     185    // Moved to ensure that the appropriate FlatDatabaseWrapper 
     186    // has been initialised during the SimpleCollectionDatabase 
     187    // call above. That way we can easily retrieve the database 
     188    // extension from the DBHelper [jmt12] 
     189    String dbExt = DBHelper.getDBExtFromDBType(databaseType); 
     190    if (null == dbExt || dbExt.equals("")) { 
     191       // assume gdbm 
     192       logger.warn("Could not recognise database type \"" + databaseType + "\", defaulting to GDBM and extension \".gdb\""); 
     193       dbExt = ".gdb"; 
     194    } 
    187195 
    188196        coll_db.openDatabase 
     
    211219        return result; 
    212220    } 
    213      
     221    /** processSourceFileOIDRetrieveService(Element) **/ 
     222 
    214223    protected Element processAssociatedImportFilesRetrieve(Element request) 
    215224    { 
     
    240249        } 
    241250         
    242         String dbExt = null; 
    243         if (databaseType.equalsIgnoreCase("jdbm"))  
    244         { 
    245             dbExt = ".jdb"; 
    246         }  
    247         else  
    248         { 
    249             dbExt = ".gdb"; // assume gdbm 
    250         } 
    251          
    252251        coll_db = new SimpleCollectionDatabase(databaseType); 
    253252        if (!coll_db.databaseOK())  
     
    257256        } 
    258257 
     258    // Moved to ensure that the appropriate FlatDatabaseWrapper 
     259    // has been initialised during the SimpleCollectionDatabase 
     260    // call above. That way we can easily retrieve the database 
     261    // extension from the DBHelper. 
     262    String dbExt = DBHelper.getDBExtFromDBType(databaseType); 
     263    if (null == dbExt || dbExt.equals("")) 
     264    { 
     265        // assume gdbm 
     266        logger.warn("Could not recognise database type \"" + databaseType + "\", defaulting to GDBM and extension \".gdb\""); 
     267        dbExt = ".gdb"; 
     268    } 
     269         
    259270        coll_db.openDatabase 
    260271        (