Class BatchInsertCommand

All Implemented Interfaces:
Command<int[]>

public class BatchInsertCommand extends BatchModifyCommand<BatchInsertQuery>
A command to execute a batch insert.

This command executes SQL INSERT statements in batch mode and generates IDs for entities if necessary.

  • Constructor Details

    • BatchInsertCommand

      public BatchInsertCommand(BatchInsertQuery query)
      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:
      executeInternal in class BatchModifyCommand<BatchInsertQuery>
      Parameters:
      preparedStatement - the prepared statement
      sqls - 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 statement
      sql - the SQL statement
      Returns:
      the number of affected rows
      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)
      Generates IDs for the batch of entities after execution.
      Overrides:
      postExecuteBatch in class BatchModifyCommand<BatchInsertQuery>
      Parameters:
      preparedStatement - the prepared statement
      position - the position of the first element in the batch
      size - the size of the executed batch