Class 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.
    Author:
    Andrew Varley
    • 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