Changeset 13706


Ignore:
Timestamp:
2007-01-19T16:16:22+13:00 (15 years ago)
Author:
mdewsnip
Message:

The second half of speeding up metadata access and editing substantially (particularly when metadata.xml files are large) by caching one metadata.xml file in memory. The loaded metadata.xml file is no longer written to disk every time a piece of metadata is added/edited, but only when a new metadata.xml file is loaded.

Location:
trunk/gli/src/org/greenstone/gatherer/metadata
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java

    r13577 r13706  
    4848    static private File loaded_file = null;
    4949    static private Document loaded_file_document = null;
     50    static private boolean loaded_file_changed = false;
    5051
    5152
     
    6061    // If this metadata.xml file isn't the one currently loaded, load it now
    6162    if (loaded_file != this) {
     63        // First we must save out the currently loaded file
     64        saveLoadedFile();
     65
    6266        // Parse the metadata.xml file
    6367        Document document = XMLTools.parseXMLFile(this);
     
    177181    }
    178182
    179     // Rewrite the metadata.xml file
    180     XMLTools.writeXMLFile(this, loaded_file_document);
     183    // Remember that we've changed the file so it gets saved when a new one is loaded
     184    loaded_file_changed = true;
    181185    }
    182186
     
    186190    // If this metadata.xml file isn't the one currently loaded, load it now
    187191    if (loaded_file != this) {
     192        // First we must save out the currently loaded file
     193        saveLoadedFile();
     194
    188195        // Parse the metadata.xml file
    189196        Document document = XMLTools.parseXMLFile(this);
     
    319326    // If this metadata.xml file isn't the one currently loaded, load it now
    320327    if (loaded_file != this) {
     328        // First we must save out the currently loaded file
     329        saveLoadedFile();
     330
    321331        // Parse the metadata.xml file
    322332        Document document = XMLTools.parseXMLFile(this);
     
    413423    }
    414424
    415     // Rewrite the metadata.xml file
    416     XMLTools.writeXMLFile(this, loaded_file_document);
     425    // Remember that we've changed the file so it gets saved when a new one is loaded
     426    loaded_file_changed = true;
    417427    }
    418428
     
    422432    // If this metadata.xml file isn't the one currently loaded, load it now
    423433    if (loaded_file != this) {
     434        // First we must save out the currently loaded file
     435        saveLoadedFile();
     436
    424437        // Parse the metadata.xml file
    425438        Document document = XMLTools.parseXMLFile(this);
     
    524537    }
    525538
    526     // Rewrite the metadata.xml file
    527     XMLTools.writeXMLFile(this, loaded_file_document);
     539    // Remember that we've changed the file so it gets saved when a new one is loaded
     540    loaded_file_changed = true;
     541    }
     542
     543
     544    static public void saveLoadedFile()
     545    {
     546    // If we have a file loaded into memory and it has been modified, save it now
     547    if (loaded_file != null && loaded_file_changed == true) {
     548        XMLTools.writeXMLFile(loaded_file, loaded_file_document);
     549        loaded_file_changed = false;
     550    }
    528551    }
    529552
  • trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java

    r13705 r13706  
    356356    static public void saveMetadataXMLFiles()
    357357    {
     358    // Save the file currently loaded into memory out to disk
     359    MetadataXMLFile.saveLoadedFile();
     360
    358361    // If the collection is stored on a remote server, upload all the modified files now
    359362    if (Gatherer.isGsdlRemote) {
Note: See TracChangeset for help on using the changeset viewer.