Class RecordService
- java.lang.Object
-
- org.forgerock.openig.ui.record.RecordService
-
public class RecordService extends Object
File-basedRecordstorage service.It is configured to record 1 file per record in a given
directory.Record's identifiers are generated from
UUIDwhen 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 aRecordServicethat 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.Recordcreate(org.forgerock.json.JsonValue content)Store the given content on disk and returns aRecordthat represents the new resource.org.forgerock.openig.ui.record.Recorddelete(String id, String revision)Deletes aRecordidentified byid(possibly at a givenrevision), returnsnullif not found.org.forgerock.openig.ui.record.Recordfind(String id)Find aRecordwith the givenid, returnsnullif not found.Set<org.forgerock.openig.ui.record.Record>listAll()List all persisted records from the file system.org.forgerock.openig.ui.record.Recordupdate(String id, String revision, org.forgerock.json.JsonValue newContent)Update theRecordidentified byid(possibly at a givenrevision) with the providedcontent.
-
-
-
Constructor Detail
-
RecordService
public RecordService(File directory) throws IOException
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 Detail
-
create
public org.forgerock.openig.ui.record.Record create(org.forgerock.json.JsonValue content) throws IOExceptionStore 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
public org.forgerock.openig.ui.record.Record find(String id) throws IOException
Find aRecordwith the givenid, returnsnullif not found.- 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
Deletes aRecordidentified byid(possibly at a givenrevision), returnsnullif not found.- 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, org.forgerock.json.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
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
-
-