Module org.seasar.doma.core
Package org.seasar.doma.jdbc.command
Class BatchModifyCommand<QUERY extends BatchModifyQuery>
java.lang.Object
org.seasar.doma.jdbc.command.BatchModifyCommand<QUERY>
- Type Parameters:
QUERY- the query type
- All Implemented Interfaces:
Command<int[]>
- Direct Known Subclasses:
BatchDeleteCommand,BatchInsertCommand,BatchUpdateCommand
public abstract class BatchModifyCommand<QUERY extends BatchModifyQuery>
extends Object
implements Command<int[]>
An abstract command for batch modification operations (insert, update, delete).
This class provides common functionality for executing SQL statements in batch mode.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindParameters(PreparedStatement preparedStatement, PreparedSql sql) Binds parameters to the prepared statement.int[]execute()Executes the batch operation.protected int[]executeBatch(PreparedStatement preparedStatement, List<PreparedSql> sqls) Executes the batch operation.protected int[]executeBatch(PreparedStatement preparedStatement, PreparedSql sql) Executes the batch operation.protected abstract int[]executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls) Executes the batch operation internally.getQuery()Returns the query.protected voidlog(PreparedSql sql) Logs the SQL statement.protected voidpostExecuteBatch(PreparedStatement preparedStatement, int position, int size) Invoked after the batch execution.protected PreparedStatementprepareStatement(Connection connection, PreparedSql sql) Prepares a statement for execution.protected voidsetupOptions(PreparedStatement preparedStatement) Sets up options for the prepared statement.protected voidvalidateRows(PreparedStatement preparedStatement, PreparedSql sql, int[] rows) Validates the affected rows count.
-
Field Details
-
query
The query to be executed.
-
-
Constructor Details
-
BatchModifyCommand
Creates a new instance.- Parameters:
query- the batch modification query- Throws:
AssertionError- if the query is null
-
-
Method Details
-
getQuery
Returns the query.- Specified by:
getQueryin interfaceCommand<QUERY extends BatchModifyQuery>- Returns:
- the query
-
execute
public int[] execute()Executes the batch operation.- Specified by:
executein interfaceCommand<QUERY extends BatchModifyQuery>- Returns:
- the array of affected rows count
-
prepareStatement
Prepares a statement for execution.- Parameters:
connection- the database connectionsql- the SQL to be prepared- Returns:
- the prepared statement
-
executeInternal
protected abstract int[] executeInternal(PreparedStatement preparedStatement, List<PreparedSql> sqls) throws SQLException Executes the batch operation internally.- Parameters:
preparedStatement- the prepared statementsqls- the SQL statements- Returns:
- the array of affected rows count
- Throws:
SQLException- if a database access error occurs
-
setupOptions
Sets up options for the prepared statement.- Parameters:
preparedStatement- the prepared statement- Throws:
SQLException- if a database access error occurs
-
executeBatch
protected int[] executeBatch(PreparedStatement preparedStatement, List<PreparedSql> sqls) throws SQLException Executes the batch operation.- Parameters:
preparedStatement- the prepared statementsqls- the SQL statements- Returns:
- the array of affected rows count
- Throws:
SQLException- if a database access error occurs
-
executeBatch
protected int[] executeBatch(PreparedStatement preparedStatement, PreparedSql sql) throws SQLException Executes the batch operation.- Parameters:
preparedStatement- the prepared statementsql- the SQL statement- Returns:
- the array of affected rows count
- Throws:
SQLException- if a database access error occursBatchUniqueConstraintException- if a unique constraint violation occurs
-
postExecuteBatch
Invoked after the batch execution.- Parameters:
preparedStatement- the prepared statementposition- the position of the first element in the batchsize- the size of the executed batch
-
log
Logs the SQL statement.- Parameters:
sql- the SQL statement
-
bindParameters
protected void bindParameters(PreparedStatement preparedStatement, PreparedSql sql) throws SQLException Binds parameters to the prepared statement.- Parameters:
preparedStatement- the prepared statementsql- the SQL statement with parameters- Throws:
SQLException- if a database access error occurs
-
validateRows
protected void validateRows(PreparedStatement preparedStatement, PreparedSql sql, int[] rows) throws SQLException Validates the affected rows count.- Parameters:
preparedStatement- the prepared statementsql- the SQL statementrows- the array of affected rows count- Throws:
SQLException- if a database access error occursBatchOptimisticLockException- if optimistic lock constraint is violated
-