java.lang.Object
org.seasar.doma.jdbc.command.BatchModifyCommand<BatchInsertQuery>
org.seasar.doma.jdbc.command.BatchInsertCommand
- All Implemented Interfaces:
Command<int[]>
A command to execute a batch insert.
This command executes SQL INSERT statements in batch mode and generates IDs for entities if necessary.
-
Field Summary
Fields inherited from class org.seasar.doma.jdbc.command.BatchModifyCommand
query -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int[]executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls) Executes the batch insert and generates IDs if necessary.protected intexecuteUpdate(PreparedStatement preparedStatement, PreparedSql sql) Executes a single update operation.protected voidpostExecuteBatch(PreparedStatement preparedStatement, int position, int size) Generates IDs for the batch of entities after execution.Methods inherited from class org.seasar.doma.jdbc.command.BatchModifyCommand
bindParameters, execute, executeBatch, executeBatch, getQuery, log, prepareStatement, setupOptions, validateRows
-
Constructor Details
-
BatchInsertCommand
Creates a new instance.- Parameters:
query- the batch insert query
-
-
Method Details
-
executeInternal
protected int[] executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls) throws SQLException Executes the batch insert and generates IDs if necessary.If batch operation is supported, it uses the batch execution mode. Otherwise, it executes each SQL statement individually.
- Specified by:
executeInternalin classBatchModifyCommand<BatchInsertQuery>- Parameters:
preparedStatement- the prepared statementsqls- the SQL statements- Returns:
- the array of inserted rows count
- Throws:
SQLException- if a database access error occurs
-
executeUpdate
protected int executeUpdate(PreparedStatement preparedStatement, PreparedSql sql) throws SQLException Executes a single update operation.- Parameters:
preparedStatement- the prepared statementsql- the SQL statement- Returns:
- the number of affected rows
- Throws:
SQLException- if a database access error occursBatchUniqueConstraintException- if a unique constraint violation occurs
-
postExecuteBatch
Generates IDs for the batch of entities after execution.- Overrides:
postExecuteBatchin classBatchModifyCommand<BatchInsertQuery>- Parameters:
preparedStatement- the prepared statementposition- the position of the first element in the batchsize- the size of the executed batch
-