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:
-
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 TypeMethodDescriptionvoidcheckLayerItemRecords(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.voidcopyDirectoryOutOf(String source, Path destination) voidcreateDirectory(String path) 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.getLayer(long id) Gets a layer by id.Gets the top layer or null if there is no 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.Creates 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.
-
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
-
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.- Specified by:
writeFilein interfaceItemStore- Parameters:
path- the path of the file relative to the storage rootcontent- the content to write- Throws:
IOException
-
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
-
createDirectory
- Specified by:
createDirectoryin interfaceItemStore- Throws:
IOException
-
copyDirectoryOutOf
- Specified by:
copyDirectoryOutOfin interfaceItemStore- Throws:
IOException
-
isAllowReadingContentFromArchives
public boolean isAllowReadingContentFromArchives() -
setAllowReadingContentFromArchives
public void setAllowReadingContentFromArchives(boolean allowReadingContentFromArchives)
-