Package org.fcrepo.storage.ocfl
Class DefaultOcflObjectSession
java.lang.Object
org.fcrepo.storage.ocfl.DefaultOcflObjectSession
- All Implemented Interfaces:
AutoCloseable,OcflObjectSession
Default OcflObjectSession implementation.
- Author:
- pwinckles
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultOcflObjectSession(String sessionId, io.ocfl.api.MutableOcflRepository ocflRepo, String ocflObjectId, Path objectStaging, com.fasterxml.jackson.databind.ObjectReader headerReader, com.fasterxml.jackson.databind.ObjectWriter headerWriter, CommitType commitType, Cache<String, ResourceHeaders> headersCache, Cache<String, String> rootIdCache, HeadersValidator headersValidator, boolean useUnsafeWrite) -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts the session, abandoning all changes.voidclose()voidcommit()Commits the session, persisting all changes to a new OCFL version.voidcommitType(CommitType commitType) Sets the commit behavior -- create a new version or update the mutable HEAD.booleancontainsResource(String resourceId) Indicates if the resource exists in the sessionvoiddeleteContentFile(ResourceHeaders headers) Deletes a content file from the session, and updates the associated headers.voiddeleteResource(String resourceId) Deletes all files associated to the specified resource.voidinvalidateCache(String resourceId) Invalidate the cache for a Fedora resource's headersbooleanisOpen()listVersions(String resourceId) List all of the versions associated to the resource in chrolological order.readContent(String resourceId) Reads a resource's content.readContent(String resourceId, String versionNumber) Reads a specific version of a resource's content.readHeaders(String resourceId) Reads a resource's header file.readHeaders(String resourceId, String versionNumber) Reads a specific version of a resource's header file.Reads a range of bytes of a resource's content.Reads a range of bytes from a specific version of a resource's content.voidrollback()Rolls back an already committed session, permanently removing the OCFL object version that was created by the session.This method is NOT currently using the ResourceHeader cache.voidversionAuthor(String name, String address) Sets the author the OCFL version is attributed to.voidversionCreationTimestamp(OffsetDateTime timestamp) Sets the timestamp that's stamped on the OCFL version.voidversionMessage(String message) Sets the OCFL version message.voidwriteHeaders(ResourceHeaders headers) Writes the resources headers to the session.writeResource(ResourceHeaders headers, InputStream content) Writes a resource to the session.
-
Constructor Details
-
DefaultOcflObjectSession
public DefaultOcflObjectSession(String sessionId, io.ocfl.api.MutableOcflRepository ocflRepo, String ocflObjectId, Path objectStaging, com.fasterxml.jackson.databind.ObjectReader headerReader, com.fasterxml.jackson.databind.ObjectWriter headerWriter, CommitType commitType, Cache<String, ResourceHeaders> headersCache, Cache<String, String> rootIdCache, HeadersValidator headersValidator, boolean useUnsafeWrite)
-
-
Method Details
-
sessionId
- Specified by:
sessionIdin interfaceOcflObjectSession- Returns:
- the id of the session
-
ocflObjectId
- Specified by:
ocflObjectIdin interfaceOcflObjectSession- Returns:
- the OCFL object id of the object the session is on
-
writeResource
Description copied from interface:OcflObjectSessionWrites a resource to the session.- Specified by:
writeResourcein interfaceOcflObjectSession- Parameters:
headers- the resource's headerscontent- the resource's content, may be null if the resource has no content- Returns:
- the resource headers that were written to disk, these may differ from the input headers
-
writeHeaders
Description copied from interface:OcflObjectSessionWrites the resources headers to the session.- Specified by:
writeHeadersin interfaceOcflObjectSession- Parameters:
headers- the headers to write
-
deleteContentFile
Description copied from interface:OcflObjectSessionDeletes a content file from the session, and updates the associated headers. If the resource was added in the current session, then its headers are also deleted and it is as if the resource never existed.- Specified by:
deleteContentFilein interfaceOcflObjectSession- Parameters:
headers- the updated resource headers
-
deleteResource
Description copied from interface:OcflObjectSessionDeletes all files associated to the specified resource. If the resource is the root resource of the object, then the object will be deleted.- Specified by:
deleteResourcein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id of the resource to delete
-
containsResource
Description copied from interface:OcflObjectSessionIndicates if the resource exists in the session- Specified by:
containsResourcein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id- Returns:
- true if the resource exists in the session
-
readHeaders
Description copied from interface:OcflObjectSessionReads a resource's header file.- Specified by:
readHeadersin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's headers
-
readHeaders
Description copied from interface:OcflObjectSessionReads a specific version of a resource's header file.- Specified by:
readHeadersin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's headers
-
readContent
Description copied from interface:OcflObjectSessionReads a resource's content.- Specified by:
readContentin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to read- Returns:
- the resource's content
-
readContent
Description copied from interface:OcflObjectSessionReads a specific version of a resource's content.- Specified by:
readContentin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEAD- Returns:
- the resource's content
-
readRange
Description copied from interface:OcflObjectSessionReads a range of bytes of a resource's content.- Specified by:
readRangein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readstartPosition- the position to start reading from, inclusiveendPosition- the position to stop reading at, inclusive- Returns:
- the range of the resources content
-
readRange
public ResourceContent readRange(String resourceId, String versionNumber, long startPosition, long endPosition) Description copied from interface:OcflObjectSessionReads a range of bytes from a specific version of a resource's content.- Specified by:
readRangein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to readversionNumber- the version to read, or null for HEADstartPosition- the position to start reading from, inclusiveendPosition- the position to stop reading at, inclusive- Returns:
- the range of the resources content
-
listVersions
Description copied from interface:OcflObjectSessionList all of the versions associated to the resource in chrolological order.- Specified by:
listVersionsin interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id- Returns:
- list of versions
-
streamResourceHeaders
This method is NOT currently using the ResourceHeader cache. It should not matter because this method is currently only used when reindexing. If it is ever used anywhere else, we may want to figure out how to get it to use the cache.- Specified by:
streamResourceHeadersin interfaceOcflObjectSession- Returns:
- ResourceHeader stream
-
versionCreationTimestamp
Description copied from interface:OcflObjectSessionSets the timestamp that's stamped on the OCFL version. If this value is not set, the current system time at the time the version is created is used.- Specified by:
versionCreationTimestampin interfaceOcflObjectSession- Parameters:
timestamp- version creation timestamp
-
versionAuthor
Description copied from interface:OcflObjectSessionSets the author the OCFL version is attributed to.- Specified by:
versionAuthorin interfaceOcflObjectSession- Parameters:
name- the author's nameaddress- the author's address
-
versionMessage
Description copied from interface:OcflObjectSessionSets the OCFL version message.- Specified by:
versionMessagein interfaceOcflObjectSession- Parameters:
message- the OCFL version message
-
invalidateCache
Description copied from interface:OcflObjectSessionInvalidate the cache for a Fedora resource's headers- Specified by:
invalidateCachein interfaceOcflObjectSession- Parameters:
resourceId- the Fedora resource id to read
-
commitType
Description copied from interface:OcflObjectSessionSets the commit behavior -- create a new version or update the mutable HEAD.- Specified by:
commitTypein interfaceOcflObjectSession- Parameters:
commitType- the commit behavior
-
commit
public void commit()Description copied from interface:OcflObjectSessionCommits the session, persisting all changes to a new OCFL version.- Specified by:
commitin interfaceOcflObjectSession
-
abort
public void abort()Description copied from interface:OcflObjectSessionAborts the session, abandoning all changes.- Specified by:
abortin interfaceOcflObjectSession
-
rollback
public void rollback()Description copied from interface:OcflObjectSessionRolls back an already committed session, permanently removing the OCFL object version that was created by the session. Sessions may only be rolled back when auto-versioning in enabled. Calling this method on a session that has not yet been committed does nothing.- Specified by:
rollbackin interfaceOcflObjectSession
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceOcflObjectSession
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceOcflObjectSession- Returns:
- true if the session is still open
-