Class AbstractSelectQuery

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.AbstractSelectQuery
All Implemented Interfaces:
Query, SelectQuery
Direct Known Subclasses:
CountQuery, SqlFileSelectQuery, SqlSelectQuery

public abstract class AbstractSelectQuery extends AbstractQuery implements SelectQuery
The base abstract class for all select query implementations.

This class provides common functionality for queries that select data from a database.

  • Field Details

    • parameters

      protected final Map<String,Value> parameters
      The parameters for the query.
    • options

      protected SelectOptions options
      The select options.
    • resultEnsured

      protected boolean resultEnsured
      Whether the query is expected to return at least one result.
    • resultMappingEnsured

      protected boolean resultMappingEnsured
      Whether the result mapping is ensured.
    • fetchType

      protected FetchType fetchType
      The fetch type for this query.
    • fetchSize

      protected int fetchSize
      The fetch size for this query.
    • maxRows

      protected int maxRows
      The maximum number of rows to be returned.
    • entityType

      protected EntityType<?> entityType
      The entity type for this query.
    • sql

      protected PreparedSql sql
      The prepared SQL for this query.
    • sqlLogType

      protected SqlLogType sqlLogType
      The SQL log type for this query.
    • resultStream

      protected boolean resultStream
      Whether the result should be processed as a stream.
    • aggregateStrategyType

      protected AggregateStrategyType aggregateStrategyType
      The aggregate strategy type for this query.
  • Constructor Details

    • AbstractSelectQuery

      protected AbstractSelectQuery()
      Creates a new instance.
  • Method Details

    • prepare

      public void prepare()
      Prepares this query for execution. This method must be called before the query is executed.

      This implementation prepares options and SQL.

      Specified by:
      prepare in interface Query
      Overrides:
      prepare in class AbstractQuery
    • prepareOptions

      protected void prepareOptions()
      Prepares the options for this query.

      This method sets default values for fetch size, max rows, and query timeout if they are not already set.

    • prepareSql

      protected abstract void prepareSql()
      Prepares the SQL for this query.

      This method must be implemented by subclasses to build the SQL statement.

    • buildSql

      Deprecated, for removal: This API element is subject to removal in a future version.
      This method is scheduled for removal in a future version
      Builds the SQL for this query using the provided SQL builder.
      Parameters:
      sqlBuilder - the function to build the SQL
    • createExpressionEvaluator

      protected ExpressionEvaluator createExpressionEvaluator()
      Creates an expression evaluator for evaluating SQL expressions.
      Returns:
      the expression evaluator
    • expandColumns

      protected List<String> expandColumns(ExpandNode node)
      Expands the columns for the entity type.
      Parameters:
      node - the expand node
      Returns:
      the list of expanded column names
      Throws:
      JdbcException - if the entity type is null
    • expandAggregateColumns

      protected List<String> expandAggregateColumns(ExpandNode node, String aliasCsv)
      Expands the columns for the aggregate strategy type with the specified aliases.
      Parameters:
      node - the expand node
      aliasCsv - the comma-separated list of aliases
      Returns:
      the list of expanded column names with aliases
      Throws:
      JdbcException - if the entity type is null
      DomaException - if an alias is not defined in the aggregate strategy type
    • populateValues

      protected void populateValues(PopulateNode node, SqlContext context)
      Populates values for the specified node in the SQL context.
      Parameters:
      node - the populate node
      context - the SQL context
      Throws:
      UnsupportedOperationException - always thrown as this method is not supported in this class
    • executeCount

      protected void executeCount(SqlNode sqlNode)
      Executes a count query using the specified SQL node. The result is set to the select options.
      Parameters:
      sqlNode - the SQL node for the count query
    • getOptions

      public SelectOptions getOptions()
      Returns the options for this select query.
      Specified by:
      getOptions in interface SelectQuery
      Returns:
      the select options
    • setOptions

      public void setOptions(SelectOptions options)
      Sets the select options.
      Parameters:
      options - the select options
    • addParameter

      public void addParameter(String name, Class<?> type, Object value)
      Adds a parameter to this query.
      Parameters:
      name - the parameter name
      type - the parameter type
      value - the parameter value
    • addParameters

      public void addParameters(Map<String,Value> parameters)
      Adds multiple parameters to this query.
      Parameters:
      parameters - the parameters to add
    • clearParameters

      public void clearParameters()
      Clears all parameters from this query.
    • isResultEnsured

      public boolean isResultEnsured()
      Returns whether the query is expected to return at least one result.
      Specified by:
      isResultEnsured in interface SelectQuery
      Returns:
      true if the query is expected to return at least one result
    • setResultEnsured

      public void setResultEnsured(boolean resultEnsured)
      Sets whether the query is expected to return at least one result.
      Parameters:
      resultEnsured - true if the query is expected to return at least one result
    • isResultMappingEnsured

      public boolean isResultMappingEnsured()
      Returns whether the result mapping is ensured.
      Specified by:
      isResultMappingEnsured in interface SelectQuery
      Returns:
      true if the result mapping is ensured
    • setResultMappingEnsured

      public void setResultMappingEnsured(boolean resultMappingEnsured)
      Sets whether the result mapping is ensured.
      Parameters:
      resultMappingEnsured - true if the result mapping is ensured
    • getFetchType

      public FetchType getFetchType()
      Returns the fetch type for this query.
      Specified by:
      getFetchType in interface SelectQuery
      Returns:
      the fetch type
    • setFetchType

      public void setFetchType(FetchType fetchType)
      Sets the fetch type for this query.
      Parameters:
      fetchType - the fetch type
    • getFetchSize

      public int getFetchSize()
      Returns the fetch size for this query.
      Specified by:
      getFetchSize in interface SelectQuery
      Returns:
      the fetch size
    • setFetchSize

      public void setFetchSize(int fetchSize)
      Sets the fetch size for this query.
      Parameters:
      fetchSize - the fetch size
    • getMaxRows

      public int getMaxRows()
      Returns the maximum number of rows to be returned.
      Specified by:
      getMaxRows in interface SelectQuery
      Returns:
      the maximum number of rows
    • setMaxRows

      public void setMaxRows(int maxRows)
      Sets the maximum number of rows to be returned.
      Parameters:
      maxRows - the maximum number of rows
    • getSqlLogType

      public SqlLogType getSqlLogType()
      Returns the SQL log type for this query.
      Specified by:
      getSqlLogType in interface SelectQuery
      Returns:
      the SQL log type
    • setSqlLogType

      public void setSqlLogType(SqlLogType sqlLogType)
      Sets the SQL log type for this query.
      Parameters:
      sqlLogType - the SQL log type
    • isResultStream

      public boolean isResultStream()
      Returns whether the result should be processed as a stream.
      Specified by:
      isResultStream in interface SelectQuery
      Returns:
      true if the result should be processed as a stream
    • setResultStream

      public void setResultStream(boolean resultStream)
      Sets whether the result should be processed as a stream.
      Parameters:
      resultStream - true if the result should be processed as a stream
    • setAggregateStrategyType

      public void setAggregateStrategyType(AggregateStrategyType aggregateStrategyType)
      Sets the aggregate strategy type for this query.
      Parameters:
      aggregateStrategyType - the aggregate strategy type
    • setEntityType

      public void setEntityType(EntityType<?> entityType)
      Sets the entity type for this query.
      Parameters:
      entityType - the entity type
    • getSql

      public PreparedSql getSql()
      Returns the prepared SQL for this select query.
      Specified by:
      getSql in interface Query
      Specified by:
      getSql in interface SelectQuery
      Returns:
      the prepared SQL
    • toString

      public String toString()
      Returns a string representation of this query.
      Overrides:
      toString in class Object
      Returns:
      the string representation of the SQL, or null if the SQL is not prepared