public class RecordService extends Object
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 and Description |
---|
RecordService(File directory)
Creates a
RecordService that will record resources in the given directory. |
Modifier and Type | Method and Description |
---|---|
org.forgerock.openig.ui.record.Record |
create(org.forgerock.json.JsonValue content)
Store the given content on disk and returns a
Record that represents the new resource. |
org.forgerock.openig.ui.record.Record |
delete(String id,
String revision)
Deletes a
Record identified by id (possibly at a given revision ),
returns null if not found. |
org.forgerock.openig.ui.record.Record |
find(String id)
Find a
Record with the given id , returns null if not found. |
Set<org.forgerock.openig.ui.record.Record> |
listAll()
List all persisted records from the file system.
|
org.forgerock.openig.ui.record.Record |
update(String id,
String revision,
org.forgerock.json.JsonValue newContent)
Update the
Record identified by id (possibly at a given revision )
with the provided content . |
public RecordService(File directory) throws IOException
RecordService
that will record resources in the given directory.directory
- storage directoryIOException
- when the given directory
is not a directory and/or cannot be createdpublic org.forgerock.openig.ui.record.Record create(org.forgerock.json.JsonValue content) throws IOException
Record
that represents the new resource.content
- content to be stored (cannot be null
)Record
with a newly generated UUIDIOException
- if resource storage failedpublic org.forgerock.openig.ui.record.Record find(String id) throws IOException
Record
with the given id
, returns null
if not found.id
- record's identifiernull
if not foundIOException
- if record loading from file has failedpublic org.forgerock.openig.ui.record.Record delete(String id, String revision) throws IOException, org.forgerock.openig.ui.record.RecordException
Record
identified by id
(possibly at a given revision
),
returns null
if not found.id
- record to delete identifierrevision
- expected revision (can be set to null
if revision has to be ignored)null
if not foundIOException
- if deleted record loading from file has failedRecordException
- if stored record has a revision that does not match the expected onepublic org.forgerock.openig.ui.record.Record update(String id, String revision, org.forgerock.json.JsonValue newContent) throws IOException, org.forgerock.openig.ui.record.RecordException
Record
identified by id
(possibly at a given revision
)
with the provided content
.
The backing file will first be deleted and then re-created with the new content
.id
- record to updaterevision
- expected revision (can be set to null
if revision has to be ignored)newContent
- new content (cannot be null
)null
is resource is not foundIOException
- if updated record deletion or re-creation failedRecordException
- if stored record has a revision that does not match the expected onepublic Set<org.forgerock.openig.ui.record.Record> listAll() throws IOException
IOException
- if one of the record cannot be loadedCopyright © 2025 Open Identity Platform Community. All rights reserved.