Class SpringXMLKVDatabase

All Implemented Interfaces:
KVDatabase, Serializable

public class SpringXMLKVDatabase extends XMLKVDatabase
XMLKVDatabase that adds support for loading the default initial content from any Spring Resource. For example, this allows initial content to be loaded from the classpath.

Instances are serializable if the configured StreamRepository and default initial content resource are.

See Also:
  • Constructor Details

  • Method Details

    • setInitialContentResource

      public void setInitialContentResource(Resource initialContentResource)
      Configure the Resource containing default initial content for an uninitialized database. This method is invoked by getInitialContent() when, on the first load, the backing XML file is not found.
      Parameters:
      initialContentResource - resource containing default initial XML database content, or null for none
    • setInitialContentFile

      public void setInitialContentFile(File initialContentFile)
      Configure the Resource containing default initial content for an uninitialized database from the specified file.
      Overrides:
      setInitialContentFile in class XMLKVDatabase
      Parameters:
      initialContentFile - file containing default initial XML database content, or null for none
    • getInitialContent

      protected InputStream getInitialContent() throws IOException
      Get the initial content for an uninitialized database. This method is invoked when, on the first load, the backing XML file is not found. It should return a stream that reads initial content for the database, if any, otherwise null.

      The implementation in SpringXMLKVDatabase returns an InputStream acquired from the Resource configured by setInitialContentResource(), if any, otherwise null.

      Overrides:
      getInitialContent in class XMLKVDatabase
      Returns:
      default initial XML database content, or null for none
      Throws:
      IOException - if an error occurs accessing the initial content file