org.intermine.sql.precompute
Class BestQueryExplainer

java.lang.Object
  extended by org.intermine.sql.precompute.BestQuery
      extended by org.intermine.sql.precompute.BestQueryExplainer
Direct Known Subclasses:
BestQueryExplainerVerbose

public class BestQueryExplainer
extends BestQuery

Gets the database to explain each Query added and keeps hold of the best one so far.


Nested Class Summary
protected  class BestQueryExplainer.Candidate
          A class representing a candidate optimised query.
 
Field Summary
protected static int ALWAYS_EXPLAIN_TABLES
           
protected  BestQueryExplainer.Candidate bestCandidate
           
protected  java.util.List<BestQueryExplainer.Candidate> candidates
           
protected  int candidateTables
           
protected  java.sql.Connection con
           
protected static int NEVER_EXPLAIN_TABLES
           
protected  java.util.Date start
           
protected  long timeLimit
           
 
Constructor Summary
BestQueryExplainer()
          Constructs an empty BestQueryExplainer for testing purposes
BestQueryExplainer(java.sql.Connection con, long timeLimit)
          Constructs a BestQueryExplainer that will use the given Connection to explain Queries.
 
Method Summary
protected  void add(BestQueryExplainer.Candidate c)
          Allows a Candidate to be added to this tracker.
 void add(Query q)
          Allows a Query to be added to this tracker.
 void add(java.lang.String q)
          Allows a Query to be added to this tracker.
protected  void didNotExplain(BestQueryExplainer.Candidate c)
          Internal method that records that a query was not explained.
protected  BestQueryExplainer.Candidate getBest()
          Gets the best Candidate found so far.
 ExplainResult getBestExplainResult()
          Gets the ExpainResult for the best Query found so far.
 Query getBestQuery()
          Gets the best Query found so far
 java.lang.String getBestQueryString()
          Gets the best query String found so far.
protected  ExplainResult getExplainResult(Query q)
          Internal method that creates an ExplainResult.
protected  ExplainResult getExplainResult(java.lang.String q)
          Internal method that creates an ExplainResult.
 void throwBestQueryException(java.lang.String message)
          Throws an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALWAYS_EXPLAIN_TABLES

protected static final int ALWAYS_EXPLAIN_TABLES
See Also:
Constant Field Values

NEVER_EXPLAIN_TABLES

protected static final int NEVER_EXPLAIN_TABLES
See Also:
Constant Field Values

candidates

protected java.util.List<BestQueryExplainer.Candidate> candidates

candidateTables

protected int candidateTables

bestCandidate

protected BestQueryExplainer.Candidate bestCandidate

con

protected java.sql.Connection con

start

protected java.util.Date start

timeLimit

protected long timeLimit
Constructor Detail

BestQueryExplainer

public BestQueryExplainer()
Constructs an empty BestQueryExplainer for testing purposes


BestQueryExplainer

public BestQueryExplainer(java.sql.Connection con,
                          long timeLimit)
Constructs a BestQueryExplainer that will use the given Connection to explain Queries.

Parameters:
con - the Connection to use
timeLimit - a time limit in milliseconds
Method Detail

add

public void add(Query q)
         throws BestQueryException,
                java.sql.SQLException
Allows a Query to be added to this tracker.

Specified by:
add in class BestQuery
Parameters:
q - a Query to be added to the tracker
Throws:
BestQueryException - if the current best Query is the best we think we are going to get
java.sql.SQLException - if error occurs in the underlying database

add

public void add(java.lang.String q)
         throws BestQueryException,
                java.sql.SQLException
Allows a Query to be added to this tracker.

Specified by:
add in class BestQuery
Parameters:
q - a query String to be added to the tracker
Throws:
BestQueryException - if the current best Query is the best we think we are going to get
java.sql.SQLException - if error occurs in the underlying database

add

protected void add(BestQueryExplainer.Candidate c)
            throws BestQueryException,
                   java.sql.SQLException
Allows a Candidate to be added to this tracker.

Parameters:
c - the Candidate
Throws:
BestQueryException - if the current best Candidate is the best we think we are going to get
java.sql.SQLException - if an error occurs in the underlying database

getExplainResult

protected ExplainResult getExplainResult(Query q)
                                  throws java.sql.SQLException
Internal method that creates an ExplainResult. It can be overridden by subclasses.

Parameters:
q - the Query
Returns:
an ExplainResult
Throws:
java.sql.SQLException - if an error occurs in the underlying database

getExplainResult

protected ExplainResult getExplainResult(java.lang.String q)
                                  throws java.sql.SQLException
Internal method that creates an ExplainResult. It can be overridden by subclasses.

Parameters:
q - the query String
Returns:
an ExplainResult
Throws:
java.sql.SQLException - if an error occurs in the underlying database

didNotExplain

protected void didNotExplain(BestQueryExplainer.Candidate c)
Internal method that records that a query was not explained. It can be overridden by subclasses.

Parameters:
c - the Candidate

getBestQuery

public Query getBestQuery()
                   throws java.sql.SQLException
Gets the best Query found so far

Specified by:
getBestQuery in class BestQuery
Returns:
the best Query, or null if no Queries added to this object
Throws:
java.sql.SQLException - if an error occurs in the underlying database

getBestQueryString

public java.lang.String getBestQueryString()
                                    throws java.sql.SQLException
Gets the best query String found so far.

Specified by:
getBestQueryString in class BestQuery
Returns:
the best Query, or null if no Queries added to this object
Throws:
java.sql.SQLException - if an error occurs in the underlying database

getBestExplainResult

public ExplainResult getBestExplainResult()
                                   throws java.sql.SQLException
Gets the ExpainResult for the best Query found so far.

Returns:
the best ExplainResult, or null if no Queries added to this object
Throws:
java.sql.SQLException - if an error occurs in the underlying database

getBest

protected BestQueryExplainer.Candidate getBest()
                                        throws java.sql.SQLException
Gets the best Candidate found so far.

Returns:
the best Candidate
Throws:
java.sql.SQLException - if an error occurs in the underlying database

throwBestQueryException

public void throwBestQueryException(java.lang.String message)
                             throws BestQueryException
Throws an exception. This gives the subclasses a chance to intercept it.

Parameters:
message - a message
Throws:
BestQueryException - with the message