Class OptimiserCache


  • public class OptimiserCache
    extends java.lang.Object
    A class that provides an implementation of a cache for String-based SQL query optimisation.
    Author:
    Matthew Wakeling
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.String,​java.util.Set<OptimiserCacheLine>> cacheLines
      A Map that holds a mapping from unoptimised query string (with LIMIT and OFFSET stripped off) to a Set of OptimiserCacheLine objects.
      static int EXPIRE_INTERVAL
      Number of events to happen before an expiration run.
      static int MAX_LINESETS
      Maximum number of cache linesets in the cache.
    • Constructor Summary

      Constructors 
      Constructor Description
      OptimiserCache()
      Constructor for this object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCacheLine​(java.lang.String original, java.lang.String optimised, int limit)
      Adds a new OptimiserCacheLine object to the cache.
      protected static void clear()
      used only for testing
      void flush()
      Removes all entries from the cache.
      static OptimiserCache getInstance​(Database db)
      Returns an OptimiserCache object relevant to the database given.
      java.lang.String lookup​(java.lang.String original, int limit)
      Attempts to find a match in the cache for an original query.
      • Methods inherited from class java.lang.Object

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

      • MAX_LINESETS

        public static final int MAX_LINESETS
        Maximum number of cache linesets in the cache.
        See Also:
        Constant Field Values
      • EXPIRE_INTERVAL

        public static final int EXPIRE_INTERVAL
        Number of events to happen before an expiration run.
        See Also:
        Constant Field Values
      • cacheLines

        protected java.util.Map<java.lang.String,​java.util.Set<OptimiserCacheLine>> cacheLines
        A Map that holds a mapping from unoptimised query string (with LIMIT and OFFSET stripped off) to a Set of OptimiserCacheLine objects.
    • Constructor Detail

      • OptimiserCache

        public OptimiserCache()
        Constructor for this object.
    • Method Detail

      • getInstance

        public static OptimiserCache getInstance​(Database db)
        Returns an OptimiserCache object relevant to the database given.
        Parameters:
        db - a Database object to find a cache for
        Returns:
        an OptimiserCache object
      • clear

        protected static void clear()
        used only for testing
      • flush

        public void flush()
        Removes all entries from the cache.
      • addCacheLine

        public void addCacheLine​(java.lang.String original,
                                 java.lang.String optimised,
                                 int limit)
        Adds a new OptimiserCacheLine object to the cache.
        Parameters:
        original - the original SQL string (stripped of LIMIT and OFFSET)
        optimised - the optimised SQL string (stripped of LIMIT and OFFSET)
        limit - the limit that was used during the optimisation
      • lookup

        public java.lang.String lookup​(java.lang.String original,
                                       int limit)
        Attempts to find a match in the cache for an original query.
        Parameters:
        original - the original SQL string (minus LIMIT and OFFSET)
        limit - the limit required
        Returns:
        a possible optimised SQL string (minus LIMIT and OFFSET)