Class Select


  • public class Select
    extends java.lang.Object
    Representation of a select statement built by SelectAdapter.build()
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Select()
      Default constructor.
      protected Select​(boolean distinct)
      Protected constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addColumn​(java.lang.String source, java.lang.String name)
      Add a single column to the select list
      void addColumn​(java.lang.String source, java.lang.String name, Alias alias)
      Add a single column to the select list, providing an alias for the column
      void addColumn​(java.lang.String columnValue, Alias alias)
      Add a value column to the select list, for example: addColumn("5", alias("RESOURCE_TYPE_ID")) can be used for: SELECT foo, 5 AS RESOURCE_TYPE_ID FROM ...
      void addColumns​(java.lang.String... columns)
      Add the list of simple columns
      void addFrom​(Select sub, Alias alias)
      Add a sub-select statement with an alias to the from-clause
      void addHavingPredicate​(java.lang.String predicate)
      Add a predicate to the HAVING clause for this statement
      void addInnerJoin​(java.lang.String tableName, Alias alias, ExpNode joinOnPredicate)
      Add an inner join to the from clause for this select statement.
      void addInnerJoin​(Select sub, Alias alias, ExpNode joinOnPredicate)
      Add an inner join to the from clause for this select statement where the joining row source is a sub-query
      void addLeftOuterJoin​(java.lang.String tableName, Alias alias, ExpNode joinOnPredicate)
      Add a left outer join to the from clause for this select statement.
      void addPagination​(int offset, int rowsPerPage)
      Add a pagination clause (offset/limit) to the query.
      void addTable​(java.lang.String tableName)
      Add a table item to the from-clause
      void addTable​(java.lang.String schemaName, java.lang.String tableName)
      Add a table item to the from-clause
      void addTable​(java.lang.String schemaName, java.lang.String tableName, Alias alias)
      Add a schema-qualified table item with an alias to the from clause
      void addTable​(java.lang.String tableName, Alias alias)
      Add a table item with an alias to the from-clause
      void addWithClause​(Select selectClause, Alias alias)
      Add a new WITH clause to the select statement for example WITH alias AS (SELECT ...) SELECT ...
      OrderByClause getOrderByClause()  
      WhereClause getWhereClause()
      Getter for the whereClause
      <T> T render​(StatementRenderer<T> renderer)
      Render the components of the statement
      static SelectAdapter select​(boolean distinct, java.lang.String... columns)
      Factory to start building a SELECT DISTINCT statement
      static SelectAdapter select​(java.lang.String... columns)
      Factory to create a new instance of the builder needed to create this statement
      void setGroupByClause​(GroupByClause gb)
      Set the group-by-clause for this statement
      void setOrderByClause​(OrderByClause ob)  
      void setUnion​(Select union)
      Set a select to UNION with this query.
      void setUnionAll​(Select unionAll)
      Set a select to UNION ALL with this query.
      void setWhereClause​(WhereClause wc)
      Set the where-clause for this statement
      java.lang.String toDebugString()
      A string representation of the query with the bind variables substituted in place which is handy for debugging - but not to be used for actual execution.
      java.lang.String toString()  
      <T> T visit​(ExpNodeVisitor<T> visitor)
      Visit the components of this query
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Select

        protected Select()
        Default constructor. Not a DISTINCT select.
      • Select

        protected Select​(boolean distinct)
        Protected constructor
        Parameters:
        distinct - if true, query will be SELECT DISTINCT ...
    • Method Detail

      • select

        public static SelectAdapter select​(java.lang.String... columns)
        Factory to create a new instance of the builder needed to create this statement
        Parameters:
        columns -
        Returns:
      • select

        public static SelectAdapter select​(boolean distinct,
                                           java.lang.String... columns)
        Factory to start building a SELECT DISTINCT statement
        Parameters:
        distinct -
        columns -
        Returns:
      • addColumns

        public void addColumns​(java.lang.String... columns)
        Add the list of simple columns
        Parameters:
        columns -
      • addWithClause

        public void addWithClause​(Select selectClause,
                                  Alias alias)
        Add a new WITH clause to the select statement for example WITH alias AS (SELECT ...) SELECT ... FROM abc JOIN alias ON ...
        Parameters:
        selectClause -
        alias -
      • addColumn

        public void addColumn​(java.lang.String source,
                              java.lang.String name)
        Add a single column to the select list
        Parameters:
        source -
        name -
      • addColumn

        public void addColumn​(java.lang.String source,
                              java.lang.String name,
                              Alias alias)
        Add a single column to the select list, providing an alias for the column
        Parameters:
        source -
        name -
        alias -
      • addColumn

        public void addColumn​(java.lang.String columnValue,
                              Alias alias)
        Add a value column to the select list, for example: addColumn("5", alias("RESOURCE_TYPE_ID")) can be used for: SELECT foo, 5 AS RESOURCE_TYPE_ID FROM ...
        Parameters:
        columnValue -
        alias -
      • addTable

        public void addTable​(java.lang.String schemaName,
                             java.lang.String tableName)
        Add a table item to the from-clause
        Parameters:
        schemaName -
        tableName -
      • addTable

        public void addTable​(java.lang.String tableName,
                             Alias alias)
        Add a table item with an alias to the from-clause
        Parameters:
        tableName -
        alias -
      • addTable

        public void addTable​(java.lang.String tableName)
        Add a table item to the from-clause
        Parameters:
        tableName -
      • addTable

        public void addTable​(java.lang.String schemaName,
                             java.lang.String tableName,
                             Alias alias)
        Add a schema-qualified table item with an alias to the from clause
        Parameters:
        schemaName -
        tableName -
        alias -
      • addFrom

        public void addFrom​(Select sub,
                            Alias alias)
        Add a sub-select statement with an alias to the from-clause
        Parameters:
        sub -
        alias -
      • setWhereClause

        public void setWhereClause​(WhereClause wc)
        Set the where-clause for this statement
        Parameters:
        wc -
      • setGroupByClause

        public void setGroupByClause​(GroupByClause gb)
        Set the group-by-clause for this statement
        Parameters:
        gb -
      • addHavingPredicate

        public void addHavingPredicate​(java.lang.String predicate)
        Add a predicate to the HAVING clause for this statement
        Parameters:
        predicate -
      • toString

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

        public java.lang.String toDebugString()
        A string representation of the query with the bind variables substituted in place which is handy for debugging - but not to be used for actual execution.
        Returns:
        the query string
      • render

        public <T> T render​(StatementRenderer<T> renderer)
        Render the components of the statement
        Type Parameters:
        T -
        Parameters:
        renderer -
        Returns:
      • addInnerJoin

        public void addInnerJoin​(java.lang.String tableName,
                                 Alias alias,
                                 ExpNode joinOnPredicate)
        Add an inner join to the from clause for this select statement.
        Parameters:
        tableName -
        alias -
        joinOnPredicate -
      • addInnerJoin

        public void addInnerJoin​(Select sub,
                                 Alias alias,
                                 ExpNode joinOnPredicate)
        Add an inner join to the from clause for this select statement where the joining row source is a sub-query
        Parameters:
        sub -
        alias -
        joinOnPredicate -
      • addLeftOuterJoin

        public void addLeftOuterJoin​(java.lang.String tableName,
                                     Alias alias,
                                     ExpNode joinOnPredicate)
        Add a left outer join to the from clause for this select statement.
        Parameters:
        tableName -
        alias -
        joinOnPredicate -
      • setOrderByClause

        public void setOrderByClause​(OrderByClause ob)
        Parameters:
        ob -
      • getWhereClause

        public WhereClause getWhereClause()
        Getter for the whereClause
        Returns:
        the whereClause value, which can be null if not yet set
      • visit

        public <T> T visit​(ExpNodeVisitor<T> visitor)
        Visit the components of this query
        Type Parameters:
        T -
        Parameters:
        visitor -
        Returns:
      • addPagination

        public void addPagination​(int offset,
                                  int rowsPerPage)
        Add a pagination clause (offset/limit) to the query.
        Parameters:
        offset -
        rowsPerPage -
      • getOrderByClause

        public OrderByClause getOrderByClause()
        Returns:
        the ORDER BY clause object for this select statement. Can be null.
      • setUnion

        public void setUnion​(Select union)
        Set a select to UNION with this query.
      • setUnionAll

        public void setUnionAll​(Select unionAll)
        Set a select to UNION ALL with this query.