Class LayeredItemStore

java.lang.Object
nl.knaw.dans.layerstore.LayeredItemStore
All Implemented Interfaces:
ItemStore

public class LayeredItemStore extends Object implements ItemStore
An implementation of ItemStore that organizes files and directories (Items) in an ordered stack of Layers. Layers are either staged or archived. Staged layers can be mutable. See

To materialize the layered store into a regular directory, unarchive any archived layers to staging directories and then copy those directories into a single target directory from oldest to newest. Files in newer layers overwrite files from older layers.

The LayeredItemStore is backed by a LayerDatabase, enabling storage on media that may be too slow for direct access (e.g., tape). See the LayerDatabase interface for details.

See Also:
  • Constructor Details

    • LayeredItemStore

      public LayeredItemStore(LayerDatabase database, LayerManager layerManager)
      Creates a new LayeredItemStore without a database-backed content manager.
      Parameters:
      database - the database to use
      layerManager - the layer manager to use
    • LayeredItemStore

      public LayeredItemStore(LayerDatabase database, LayerManager layerManager, DatabaseBackedContentManager databaseBackedContentManager)
      Creates a new LayeredItemStore.
      Parameters:
      database - the database to use
      layerManager - the layer manager to use
      databaseBackedContentManager - the database-backed content manager to use
  • Method Details

    • newTopLayer

      public Layer newTopLayer() throws IOException
      Creates a new top layer, archiving any existing top layer.
      Returns:
      the new top layer
      Throws:
      IOException - if an I/O error occurs
    • getLayer

      public Layer getLayer(long id) throws IOException
      Gets a layer by id.
      Parameters:
      id - the layer id
      Returns:
      the layer
      Throws:
      IOException - if an I/O error occurs
    • getTopLayer

      public Layer getTopLayer() throws IOException
      Gets the top layer or null if there is no top layer.
      Returns:
      the top layer or null if there is no top layer
      Throws:
      IOException - if an I/O error occurs while reading from the database or the layer manager
    • listLayerIds

      public List<Long> listLayerIds() throws IOException
      Throws:
      IOException
    • checkSameLayersOnStorageAndDb

      public void checkSameLayersOnStorageAndDb() throws IOException, LayerIdsMismatchException
      Checks that the layers in the database match the layers in the layer manager.
      Throws:
      IOException - if an I/O error occurs while reading from the database or the layer manager
      LayerIdsMismatchException - if the layer ids do not match
    • checkLayerItemRecords

      public void checkLayerItemRecords(long layerId) throws IOException, ItemsMismatchException
      Checks that the items in the database match the items in the layer.
      Parameters:
      layerId - the layer id to check
      Throws:
      IOException - if an I/O error occurs while reading from the layer or the database
      ItemsMismatchException - if the items do not match
    • listDirectory

      public List<Item> listDirectory(String directoryPath) throws IOException
      Description copied from interface: ItemStore
      Returns the items in the given directory, taking into account the complete stack of layers.
      Specified by:
      listDirectory in interface ItemStore
      Parameters:
      directoryPath - the directory path relative to the storage root
      Returns:
      the items in the directory
      Throws:
      NoSuchFileException - if the directory does not exist in any of the layers
      NotDirectoryException - if the path exists but is not a directory
      IOException
    • listRecursive

      public List<Item> listRecursive(String directoryPath) throws IOException
      Description copied from interface: ItemStore
      Returns the files and directories in the given directory and its subdirectories.
      Specified by:
      listRecursive in interface ItemStore
      Parameters:
      directoryPath - the directory path relative to the storage root
      Returns:
      the items in the directory and its subdirectories
      Throws:
      NoSuchFileException - if the directory does not exist in any of the layers
      NotDirectoryException - if the path exists but is not a directory
      IOException
    • existsPathLike

      public boolean existsPathLike(String path)
      Description copied from interface: ItemStore
      Returns whether a path with the given pattern exists in the store.
      Specified by:
      existsPathLike in interface ItemStore
      Parameters:
      path - a path, which may contain the SQL wildcard character '%'
      Returns:
      true if a path exists that matches the pattern, false otherwise
    • readFile

      public InputStream readFile(String path) throws IOException
      Description copied from interface: ItemStore
      Opens an input stream to the file at the given path.
      Specified by:
      readFile in interface ItemStore
      Parameters:
      path - the path of the file relative to the storage root
      Returns:
      an input stream to the file
      Throws:
      IOException - if the file could not be opened
    • writeFile

      public void writeFile(String path, InputStream content) throws IOException
      Description copied from interface: ItemStore
      Writes the given content to the file at the given path. If the file does not exist yet, it is created.
      Specified by:
      writeFile in interface ItemStore
      Parameters:
      path - the path of the file relative to the storage root
      content - the content to write
      Throws:
      IOException
    • moveDirectoryInto

      public void moveDirectoryInto(Path source, String destination) throws IOException
      Description copied from interface: ItemStore
      Moves the directory outside the store into the given destination. The parent of the destination must exist, but the destination itself must not exist yet.
      Specified by:
      moveDirectoryInto in interface ItemStore
      Parameters:
      source - the path of the directory to move
      destination - the path of the destination directory relative to the storage root
      Throws:
      IOException
    • moveDirectoryInternal

      public void moveDirectoryInternal(String source, String destination) throws IOException
      Description copied from interface: ItemStore
      Moves the directory inside the store to the given destination. The destination must not exist yet, but its parent must exist.
      Specified by:
      moveDirectoryInternal in interface ItemStore
      Parameters:
      source - the path of the directory to move relative to the storage root
      destination - the path of the destination directory relative to the storage root
      Throws:
      IOException
    • deleteDirectory

      public void deleteDirectory(String path) throws IOException
      Description copied from interface: ItemStore
      Deletes the directory at the given path, including all its contents.
      Specified by:
      deleteDirectory in interface ItemStore
      Parameters:
      path - the path of the directory relative to the storage root
      Throws:
      IOException
    • deleteFiles

      public void deleteFiles(List<String> paths) throws IOException
      Description copied from interface: ItemStore
      Deletes the files at the given paths.
      Specified by:
      deleteFiles in interface ItemStore
      Parameters:
      paths - the paths of the files relative to the storage root
      Throws:
      IOException
    • createDirectory

      public void createDirectory(String path) throws IOException
      Specified by:
      createDirectory in interface ItemStore
      Throws:
      IOException
    • copyDirectoryOutOf

      public void copyDirectoryOutOf(String source, Path destination) throws IOException
      Specified by:
      copyDirectoryOutOf in interface ItemStore
      Throws:
      IOException
    • isAllowReadingContentFromArchives

      public boolean isAllowReadingContentFromArchives()
    • setAllowReadingContentFromArchives

      public void setAllowReadingContentFromArchives(boolean allowReadingContentFromArchives)