Package org.apache.torque.sql

## Class Query

- java.lang.Object
- - org.apache.torque.sql.Query

-     public class Query
      extends Object

  Contains the various parts of a SQL statement (select, update or delete). Attributes exist for the sections of these statements: modifiers, columns, from clause, where clause, and order by clause. Most parts of the query are appended to buffers which only accept unique entries.
  Version:
    $Id: Query.java 1867515 2019-09-25 15:02:03Z gk $ TODO rename to SqlStatement
  Author:
    John D. McNally, Sam Joseph, Martin Poeschl, Thomas Fischer

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Query.Type` | All types of the statement.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Query()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `String` | `getDisplayString()` | Returns a String to display this query.
    `Integer` | `getFetchSize()` | Returns the JDBC statement fetch size to use for queries.
    `String` | `getForUpdate()` | Returns the FOR UPDATE clause which should be added to the query.
    `UniqueList<FromElement>` | `getFromClause()` | Retrieve the from buffer in order to specify which tables are involved in this query.
    `UniqueList<String>` | `getGroupByClause()` | Retrieve the group by columns buffer in order to specify which columns are used to group the results of the query.
    `String` | `getHaving()` | Get the having clause.
    `String` | `getLimit()` | Get the limit number.
    `String` | `getOffset()` | Get the offset number.
    `UniqueList<String>` | `getOrderByClause()` | Retrieve the order by columns buffer in order to specify which columns are used to sort the results of the query.
    `String` | `getPartOperator()` | Returns the operator connecting the query parts.
    `List<Query>` | `getParts()` | Returns the parts of this query.
    `String` | `getPostLimit()` | Get the Post limit String.
    `String` | `getPreLimit()` | Get the Pre limit String.
    `List<Object>` | `getPreparedStatementReplacements()` | Returns all preparedStatementReplacements in the query.
    `String` | `getRowcount()` | Get the rowcount number.
    `UniqueList<String>` | `getSelectClause()` | Retrieve the columns buffer in order to specify which columns are returned in this query.
    `UniqueList<String>` | `getSelectModifiers()` | Retrieve the modifier buffer in order to add modifiers to this query.
    `Query.Type` | `getType()` | Returns the type of this SQL statement.
    `ColumnValues` | `getUpdateValues()` | Retrieve the values to update to in case of an update statement.
    `UniqueList<String>` | `getWhereClause()` | Retrieve the where buffer in order to specify the selection criteria E.g. column_a=?.
    `List<Object>` | `getWhereClausePreparedStatementReplacements()` | Retrieves the replacements which are inserted into prepared statement placeholders in the where clause.
    `boolean` | `hasLimit()` | True if this query has a limit clause registered.
    `void` | `setFetchSize​(Integer fetchSize)` | Sets the JDBC statement fetch size to use for queries.
    `void` | `setForUpdate​(String forUpdate)` | Sets the FOR UPDATE clause which should be added to the query.
    `void` | `setHaving​(String having)` | Set the having clause.
    `void` | `setLimit​(String limit)` | Set the limit number.
    `void` | `setOffset​(String offset)` | Set the offset number.
    `void` | `setPartOperator​(String partOperator)` | Sets the operator connecting the query parts.
    `void` | `setPostLimit​(String postLimit)` | Set the Post limit String.
    `void` | `setPreLimit​(String preLimit)` | Get the Pre limit String.
    `void` | `setRowcount​(String rowcount)` | Set the rowcount number.
    `void` | `setType​(Query.Type type)` | Sets the type of this SQL statement.
    `String` | `toString()` | Outputs the query statement.
    `StringBuilder` | `toStringBuilder​(StringBuilder stringBuilder)` | Appends the query to a string builder.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Query

          public Query()

  - ### Method Detail

    - #### getSelectModifiers

          public UniqueList<String> getSelectModifiers()

      Retrieve the modifier buffer in order to add modifiers to this query. E.g. DISTINCT and ALL.
      Returns:
        An UniqueList used to add modifiers.

    - #### getSelectClause

          public UniqueList<String> getSelectClause()

      Retrieve the columns buffer in order to specify which columns are returned in this query.
      Returns:
        An UniqueList used to add columns to be selected.

    - #### getUpdateValues

          public ColumnValues getUpdateValues()

      Retrieve the values to update to in case of an update statement.
      Returns:
        A modifiable ColumnValues object containing the current update values.

    - #### getFromClause

          public UniqueList<FromElement> getFromClause()

      Retrieve the from buffer in order to specify which tables are involved in this query.
      Returns:
        An UniqueList used to add tables involved in the query.

    - #### getWhereClause

          public UniqueList<String> getWhereClause()

      Retrieve the where buffer in order to specify the selection criteria E.g. column_a=?. Expressions added to the buffer will be separated using AND.
      Returns:
        An UniqueList used to add selection criteria.

    - #### getWhereClausePreparedStatementReplacements

          public List<Object> getWhereClausePreparedStatementReplacements()

      Retrieves the replacements which are inserted into prepared statement placeholders in the where clause. The number and order of the elements in the list must correspond to the order of the placeholders in the where clause string.
      Returns:
        A List containing all the replacements for the prepared statement placeholders, not null.

    - #### getPreparedStatementReplacements

          public List<Object> getPreparedStatementReplacements()

      Returns all preparedStatementReplacements in the query.
      Returns:
        an unmodifiable list of all preparedStatementReplacements.

    - #### getOrderByClause

          public UniqueList<String> getOrderByClause()

      Retrieve the order by columns buffer in order to specify which columns are used to sort the results of the query.
      Returns:
        An UniqueList used to add columns to sort on.

    - #### getGroupByClause

          public UniqueList<String> getGroupByClause()

      Retrieve the group by columns buffer in order to specify which columns are used to group the results of the query.
      Returns:
        An UniqueList used to add columns to group on.

    - #### getHaving

          public String getHaving()

      Get the having clause. This is used to restrict which rows are returned based on some condition.
      Returns:
        A String that is the having clause.

    - #### setHaving

          public void setHaving​(String having)

      Set the having clause. This is used to restrict which rows are returned.
      Parameters:
        `having` - A String.

    - #### getLimit

          public String getLimit()

      Get the limit number. This is used to limit the number of returned by a query in Postgres.
      Returns:
        A String with the limit.

    - #### setLimit

          public void setLimit​(String limit)

      Set the limit number. This is used to limit the number of rows returned by a query.
      Parameters:
        `limit` - A String.

    - #### getPreLimit

          public String getPreLimit()

      Get the Pre limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.
      Returns:
        A String with the preLimit.

    - #### setPreLimit

          public void setPreLimit​(String preLimit)

      Get the Pre limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.
      Parameters:
        `preLimit` - A String with the preLimit.

    - #### getPostLimit

          public String getPostLimit()

      Get the Post limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.
      Returns:
        A String with the preLimit.

    - #### setPostLimit

          public void setPostLimit​(String postLimit)

      Set the Post limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.
      Parameters:
        `postLimit` - A String with the postLimit.

    - #### getOffset

          public String getOffset()

      Get the offset number. This is used to set the row where the resultset starts.
      Returns:
        A String with the offset, or null if no offset is set.

    - #### setOffset

          public void setOffset​(String offset)

      Set the offset number. This is used to set the row where the resultset starts.
      Parameters:
        `offset` - A String.

    - #### getRowcount

          public String getRowcount()

      Get the rowcount number. This is used to limit the number of returned by a query in Sybase and MS SQL/Server.
      Returns:
        A String with the row count.

    - #### setRowcount

          public void setRowcount​(String rowcount)

      Set the rowcount number. This is used to limit the number of rows returned by Sybase and MS SQL/Server.
      Parameters:
        `rowcount` - A String.

    - #### setForUpdate

          public void setForUpdate​(String forUpdate)

      Sets the FOR UPDATE clause which should be added to the query.
      Parameters:
        `forUpdate` - the FOR UPDATE clause which should be added, null if no FOR UPDATE clause should be used.

    - #### getForUpdate

          public String getForUpdate()

      Returns the FOR UPDATE clause which should be added to the query.
      Returns:
        the FOR UPDATE clause, or null if none should be added.

    - #### hasLimit

          public boolean hasLimit()

      True if this query has a limit clause registered.
      Returns:
        true if a limit clause exists.

    - #### getType

          public Query.Type getType()

      Returns the type of this SQL statement.
      Returns:
        type the new type, not null.

    - #### setType

          public void setType​(Query.Type type)

      Sets the type of this SQL statement.
      Parameters:
        `type` - the new type, not null.
      Throws:
        `NullPointerException` - if `type` is null.

    - #### getFetchSize

          public Integer getFetchSize()

      Returns the JDBC statement fetch size to use for queries.
      Returns:
        the fetch size, or null if none is set.

    - #### setFetchSize

          public void setFetchSize​(Integer fetchSize)

      Sets the JDBC statement fetch size to use for queries.
      Parameters:
        `fetchSize` - the fetch size, or null for not set.

    - #### getParts

          public List<Query> getParts()

      Returns the parts of this query.
      Returns:
        a modifiable list containing the parts of this query, not null.

    - #### getPartOperator

          public String getPartOperator()

      Returns the operator connecting the query parts.
      Returns:
        the operator connecting the parts, or null.

    - #### setPartOperator

          public void setPartOperator​(String partOperator)

      Sets the operator connecting the query parts.
      Parameters:
        `partOperator` - the operator connecting the parts, or null.

    - #### toString

          public String toString()

      Outputs the query statement.
      Overrides:
        `toString` in class `Object`
      Returns:
        A String with the query statement.

    - #### toStringBuilder

          public StringBuilder toStringBuilder​(StringBuilder stringBuilder)

      Appends the query to a string builder.
      Parameters:
        `stringBuilder` - the stringBuilder to append to, not null.
      Returns:
        the modified passed in string builder.

    - #### getDisplayString

          public String getDisplayString()
                                  throws TorqueException

      Returns a String to display this query.
      Returns:
        the SQL query for display.
      Throws:
        `TorqueException` - Trouble creating the query string.