Class VersionedObjectStore

  • All Implemented Interfaces:
    Serializable

    public class VersionedObjectStore
    extends Object
    implements Serializable
    This class allows you to version-control almost arbitrary objects. TODO: This class is in heavy need of a read/write lock TODO: Improve the JavaDoc of this class.
    Author:
    mhschroe
    See Also:
    Serialized Form
    • Constructor Detail

      • VersionedObjectStore

        public VersionedObjectStore()
    • Method Detail

      • toXML

        public String toXML()
      • size

        public int size()
      • save

        public void save​(File file)
                  throws IOException
        Calling this function causes the store to be saved to disk. Not making the save automatic allows you to make bulk-changes and only dump them to disk once finished. Do note that while the function itself is synchronized, at the moment nothing prevents others to change the underlying data fields during save. TODO: Fix this, so that saves are truly atomic. Do note that this function fails silently in case the output file is not writable. It will log an error, but do nothing beyond that
        Parameters:
        file - the file to save the data to. The data is dumped as GZIP-compressed XML.
        Throws:
        IOException - in case the save file can't be read.
      • getLatestVersion

        public VersionedObjectStore.Version getLatestVersion()
        This retrieves the actual last versioned object.
        Returns:
        the latest version, or null if no version exists
      • getAllVersionsSince

        public LinkedList<VersionedObjectStore.Version> getAllVersionsSince​(Long sinceVersionId)
        gets all the more recent version ids since the sinceVersionId
        Parameters:
        sinceVersionId - timestamp in milliseconds since the epoch
        Returns:
        all versions since the given timestamp
      • getAllVersions

        public SortedSet<VersionedObjectStore.Version> getAllVersions()
        Returns a new set of all versions, sorted by their ID in ascending order.
        Returns:
        a sorted set of versions in ascending order.
      • createNextVersion

        public VersionedObjectStore.Version createNextVersion()
        This method creates the next version and copies all key/value object entries from the previous one.
        Returns:
        a blank next version.
      • undoVersion

        public void undoVersion​(VersionedObjectStore.Version v)
        This function removes the given version from the internal storage, if it is the last version that is present.

        You should not expose this function to the outside. Ever!

        Parameters:
        v - the version to commit
      • createNextVersionAsEmpty

        public VersionedObjectStore.Version createNextVersionAsEmpty()
        Creates the next version with an empty key/value object mapping.
        Returns:
        a blank, next version
      • getValueMapFor

        public Map<String,​Object> getValueMapFor​(Long id)
        This returns an immutable map that wraps around the key/value object map associated with the given version.

        Use this method in favour of getObject(Long, String) to avoid the O(log(n)) cost of retrieving the given version if you access more than one stored object.

        Parameters:
        id - the numerical ID of the version to retrieve
        Returns:
        an immutable map of key/value object pairs
      • getUserNotificationFor

        public VersionsNotification getUserNotificationFor​(Long version)
        This method generates a notification to the user, depending on what type of version currently being edited:
        1. user is editing an unstable version (Warning)
        2. user is editing the last stable version which is not the last version (Warning)
        3. user is editing the last stable version which is the last version (Info)
        4. user is editing some stable version which is not the latest stable version (Warning)
        Parameters:
        version - the specific version for which to get the notification
        Returns:
        a notification about the suitability of the given version