- All Implemented Interfaces:
BatchModifyQuery,Query
- Direct Known Subclasses:
SqlBatchDeleteQuery,SqlBatchInsertQuery,SqlBatchUpdateQuery
This class provides common functionality for executing batch operations using SQL statements. It handles SQL node processing, parameter binding, and batch execution for INSERT, UPDATE, and DELETE operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe batch size for this query.protected final SqlKindThe SQL kind (INSERT, UPDATE, or DELETE).protected booleanWhether optimistic lock checking is required for this query.The parameters for the SQL statement, mapped by name.protected intThe size of the parameter lists.protected SqlLogTypeThe SQL log type for this query.protected SqlNodeThe SQL node representing the SQL statement.protected List<PreparedSql>The prepared SQL statements for the batch.Fields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSqlBatchModifyQuery(SqlKind kind) Constructs a new instance with the specified SQL kind. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParameter(String name, Class<?> type, List<?> values) Adds a parameter to this query.voidClears all parameters from this query.voidcomplete()Completes this query after execution.intReturns the batch size for this query.getSql()Returns a representative prepared SQL statement for this batch query.Returns the cause if SQL execution should be skipped.Returns the SQL log type for this batch query.getSqls()Returns the list of prepared SQL statements for this batch query.booleanReturns whether auto-generated keys are supported for this batch query.booleanReturns whether this batch query is executable.booleanReturns whether optimistic lock checking is required for this batch query.voidprepare()Prepares this query for execution.protected voidPrepares the query options.protected voidPrepares the SQL statements for the batch.voidsetBatchSize(int batchSize) Sets the batch size for this query.voidsetSqlLogType(SqlLogType sqlLogType) Sets the SQL log type for this query.voidsetSqlNode(SqlNode sqlNode) Sets the SQL node for this query.toString()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, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
kind
The SQL kind (INSERT, UPDATE, or DELETE). -
sqlNode
The SQL node representing the SQL statement. -
parameters
The parameters for the SQL statement, mapped by name. -
sqls
The prepared SQL statements for the batch. -
optimisticLockCheckRequired
protected boolean optimisticLockCheckRequiredWhether optimistic lock checking is required for this query. -
batchSize
protected int batchSizeThe batch size for this query. -
sqlLogType
The SQL log type for this query. -
parameterSize
protected int parameterSizeThe size of the parameter lists.
-
-
Constructor Details
-
SqlBatchModifyQuery
Constructs a new instance with the specified SQL kind.- Parameters:
kind- the SQL kind
-
-
Method Details
-
prepare
public void prepare()Prepares this query for execution. This method must be called before the query is executed.This implementation prepares the SQL statements for the batch operation by setting options and building SQL statements.
- Specified by:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
prepareOptions
protected void prepareOptions()Prepares the query options.This method sets the query timeout and batch size from the configuration if they're not already set.
-
prepareSql
protected void prepareSql()Prepares the SQL statements for the batch.This method creates a SQL statement for each set of parameter values in the batch.
-
complete
public void complete()Completes this query after execution. This method must be called after the query is executed.This implementation does nothing because no post-processing is required.
-
setSqlNode
Sets the SQL node for this query.- Parameters:
sqlNode- the SQL node
-
addParameter
Adds a parameter to this query.This method adds a named parameter with a list of values for batch processing.
- Parameters:
name- the parameter nametype- the parameter typevalues- the parameter values
-
clearParameters
public void clearParameters()Clears all parameters from this query. -
setBatchSize
public void setBatchSize(int batchSize) Sets the batch size for this query.- Parameters:
batchSize- the batch size
-
setSqlLogType
Sets the SQL log type for this query.- Parameters:
sqlLogType- the SQL log type
-
getSql
Returns a representative prepared SQL statement for this batch query.This method is typically used for logging purposes.
This implementation returns the first SQL statement in the batch.
- Specified by:
getSqlin interfaceBatchModifyQuery- Specified by:
getSqlin interfaceQuery- Returns:
- a representative prepared SQL statement
-
getSqls
Returns the list of prepared SQL statements for this batch query.This implementation returns all SQL statements in the batch.
- Specified by:
getSqlsin interfaceBatchModifyQuery- Returns:
- the list of prepared SQL statements
-
isOptimisticLockCheckRequired
public boolean isOptimisticLockCheckRequired()Returns whether optimistic lock checking is required for this batch query.This implementation returns whether optimistic lock checking is required for this query.
- Specified by:
isOptimisticLockCheckRequiredin interfaceBatchModifyQuery- Returns:
trueif optimistic lock checking is required
-
isExecutable
public boolean isExecutable()Returns whether this batch query is executable.This implementation always returns true because SQL batch queries are always executable.
- Specified by:
isExecutablein interfaceBatchModifyQuery- Returns:
trueif this batch query is executable
-
getSqlExecutionSkipCause
Returns the cause if SQL execution should be skipped.This implementation always returns null because SQL batch queries are always executable.
- Specified by:
getSqlExecutionSkipCausein interfaceBatchModifyQuery- Returns:
- the cause of SQL execution skip, or
nullif execution should not be skipped
-
isAutoGeneratedKeysSupported
public boolean isAutoGeneratedKeysSupported()Returns whether auto-generated keys are supported for this batch query.This implementation always returns false because SQL batch queries do not support auto-generated keys.
- Specified by:
isAutoGeneratedKeysSupportedin interfaceBatchModifyQuery- Returns:
trueif auto-generated keys are supported
-
getBatchSize
public int getBatchSize()Returns the batch size for this query.This implementation returns the batch size for this query.
- Specified by:
getBatchSizein interfaceBatchModifyQuery- Returns:
- the batch size
-
getSqlLogType
Returns the SQL log type for this batch query.This implementation returns the SQL log type for this query.
- Specified by:
getSqlLogTypein interfaceBatchModifyQuery- Returns:
- the SQL log type
-
toString
This implementation returns the string representation of the SQL statements.
-