Class InsertCommand

java.lang.Object
org.seasar.doma.jdbc.command.ModifyCommand<InsertQuery>
org.seasar.doma.jdbc.command.InsertCommand
All Implemented Interfaces:
Command<Integer>

public class InsertCommand extends ModifyCommand<InsertQuery>
A command that executes INSERT SQL statements.

This class extends ModifyCommand to provide specific functionality for executing INSERT operations in a database. It handles the execution of prepared statements for inserting data and tracks execution statistics.

The command returns the number of rows affected by the INSERT operation. It also handles the generation of auto-generated keys (such as identity columns) and assigns them back to the entity being inserted.

  • Constructor Details

    • InsertCommand

      public InsertCommand(InsertQuery query)
      Constructs a new InsertCommand with the specified query.
      Parameters:
      query - the insert query to execute, which contains the SQL statement and configuration
  • Method Details

    • executeInternal

      protected int executeInternal(PreparedStatement preparedStatement) throws SQLException
      Executes the INSERT statement and returns the number of affected rows.

      This method uses the statistic manager to track execution statistics for the SQL operation if statistics collection is enabled. It also handles the generation of auto-generated keys after the insert operation is completed.

      Specified by:
      executeInternal in class ModifyCommand<InsertQuery>
      Parameters:
      preparedStatement - the prepared statement to execute
      Returns:
      the number of rows affected by the INSERT operation
      Throws:
      SQLException - if a database access error occurs during execution