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
The base abstract class for all select query implementations.
This class provides common functionality for queries that select data from a database.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AggregateStrategyTypeThe aggregate strategy type for this query.protected EntityType<?>The entity type for this query.protected intThe fetch size for this query.protected FetchTypeThe fetch type for this query.protected intThe maximum number of rows to be returned.protected SelectOptionsThe select options.The parameters for the query.protected booleanWhether the query is expected to return at least one result.protected booleanWhether the result mapping is ensured.protected booleanWhether the result should be processed as a stream.protected PreparedSqlThe prepared SQL for this query.protected SqlLogTypeThe SQL log type for this query.Fields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParameter(String name, Class<?> type, Object value) Adds a parameter to this query.voidaddParameters(Map<String, Value> parameters) Adds multiple parameters to this query.protected voidbuildSql(BiFunction<ExpressionEvaluator, Function<ExpandNode, List<String>>, PreparedSql> sqlBuilder) Deprecated, for removal: This API element is subject to removal in a future version.This method is scheduled for removal in a future versionvoidClears all parameters from this query.protected ExpressionEvaluatorCreates an expression evaluator for evaluating SQL expressions.protected voidexecuteCount(SqlNode sqlNode) Executes a count query using the specified SQL node.expandAggregateColumns(ExpandNode node, String aliasCsv) Expands the columns for the aggregate strategy type with the specified aliases.expandColumns(ExpandNode node) Expands the columns for the entity type.intReturns the fetch size for this query.Returns the fetch type for this query.intReturns the maximum number of rows to be returned.Returns the options for this select query.getSql()Returns the prepared SQL for this select query.Returns the SQL log type for this query.booleanReturns whether the query is expected to return at least one result.booleanReturns whether the result mapping is ensured.booleanReturns whether the result should be processed as a stream.protected voidpopulateValues(PopulateNode node, SqlContext context) Populates values for the specified node in the SQL context.voidprepare()Prepares this query for execution.protected voidPrepares the options for this query.protected abstract voidPrepares the SQL for this query.voidsetAggregateStrategyType(AggregateStrategyType aggregateStrategyType) Sets the aggregate strategy type for this query.voidsetEntityType(EntityType<?> entityType) Sets the entity type for this query.voidsetFetchSize(int fetchSize) Sets the fetch size for this query.voidsetFetchType(FetchType fetchType) Sets the fetch type for this query.voidsetMaxRows(int maxRows) Sets the maximum number of rows to be returned.voidsetOptions(SelectOptions options) Sets the select options.voidsetResultEnsured(boolean resultEnsured) Sets whether the query is expected to return at least one result.voidsetResultMappingEnsured(boolean resultMappingEnsured) Sets whether the result mapping is ensured.voidsetResultStream(boolean resultStream) Sets whether the result should be processed as a stream.voidsetSqlLogType(SqlLogType sqlLogType) Sets the SQL log type for this query.toString()Returns a string representation of this query.Methods inherited from class org.seasar.doma.jdbc.query.AbstractQuery
comment, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout, setCallerClassName, setCallerMethodName, setConfig, setMessage, setMethod, setQueryTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.seasar.doma.jdbc.query.Query
comment, complete, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
parameters
The parameters for the query. -
options
The select options. -
resultEnsured
protected boolean resultEnsuredWhether the query is expected to return at least one result. -
resultMappingEnsured
protected boolean resultMappingEnsuredWhether the result mapping is ensured. -
fetchType
The fetch type for this query. -
fetchSize
protected int fetchSizeThe fetch size for this query. -
maxRows
protected int maxRowsThe maximum number of rows to be returned. -
entityType
The entity type for this query. -
sql
The prepared SQL for this query. -
sqlLogType
The SQL log type for this query. -
resultStream
protected boolean resultStreamWhether the result should be processed as a stream. -
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:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
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(forRemoval=true) protected void buildSql(BiFunction<ExpressionEvaluator, Function<ExpandNode, List<String>>, PreparedSql> sqlBuilder) Deprecated, for removal: This API element is subject to removal in a future version.This method is scheduled for removal in a future versionBuilds the SQL for this query using the provided SQL builder.- Parameters:
sqlBuilder- the function to build the SQL
-
createExpressionEvaluator
Creates an expression evaluator for evaluating SQL expressions.- Returns:
- the expression evaluator
-
expandColumns
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
Expands the columns for the aggregate strategy type with the specified aliases.- Parameters:
node- the expand nodealiasCsv- the comma-separated list of aliases- Returns:
- the list of expanded column names with aliases
- Throws:
JdbcException- if the entity type is nullDomaException- if an alias is not defined in the aggregate strategy type
-
populateValues
Populates values for the specified node in the SQL context.- Parameters:
node- the populate nodecontext- the SQL context- Throws:
UnsupportedOperationException- always thrown as this method is not supported in this class
-
executeCount
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
Returns the options for this select query.- Specified by:
getOptionsin interfaceSelectQuery- Returns:
- the select options
-
setOptions
Sets the select options.- Parameters:
options- the select options
-
addParameter
Adds a parameter to this query.- Parameters:
name- the parameter nametype- the parameter typevalue- the parameter value
-
addParameters
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:
isResultEnsuredin interfaceSelectQuery- Returns:
trueif 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-trueif the query is expected to return at least one result
-
isResultMappingEnsured
public boolean isResultMappingEnsured()Returns whether the result mapping is ensured.- Specified by:
isResultMappingEnsuredin interfaceSelectQuery- Returns:
trueif the result mapping is ensured
-
setResultMappingEnsured
public void setResultMappingEnsured(boolean resultMappingEnsured) Sets whether the result mapping is ensured.- Parameters:
resultMappingEnsured-trueif the result mapping is ensured
-
getFetchType
Returns the fetch type for this query.- Specified by:
getFetchTypein interfaceSelectQuery- Returns:
- the fetch type
-
setFetchType
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:
getFetchSizein interfaceSelectQuery- 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:
getMaxRowsin interfaceSelectQuery- 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
Returns the SQL log type for this query.- Specified by:
getSqlLogTypein interfaceSelectQuery- Returns:
- the SQL log type
-
setSqlLogType
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:
isResultStreamin interfaceSelectQuery- Returns:
trueif 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-trueif the result should be processed as a stream
-
setAggregateStrategyType
Sets the aggregate strategy type for this query.- Parameters:
aggregateStrategyType- the aggregate strategy type
-
setEntityType
Sets the entity type for this query.- Parameters:
entityType- the entity type
-
getSql
Returns the prepared SQL for this select query.- Specified by:
getSqlin interfaceQuery- Specified by:
getSqlin interfaceSelectQuery- Returns:
- the prepared SQL
-
toString
Returns a string representation of this query.
-