Package nl.knaw.dans.layerstore
Class LayeredItemStore
java.lang.Object
nl.knaw.dans.layerstore.LayeredItemStore
- All Implemented Interfaces:
ItemStore
An implementation of FileStore that stores files and directories as a stack of layers. A layer can be staged or archived. Staged layers can be modified, archived layers are read-only. To transform
the layered file store into a regular file system directory, each layer must be unarchived (if it was archived) to a staging directory. The staging directories must be copied into a single
directory, starting with the oldest layer and ending with the newest layer. Files in newer layers overwrite files in older layers.
The LayeredFileStore is backed by a LayerDatabase to support storage of layers in a way that may not be fast enough for direct access, for example, on tape. See the LayerDatabase interface for more information.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLayeredItemStore
(LayerDatabase database, LayerManager layerManager) Creates a new LayeredItemStore without a database-backed content manager.LayeredItemStore
(LayerDatabase database, LayerManager layerManager, DatabaseBackedContentManager databaseBackedContentManager) Creates a new LayeredItemStore. -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkLayerItemRecords
(long layerId) Checks that the items in the database match the items in the layer.void
Checks that the layers in the database match the layers in the layer manager.void
copyDirectoryOutOf
(String source, Path destination) void
createDirectory
(String path) void
deleteDirectory
(String path) Deletes the directory at the given path, including all its contents.void
deleteFiles
(List<String> paths) Deletes the files at the given paths.boolean
existsPathLike
(String path) Returns whether a path with the given pattern exists in the store.getLayer
(long id) Gets a layer by id.Gets the top layer or null if there is no top layer.listDirectory
(String directoryPath) Returns the items in the given directory, taking into account the complete stack of layers.listRecursive
(String directoryPath) Returns the files and directories in the given directory and its subdirectories.void
moveDirectoryInternal
(String source, String destination) Moves the directory inside the store to the given destination.void
moveDirectoryInto
(Path source, String destination) Moves the directory outside the store into the given destination.Creates a new top layer, archiving any existing top layer.Opens an input stream to the file at the given path.void
writeFile
(String path, InputStream content) Writes the given content to the file at the given path.
-
Constructor Details
-
LayeredItemStore
Creates a new LayeredItemStore without a database-backed content manager.- Parameters:
database
- the database to uselayerManager
- the layer manager to use
-
LayeredItemStore
public LayeredItemStore(LayerDatabase database, LayerManager layerManager, DatabaseBackedContentManager databaseBackedContentManager) Creates a new LayeredItemStore.- Parameters:
database
- the database to uselayerManager
- the layer manager to usedatabaseBackedContentManager
- the database-backed content manager to use
-
-
Method Details
-
newTopLayer
Creates a new top layer, archiving any existing top layer.- Returns:
- the new top layer
- Throws:
IOException
- if an I/O error occurs
-
getLayer
Gets a layer by id.- Parameters:
id
- the layer id- Returns:
- the layer
- Throws:
IOException
- if an I/O error occurs
-
getTopLayer
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
-
checkSameLayersOnStorageAndDb
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 managerLayerIdsMismatchException
- if the layer ids do not match
-
checkLayerItemRecords
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 databaseItemsMismatchException
- if the items do not match
-
listDirectory
Description copied from interface:ItemStore
Returns the items in the given directory, taking into account the complete stack of layers.- Specified by:
listDirectory
in interfaceItemStore
- 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 layersNotDirectoryException
- if the path exists but is not a directoryIOException
-
listRecursive
Description copied from interface:ItemStore
Returns the files and directories in the given directory and its subdirectories.- Specified by:
listRecursive
in interfaceItemStore
- 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 layersNotDirectoryException
- if the path exists but is not a directoryIOException
-
existsPathLike
Description copied from interface:ItemStore
Returns whether a path with the given pattern exists in the store.- Specified by:
existsPathLike
in interfaceItemStore
- Parameters:
path
- a path, which may contain the SQL wildcard character '%'- Returns:
- true if a path exists that matches the pattern, false otherwise
-
readFile
Description copied from interface:ItemStore
Opens an input stream to the file at the given path.- Specified by:
readFile
in interfaceItemStore
- 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
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 interfaceItemStore
- Parameters:
path
- the path of the file relative to the storage rootcontent
- the content to write- Throws:
IOException
-
moveDirectoryInto
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 interfaceItemStore
- Parameters:
source
- the path of the directory to movedestination
- the path of the destination directory relative to the storage root- Throws:
IOException
-
moveDirectoryInternal
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 interfaceItemStore
- Parameters:
source
- the path of the directory to move relative to the storage rootdestination
- the path of the destination directory relative to the storage root- Throws:
IOException
-
deleteDirectory
Description copied from interface:ItemStore
Deletes the directory at the given path, including all its contents.- Specified by:
deleteDirectory
in interfaceItemStore
- Parameters:
path
- the path of the directory relative to the storage root- Throws:
IOException
-
deleteFiles
Description copied from interface:ItemStore
Deletes the files at the given paths.- Specified by:
deleteFiles
in interfaceItemStore
- Parameters:
paths
- the paths of the files relative to the storage root- Throws:
IOException
-
createDirectory
- Specified by:
createDirectory
in interfaceItemStore
- Throws:
IOException
-
copyDirectoryOutOf
- Specified by:
copyDirectoryOutOf
in interfaceItemStore
- Throws:
IOException
-