Class RecordService
Record storage service.
It is configured to record 1 file per record in a given directory.
Record's identifiers are generated from UUID when created. This UUID is then used
as the name (with the .json suffix) of the file where content will be persisted.
Content is stored without any change (it won't include _id or _rev) inside of the file. Content can be any generic JSON structure: primitives, null, array or object.
Note that the following structure is used:
{
"id": "43c7d754-efc7-4838-a5da-782dd9c360c4",
"rev": "1ce6ce0e-387f-4ebe-8450-9d21ab5d71e5",
"content": {
"key": [ 42 ]
}
}
Record's revision is based on a UUID that change with each update. That provides a basic MVCC support.
Note that we don't provide full MVCC support: we don't keep older revisions of the records to allow concurrent reads on different versions.
As we don't expect high concurrency and high performance is not a requirement, data consistency is guaranteed with the usage of synchronized methods.
-
Constructor Summary
ConstructorsConstructorDescriptionRecordService(File directory) Creates aRecordServicethat will record resources in the given directory. -
Method Summary
-
Constructor Details
-
RecordService
Creates aRecordServicethat will record resources in the given directory.- Parameters:
directory- storage directory- Throws:
IOException- when the givendirectoryis not a directory and/or cannot be created
-
-
Method Details
-
create
Store the given content on disk and returns aRecordthat represents the new resource.- Parameters:
content- content to be stored (cannot benull)- Returns:
- a new
Recordwith a newly generated UUID - Throws:
IOException- if resource storage failed
-
find
- Parameters:
id- record's identifier- Returns:
- the found record or
nullif not found - Throws:
IOException- if record loading from file has failed
-
delete
public org.forgerock.openig.ui.record.Record delete(String id, String revision) throws IOException, org.forgerock.openig.ui.record.RecordException - Parameters:
id- record to delete identifierrevision- expected revision (can be set tonullif revision has to be ignored)- Returns:
- the found record or
nullif not found - Throws:
IOException- if deleted record loading from file has failedorg.forgerock.openig.ui.record.RecordException- if stored record has a revision that does not match the expected one
-
update
public org.forgerock.openig.ui.record.Record update(String id, String revision, JsonValue newContent) throws IOException, org.forgerock.openig.ui.record.RecordException Update theRecordidentified byid(possibly at a givenrevision) with the providedcontent. The backing file will first be deleted and then re-created with the newcontent.- Parameters:
id- record to updaterevision- expected revision (can be set tonullif revision has to be ignored)newContent- new content (cannot benull)- Returns:
- the updated record or
nullis resource is not found - Throws:
IOException- if updated record deletion or re-creation failedorg.forgerock.openig.ui.record.RecordException- if stored record has a revision that does not match the expected one
-
listAll
List all persisted records from the file system.- Returns:
- all persisted records
- Throws:
IOException- if one of the record cannot be loaded
-