org.apache.cayenne.access.trans

## Class SelectTranslator

- java.lang.Object
- - org.apache.cayenne.access.trans.QueryAssembler
  - - org.apache.cayenne.access.trans.SelectTranslator

- Direct Known Subclasses:
    IngresSelectTranslator, SQLServerSelectTranslator

      public class SelectTranslator
      extends QueryAssembler

  A builder of JDBC PreparedStatements based on Cayenne SelectQueries. Translates SelectQuery to parameterized SQL string and wraps it in a PreparedStatement. SelectTranslator is stateful and thread-unsafe.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static int[]` | `UNSUPPORTED_DISTINCT_TYPES`

    - ### Fields inherited from class org.apache.cayenne.access.trans.QueryAssembler

      `adapter, attributes, connection, entityResolver, logger, parameterIndex, query, queryMetadata, values`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SelectTranslator()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `appendLimitAndOffsetClauses(StringBuilder buffer)` Handles appending optional limit and offset clauses.
    `protected void` | `appendSelectColumns(StringBuilder buffer, List<String> selectColumnExpList)`
    `protected List<ColumnDescriptor>` | `buildResultColumns()`
    `protected JoinStack` | `createJoinStack()`
    `String` | `createSqlString()` Returns query translated to SQL.
    `void` | `dbRelationshipAdded(DbRelationship relationship, JoinType joinType, String joinSplitAlias)` Appends a join with given semantics to the query.
    `Map<ObjAttribute,ColumnDescriptor>` | `getAttributeOverrides()` Returns a map of ColumnDescriptors keyed by ObjAttribute for columns that may need to be reprocessed manually due to incompatible mappings along the inheritance hierarchy.
    `String` | `getCurrentAlias()` Returns an alias of the table which is currently at the top of the join stack.
    `JoinStack` | `getJoinStack()`
    `ColumnDescriptor[]` | `getResultColumns()` Returns a list of ColumnDescriptors for the query columns.
    `boolean` | `isSuppressingDistinct()` Returns true if SelectTranslator determined that a query requiring DISTINCT can't be run with DISTINCT keyword for internal reasons.
    `protected static boolean` | `isUnsupportedForDistinct(int type)`
    `void` | `resetJoinStack()` A callback invoked by a child qualifier or ordering processor allowing query assembler to reset its join stack.
    `boolean` | `supportsTableAliases()` Always returns true.

    - ### Methods inherited from class org.apache.cayenne.access.trans.QueryAssembler

      `addToParamList, createStatement, getAdapter, getEntityResolver, getJdbcEventLogger, getPathAliases, getQuery, getQueryMetadata, getRootDbEntity, getRootEntity, initStatement, setAdapter, setConnection, setEntityResolver, setJdbcEventLogger, setQuery`

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

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

- - ### Field Detail

    - #### UNSUPPORTED_DISTINCT_TYPES

          protected static final int[] UNSUPPORTED_DISTINCT_TYPES

  - ### Constructor Detail

    - #### SelectTranslator

          public SelectTranslator()

  - ### Method Detail

    - #### isUnsupportedForDistinct

          protected static boolean isUnsupportedForDistinct(int type)

    - #### getJoinStack

          public JoinStack getJoinStack()

    - #### createJoinStack

          protected JoinStack createJoinStack()

    - #### createSqlString

          public String createSqlString()
                                 throws Exception

      Returns query translated to SQL. This is a main work method of the SelectTranslator.
      Specified by:
        `createSqlString` in class `QueryAssembler`
      Throws:
        `Exception`

    - #### appendSelectColumns

          protected void appendSelectColumns(StringBuilder buffer,
                                             List<String> selectColumnExpList)

      Since:
        3.1

    - #### appendLimitAndOffsetClauses

          protected void appendLimitAndOffsetClauses(StringBuilder buffer)

      Handles appending optional limit and offset clauses. This implementation does nothing, deferring to subclasses to define the LIMIT/OFFSET clause syntax.
      Since:
        3.0

    - #### getCurrentAlias

          public String getCurrentAlias()

      Description copied from class: `QueryAssembler`
      Returns an alias of the table which is currently at the top of the join stack.
      Specified by:
        `getCurrentAlias` in class `QueryAssembler`

    - #### getResultColumns

          public ColumnDescriptor[] getResultColumns()

      Returns a list of ColumnDescriptors for the query columns.
      Since:
        1.2

    - #### getAttributeOverrides

          public Map<ObjAttribute,ColumnDescriptor> getAttributeOverrides()

      Returns a map of ColumnDescriptors keyed by ObjAttribute for columns that may need to be reprocessed manually due to incompatible mappings along the inheritance hierarchy.
      Since:
        1.2

    - #### isSuppressingDistinct

          public boolean isSuppressingDistinct()

      Returns true if SelectTranslator determined that a query requiring DISTINCT can't be run with DISTINCT keyword for internal reasons. If this method returns true, DataNode may need to do in-memory distinct filtering.
      Since:
        1.1

    - #### buildResultColumns

          protected List<ColumnDescriptor> buildResultColumns()

    - #### resetJoinStack

          public void resetJoinStack()

      Description copied from class: `QueryAssembler`
      A callback invoked by a child qualifier or ordering processor allowing query assembler to reset its join stack.
      Specified by:
        `resetJoinStack` in class `QueryAssembler`
      Since:
        3.0

    - #### dbRelationshipAdded

          public void dbRelationshipAdded(DbRelationship relationship,
                                          JoinType joinType,
                                          String joinSplitAlias)

      Description copied from class: `QueryAssembler`
      Appends a join with given semantics to the query.
      Specified by:
        `dbRelationshipAdded` in class `QueryAssembler`
      Since:
        3.0

    - #### supportsTableAliases

          public boolean supportsTableAliases()

      Always returns true.
      Overrides:
        `supportsTableAliases` in class `QueryAssembler`

Copyright © 2001–2018 Apache Cayenne. All rights reserved.