Package nl.knaw.dans.layerstore
Class LayeredItemStore
java.lang.Object
nl.knaw.dans.layerstore.LayeredItemStore
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidarchiveLayer(long layerId, boolean overwrite) Requests the archiving of the layer with the specified id.voidcheckLayerItemRecords(long layerId) Checks that the items in the database match the items in the layer.voidChecks that the layers in the database match the layers in the layer manager.voidcloseLayer(long id) Closes the layer with the given id.voidcopyDirectoryOutOf(String source, Path destination) Copies the contents of a specified directory from the store to a given destination outside the store.voidcreateDirectories(String path) Creates the directory at the specified path, including any necessary but nonexistent parent directories.voiddeleteDirectory(String path) Deletes the directory at the given path, including all its contents.voiddeleteFiles(List<String> paths) Deletes the files at the given paths.booleanexistsPathLike(String path) Returns whether a path with the given pattern exists in the store.Returns the internal layer consistency checker.longgetLayerSizeInBytes(long id) Returns the size in bytes of the layer with the given id.Returns the id of the top layer, ornullif there is no top layer.longReturns the size in bytes of the top layer.booleanlistDirectory(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.voidmoveDirectoryInternal(String source, String destination) Moves the directory inside the store to the given destination.voidmoveDirectoryInto(Path source, String destination) Moves the directory outside the store into the given destination.longCreates a new top layer, archiving any existing top layer.Opens an input stream to the file at the given path.voidsetAllowReadingContentFromArchives(boolean allowReadingContentFromArchives) voidwriteFile(String path, InputStream content) Writes the given content to the file at the given path.
-
Method Details
-
getLayerConsistencyChecker
Returns the internal layer consistency checker.- Returns:
- the layer consistency checker
-
newTopLayer
Creates a new top layer, archiving any existing top layer.- Returns:
- the id of the new top layer
- Throws:
IOException- if an I/O error occurs
-
archiveLayer
public void archiveLayer(long layerId, boolean overwrite) Requests the archiving of the layer with the specified id. The operation may be performed asynchronously, so the caller should check the layer's status to determine when the archiving is complete.- Parameters:
layerId- the id of the layer to archiveoverwrite- whether to overwrite an existing archive- Throws:
IllegalArgumentException- if no layer with the specified id exists
-
closeLayer
Closes the layer with the given id.- Parameters:
id- the layer id- Throws:
IOException- if an I/O error occurs
-
getTopLayerId
Returns the id of the top layer, ornullif there is no top layer.- Returns:
- the id of the top layer or
null
-
getTopLayerSizeInBytes
Returns the size in bytes of the top layer.- Returns:
- the size in bytes of the top layer
- Throws:
IOException- if an I/O error occurs
-
getLayerSizeInBytes
Returns the size in bytes of the layer with the given id.- Parameters:
id- the layer id- Returns:
- the size in bytes
- Throws:
IOException- if an I/O error occurs
-
listLayerIds
- Throws:
IOException
-
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:ItemStoreReturns the items in the given directory, taking into account the complete stack of layers.- Specified by:
listDirectoryin 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:ItemStoreReturns the files and directories in the given directory and its subdirectories.- Specified by:
listRecursivein 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:ItemStoreReturns whether a path with the given pattern exists in the store.- Specified by:
existsPathLikein 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:ItemStoreOpens an input stream to the file at the given path.- Specified by:
readFilein 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:ItemStoreWrites the given content to the file at the given path. If the file does not exist yet, it is created. Note that this is different from the behavior of io.ocfl.core.storage.common.Storage#write(java.lang.String, byte[], java.lang.String), which throws an exception if the file already exists. Note also that the parent directory of the file must exist prior to this call. It can be created withItemStore.createDirectories(String)- Specified by:
writeFilein interfaceItemStore- Parameters:
path- the path of the file relative to the storage rootcontent- the content to write- Throws:
IOException- if the file could not be written
-
moveDirectoryInto
Description copied from interface:ItemStoreMoves 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:
moveDirectoryIntoin 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:ItemStoreMoves the directory inside the store to the given destination. The destination must not exist yet, but its parent must exist.- Specified by:
moveDirectoryInternalin 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:ItemStoreDeletes the directory at the given path, including all its contents.- Specified by:
deleteDirectoryin interfaceItemStore- Parameters:
path- the path of the directory relative to the storage root- Throws:
IOException
-
deleteFiles
Description copied from interface:ItemStoreDeletes the files at the given paths.- Specified by:
deleteFilesin interfaceItemStore- Parameters:
paths- the paths of the files relative to the storage root- Throws:
IOException
-
createDirectories
Description copied from interface:ItemStoreCreates the directory at the specified path, including any necessary but nonexistent parent directories. If the directory already exists, no exception is thrown. If a regular file exists at the given path, a java.nio.FileAlreadyExistsException is thrown.- Specified by:
createDirectoriesin interfaceItemStore- Parameters:
path- the path of the directory to create, relative to the storage root- Throws:
IOException- if an I/O error occurs while creating the directories
-
copyDirectoryOutOf
Description copied from interface:ItemStoreCopies the contents of a specified directory from the store to a given destination outside the store. The destination directory will be created if it does not exist.- Specified by:
copyDirectoryOutOfin interfaceItemStore- Parameters:
source- the path of the directory to copy, relative to the storage rootdestination- the target filesystem path where the directory content will be copied- Throws:
IOException- if an I/O error occurs during the copy process
-
isAllowReadingContentFromArchives
public boolean isAllowReadingContentFromArchives() -
setAllowReadingContentFromArchives
public void setAllowReadingContentFromArchives(boolean allowReadingContentFromArchives)
-