Class NoteMap

  • All Implemented Interfaces:
    java.lang.Iterable<Note>

    public class NoteMap
    extends java.lang.Object
    implements java.lang.Iterable<Note>
    Index of notes from a note branch. This class is not thread-safe, and relies on an ObjectReader that it borrows/shares with the caller. The reader can be used during any call, and is not released by this class. The caller should arrange for releasing the shared ObjectReader at the proper times.
    • Field Detail

      • reader

        private final ObjectReader reader
        Borrowed reader to access the repository.
    • Constructor Detail

    • Method Detail

      • newEmptyMap

        public static NoteMap newEmptyMap()
        Construct a new empty note map.
        Returns:
        an empty note map.
      • shortenRefName

        public static java.lang.String shortenRefName​(java.lang.String noteRefName)
        Shorten the note ref name by trimming off the Constants.R_NOTES prefix if it exists.
        Parameters:
        noteRefName - a String object.
        Returns:
        a more user friendly note name
      • newMap

        static NoteMap newMap​(InMemoryNoteBucket root,
                              ObjectReader reader)
        Construct a new note map from an existing note bucket.
        Parameters:
        root - the root bucket of this note map
        reader - reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.
        Returns:
        the note map built from the note bucket
      • iterator

        public java.util.Iterator<Note> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Note>
      • get

        public ObjectId get​(AnyObjectId id)
                     throws java.io.IOException
        Lookup a note for a specific ObjectId.
        Parameters:
        id - the object to look for.
        Returns:
        the note's blob ObjectId, or null if no note exists.
        Throws:
        java.io.IOException - a portion of the note space is not accessible.
      • getNote

        public Note getNote​(AnyObjectId id)
                     throws java.io.IOException
        Lookup a note for a specific ObjectId.
        Parameters:
        id - the object to look for.
        Returns:
        the note for the given object id, or null if no note exists.
        Throws:
        java.io.IOException - a portion of the note space is not accessible.
      • contains

        public boolean contains​(AnyObjectId id)
                         throws java.io.IOException
        Determine if a note exists for the specified ObjectId.
        Parameters:
        id - the object to look for.
        Returns:
        true if a note exists; false if there is no note.
        Throws:
        java.io.IOException - a portion of the note space is not accessible.
      • getCachedBytes

        public byte[] getCachedBytes​(AnyObjectId id,
                                     int sizeLimit)
                              throws LargeObjectException,
                                     MissingObjectException,
                                     java.io.IOException
        Open and return the content of an object's note. This method assumes the note is fairly small and can be accessed efficiently. Larger notes should be accessed by streaming:
         ObjectId dataId = thisMap.get(id);
         if (dataId != null)
                reader.open(dataId).openStream();
         
        Parameters:
        id - object to lookup the note of.
        sizeLimit - maximum number of bytes to return. If the note data size is larger than this limit, LargeObjectException will be thrown.
        Returns:
        if a note is defined for id, the note content. If no note is defined, null.
        Throws:
        LargeObjectException - the note data is larger than sizeLimit.
        MissingObjectException - the note's blob does not exist in the repository.
        java.io.IOException - the note's blob cannot be read from the repository
      • set

        public void set​(AnyObjectId noteOn,
                        ObjectId noteData)
                 throws java.io.IOException
        Attach (or remove) a note on an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed). This method only updates the map in memory. If the caller wants to attach a UTF-8 encoded string message to an object, set(AnyObjectId, String, ObjectInserter) is a convenient way to encode and update a note in one step.
        Parameters:
        noteOn - the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.
        noteData - data to associate with the note. This must be the ObjectId of a blob that already exists in the repository. If null the note will be deleted, if present.
        Throws:
        java.io.IOException - a portion of the note space is not accessible.
      • set

        public void set​(AnyObjectId noteOn,
                        java.lang.String noteData,
                        ObjectInserter ins)
                 throws java.io.IOException
        Attach a note to an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed).
        Parameters:
        noteOn - the object to attach the note to. This same ObjectId can later be used as an argument to get(AnyObjectId) or getCachedBytes(AnyObjectId, int) to read back the noteData.
        noteData - text to store in the note. The text will be UTF-8 encoded when stored in the repository. If null the note will be deleted, if the empty string a note with the empty string will be stored.
        ins - inserter to write the encoded noteData out as a blob. The caller must ensure the inserter is flushed before the updated note map is made available for reading.
        Throws:
        java.io.IOException - the note data could not be stored in the repository.
      • remove

        public void remove​(AnyObjectId noteOn)
                    throws java.io.IOException
        Remove a note from an object. If no note exists, no action is performed. This method only updates the map in memory.
        Parameters:
        noteOn - the object to remove the note from.
        Throws:
        java.io.IOException - a portion of the note space is not accessible.
      • writeTree

        public ObjectId writeTree​(ObjectInserter inserter)
                           throws java.io.IOException
        Write this note map as a tree.
        Parameters:
        inserter - inserter to use when writing trees to the object database. Caller is responsible for flushing the inserter before trying to read the objects, or exposing them through a reference.
        Returns:
        the top level tree.
        Throws:
        java.io.IOException - a tree could not be written.