Class DataTracker


  • public class DataTracker
    extends java.lang.Object
    Interface providing access to data tracking. This class is almost a generic map. However, it particularly maps from an Integer and a String to a String and a boolean, where entries are grouped by the Integer.
    Author:
    Matthew Wakeling
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Exception broken  
    • Constructor Summary

      Constructors 
      Constructor Description
      DataTracker​(Database db, int maxSize, int commitSize)
      Constructor for DataTracker.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the data tracker of all entries.
      void clearObj​(java.lang.Integer id)
      Clears the cache for a particular object, in preparation for writing all the data for that object.
      void close()
      Closes this DataTracker, releasing both connections to the database.
      boolean doWrite()
      Performs maintenance of the cache, writing stuff to the backing database.
      void flush()
      Flushes everything to the backing database.
      Source getSource​(java.lang.Integer id, java.lang.String field)
      Retrieve the Source for a specified field of an Object stored in the database.
      void prefetchIds​(java.util.Set<java.lang.Integer> ids)
      Prefetches data for a specified set of object ids.
      void setSource​(java.lang.Integer id, java.lang.String field, Source source)
      Set the Source for a field of an object in the database
      java.lang.String sourceToString​(Source source)
      Converts a Source to a source name.
      Source stringToSource​(java.lang.String name)
      Converts a string sourcename to a Source.
      Source stringToSource​(java.lang.String name, java.lang.String type)
      Converts a string sourcename to a Source if the type is known.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • broken

        protected java.lang.Exception broken
    • Constructor Detail

      • DataTracker

        public DataTracker​(Database db,
                           int maxSize,
                           int commitSize)
        Constructor for DataTracker.
        Parameters:
        db - a Database to back the tracker
        maxSize - maximum number of cache entries
        commitSize - number of entries to write to the database at a time
    • Method Detail

      • clear

        public void clear()
                   throws java.sql.SQLException
        Clears the data tracker of all entries. This method may only be called immediately after construction.
        Throws:
        java.sql.SQLException - sometimes
      • prefetchIds

        public void prefetchIds​(java.util.Set<java.lang.Integer> ids)
        Prefetches data for a specified set of object ids.
        Parameters:
        ids - a Set of Integers
      • getSource

        public Source getSource​(java.lang.Integer id,
                                java.lang.String field)
        Retrieve the Source for a specified field of an Object stored in the database.
        Parameters:
        id - the ID of the object
        field - the name of the field
        Returns:
        the Source
      • setSource

        public void setSource​(java.lang.Integer id,
                              java.lang.String field,
                              Source source)
        Set the Source for a field of an object in the database
        Parameters:
        id - the ID of the object
        field - the name of the field
        source - the Source of the field
      • clearObj

        public void clearObj​(java.lang.Integer id)
        Clears the cache for a particular object, in preparation for writing all the data for that object. This allows the data tracker to cache the writes that are about to happen. This method should only be called with Ids that this DataTracker has never seen before, otherwise it will get the data wrong.
        Parameters:
        id - the ID of the object
      • doWrite

        public boolean doWrite()
        Performs maintenance of the cache, writing stuff to the backing database.
        Returns:
        true if some action was performed
      • flush

        public void flush()
        Flushes everything to the backing database.
      • close

        public void close()
        Closes this DataTracker, releasing both connections to the database. No further operations can be performed on the tracker.
      • stringToSource

        public Source stringToSource​(java.lang.String name)
        Converts a string sourcename to a Source.
        Parameters:
        name - a string source name
        Returns:
        a Source
      • stringToSource

        public Source stringToSource​(java.lang.String name,
                                     java.lang.String type)
        Converts a string sourcename to a Source if the type is known.
        Parameters:
        name - a string source name
        type - the source type
        Returns:
        a Source
      • sourceToString

        public java.lang.String sourceToString​(Source source)
        Converts a Source to a source name.
        Parameters:
        source - a Source
        Returns:
        the name