Class RecordService
- java.lang.Object
-
- org.forgerock.openig.ui.record.RecordService
-
public class RecordService extends Object
File-basedRecord
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
Constructors Constructor Description RecordService(File directory)
Creates aRecordService
that will record resources in the given directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.forgerock.openig.ui.record.Record
create(JsonValue content)
Store the given content on disk and returns aRecord
that represents the new resource.org.forgerock.openig.ui.record.Record
delete(String id, String revision)
Deletes aRecord
identified byid
(possibly at a givenrevision
), returnsnull
if not found.org.forgerock.openig.ui.record.Record
find(String id)
Find aRecord
with the givenid
, returnsnull
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, JsonValue newContent)
Update theRecord
identified byid
(possibly at a givenrevision
) with the providedcontent
.
-
-
-
Constructor Detail
-
RecordService
public RecordService(File directory) throws IOException
Creates aRecordService
that will record resources in the given directory.- Parameters:
directory
- storage directory- Throws:
IOException
- when the givendirectory
is not a directory and/or cannot be created
-
-
Method Detail
-
create
public org.forgerock.openig.ui.record.Record create(JsonValue content) throws IOException
Store the given content on disk and returns aRecord
that represents the new resource.- Parameters:
content
- content to be stored (cannot benull
)- Returns:
- a new
Record
with a newly generated UUID - Throws:
IOException
- if resource storage failed
-
find
public org.forgerock.openig.ui.record.Record find(String id) throws IOException
Find aRecord
with the givenid
, returnsnull
if not found.- Parameters:
id
- record's identifier- Returns:
- the found record or
null
if 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
Deletes aRecord
identified byid
(possibly at a givenrevision
), returnsnull
if not found.- Parameters:
id
- record to delete identifierrevision
- expected revision (can be set tonull
if revision has to be ignored)- Returns:
- the found record or
null
if 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 theRecord
identified 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 tonull
if revision has to be ignored)newContent
- new content (cannot benull
)- Returns:
- the updated record or
null
is 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
public Set<org.forgerock.openig.ui.record.Record> listAll() throws IOException
List all persisted records from the file system.- Returns:
- all persisted records
- Throws:
IOException
- if one of the record cannot be loaded
-
-