Package org.intermine.sql.precompute
Class OptimiserCache
- java.lang.Object
-
- org.intermine.sql.precompute.OptimiserCache
-
public class OptimiserCache extends java.lang.ObjectA 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>>cacheLinesA Map that holds a mapping from unoptimised query string (with LIMIT and OFFSET stripped off) to a Set of OptimiserCacheLine objects.static intEXPIRE_INTERVALNumber of events to happen before an expiration run.static intMAX_LINESETSMaximum 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 voidaddCacheLine(java.lang.String original, java.lang.String optimised, int limit)Adds a new OptimiserCacheLine object to the cache.protected static voidclear()used only for testingvoidflush()Removes all entries from the cache.static OptimiserCachegetInstance(Database db)Returns an OptimiserCache object relevant to the database given.java.lang.Stringlookup(java.lang.String original, int limit)Attempts to find a match in the cache for an original query.
-
-
-
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.
-
-
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)
-
-