Class PrecomputedTable

  • All Implemented Interfaces:
    java.lang.Comparable<PrecomputedTable>, SQLStringable

    public class PrecomputedTable
    extends java.lang.Object
    implements SQLStringable, java.lang.Comparable<PrecomputedTable>
    Represents a Precomputed table in a database. A precomputed table is a materialised SQL query. Note - the query encapsulated in this PrecomputedTable should not be altered.
    Author:
    Andrew Varley
    • Constructor Summary

      Constructors 
      Constructor Description
      PrecomputedTable​(Query q, java.lang.String originalSql, java.lang.String name, java.lang.String category, java.sql.Connection conn)
      Construct a new PrecomputedTable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(PrecomputedTable obj)
      Implements Comparable's method, so we can put PrecomputedTable objects into SortedMaps.
      boolean equals​(java.lang.Object obj)
      Overrides Object.equals().
      java.lang.String getCategory()
      Returns the category of this PrecomputedTable
      boolean getFirstOrderByHasNoNulls()
      Returns true if the first element of the ORDER BY clause is a column that contains no nulls.
      java.lang.String getName()
      Gets the name of this PrecomputedTable
      java.lang.String getOrderByField()
      Returns the name of the order by field, if it exists.
      java.lang.String getOriginalSql()
      Returns the original SQL text stored in the index for this PrecomputedTable
      Query getQuery()
      Gets the Query that is materialised in this PrecomputedTable
      java.lang.String getSQLString()
      Get a "CREATE TABLE" SQL statement for this PrecomputedTable.
      java.util.Map<AbstractValue,​SelectValue> getValueMap()
      Gets a Map from AbstractValue to SelectValue for the Query in this PrecomputedTable.
      int hashCode()
      Overrides Object.hashCode().
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ORDERBY_FIELD

        public static final java.lang.String ORDERBY_FIELD
        The name of the field that is generated as the order by field
        See Also:
        Constant Field Values
      • originalSql

        protected java.lang.String originalSql
      • name

        protected java.lang.String name
      • category

        protected java.lang.String category
      • orderByField

        protected java.lang.String orderByField
      • generationSqlString

        protected java.lang.String generationSqlString
      • firstOrderByHasNoNulls

        protected boolean firstOrderByHasNoNulls
    • Constructor Detail

      • PrecomputedTable

        public PrecomputedTable​(Query q,
                                java.lang.String originalSql,
                                java.lang.String name,
                                java.lang.String category,
                                java.sql.Connection conn)
        Construct a new PrecomputedTable
        Parameters:
        q - the Query that this PrecomputedTable materialises
        originalSql - the original SQL text that appears in the index table
        name - the name of this PrecomputedTable
        category - the type of PrecomputedTable this is. Note that a value of "template" denotes PrecomputedTables that are managed automatically by the webapp. Such tables are liable to be created and deleted at random
        conn - a Connection to use to work out if the order by fields are compatible with a unified orderby_field
    • Method Detail

      • getQuery

        public Query getQuery()
        Gets the Query that is materialised in this PrecomputedTable
        Returns:
        the Query that this PrecomputedTable materialises
      • getOriginalSql

        public java.lang.String getOriginalSql()
        Returns the original SQL text stored in the index for this PrecomputedTable
        Returns:
        an SQL String
      • getName

        public java.lang.String getName()
        Gets the name of this PrecomputedTable
        Returns:
        the name of the PrecomputedTable
      • getCategory

        public java.lang.String getCategory()
        Returns the category of this PrecomputedTable
        Returns:
        a String
      • getValueMap

        public java.util.Map<AbstractValue,​SelectValue> getValueMap()
        Gets a Map from AbstractValue to SelectValue for the Query in this PrecomputedTable.
        Returns:
        the valueMap
      • getSQLString

        public java.lang.String getSQLString()
        Get a "CREATE TABLE" SQL statement for this PrecomputedTable.
        Specified by:
        getSQLString in interface SQLStringable
        Returns:
        this PrecomputedTable as an SQL statement
      • getOrderByField

        public java.lang.String getOrderByField()
        Returns the name of the order by field, if it exists.
        Returns:
        orderByField
      • getFirstOrderByHasNoNulls

        public boolean getFirstOrderByHasNoNulls()
        Returns true if the first element of the ORDER BY clause is a column that contains no nulls.
        Returns:
        a boolean
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides Object.equals().
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - an Object to compare to
        Returns:
        true if the object is equal
      • hashCode

        public int hashCode()
        Overrides Object.hashCode().
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        an arbitrary integer based on the contents of the Query and the name
      • compareTo

        public int compareTo​(PrecomputedTable obj)
        Implements Comparable's method, so we can put PrecomputedTable objects into SortedMaps.
        Specified by:
        compareTo in interface java.lang.Comparable<PrecomputedTable>
        Parameters:
        obj - an Object to compare to
        Returns:
        an integer based on the comparison
        Throws:
        java.lang.ClassCastException - if obj is not a PrecomputedTable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object