Class RecordService


  • public class RecordService
    extends Object
    File-based 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

      Constructors 
      Constructor Description
      RecordService​(File directory)
      Creates a RecordService 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 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, JsonValue newContent)
      Update the Record identified by id (possibly at a given revision) with the provided content.
    • Constructor Detail

      • RecordService

        public RecordService​(File directory)
                      throws IOException
        Creates a RecordService that will record resources in the given directory.
        Parameters:
        directory - storage directory
        Throws:
        IOException - when the given directory 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 a Record that represents the new resource.
        Parameters:
        content - content to be stored (cannot be null)
        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 a Record with the given id, returns null 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 a Record identified by id (possibly at a given revision), returns null if not found.
        Parameters:
        id - record to delete identifier
        revision - expected revision (can be set to null if revision has to be ignored)
        Returns:
        the found record or null if not found
        Throws:
        IOException - if deleted record loading from file has failed
        org.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 the 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.
        Parameters:
        id - record to update
        revision - expected revision (can be set to null if revision has to be ignored)
        newContent - new content (cannot be null)
        Returns:
        the updated record or null is resource is not found
        Throws:
        IOException - if updated record deletion or re-creation failed
        org.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