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 Details

  • Constructor Details

    • BatchModifyCommand

      protected BatchModifyCommand(QUERY query)
      Creates a new instance.
      Parameters:
      query - the batch modification query
      Throws:
      AssertionError - if the query is null
  • Method Details

    • getQuery

      public QUERY getQuery()
      Returns the query.
      Specified by:
      getQuery in interface Command<QUERY extends BatchModifyQuery>
      Returns:
      the query
    • execute

      public int[] execute()
      Executes the batch operation.
      Specified by:
      execute in interface Command<QUERY extends BatchModifyQuery>
      Returns:
      the array of affected rows count
    • prepareStatement

      protected PreparedStatement prepareStatement(Connection connection, PreparedSql sql)
      Prepares a statement for execution.
      Parameters:
      connection - the database connection
      sql - 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 statement
      sqls - the SQL statements
      Returns:
      the array of affected rows count
      Throws:
      SQLException - if a database access error occurs
    • setupOptions

      protected void setupOptions(PreparedStatement preparedStatement) throws SQLException
      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 statement
      sqls - 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 statement
      sql - the SQL statement
      Returns:
      the array of affected rows count
      Throws:
      SQLException - if a database access error occurs
      BatchUniqueConstraintException - if a unique constraint violation occurs
    • postExecuteBatch

      protected void postExecuteBatch(PreparedStatement preparedStatement, int position, int size)
      Invoked after the batch execution.
      Parameters:
      preparedStatement - the prepared statement
      position - the position of the first element in the batch
      size - the size of the executed batch
    • log

      protected void log(PreparedSql sql)
      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 statement
      sql - 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 statement
      sql - the SQL statement
      rows - the array of affected rows count
      Throws:
      SQLException - if a database access error occurs
      BatchOptimisticLockException - if optimistic lock constraint is violated