Class InsertReturningCommand<RESULT>

java.lang.Object
org.seasar.doma.jdbc.command.ModifyReturningCommand<InsertQuery,RESULT>
org.seasar.doma.jdbc.command.InsertReturningCommand<RESULT>
Type Parameters:
RESULT - the type of result returned from the RETURNING clause
All Implemented Interfaces:
Command<RESULT>

public class InsertReturningCommand<RESULT> extends ModifyReturningCommand<InsertQuery,RESULT>
A command that executes an SQL INSERT statement and retrieves a result set generated from a RETURNING clause.

This command extends ModifyReturningCommand to provide specific functionality for executing INSERT operations that return data via a RETURNING clause. This is useful for retrieving auto-generated values (like primary keys) or other column values after an insert operation.

The RETURNING clause is a SQL feature supported by some database systems (like PostgreSQL, Oracle) that allows retrieving data from inserted rows as part of the same statement that performs the insertion, without requiring a separate SELECT statement.

  • Constructor Details

    • InsertReturningCommand

      public InsertReturningCommand(InsertQuery query, ResultSetHandler<RESULT> resultSetHandler, Supplier<RESULT> emptyResultSupplier)
      Creates an instance of the InsertReturningCommand.
      Parameters:
      query - the insert query to execute, containing the SQL statement with a RETURNING clause
      resultSetHandler - the handler for processing the result set returned by the RETURNING clause
      emptyResultSupplier - the supplier that provides an empty result when no rows are returned or when the RETURNING clause is not supported by the database
  • Method Details

    • executeInternal

      protected RESULT executeInternal(PreparedStatement preparedStatement) throws SQLException
      Executes the SQL INSERT statement with a RETURNING clause and processes the returned result set.

      This method uses the StatisticManager to track execution statistics and delegates to the executeQuery method to execute the prepared statement. Unlike regular INSERT commands that return the number of affected rows, this method returns data from the RETURNING clause, such as auto-generated primary keys or other column values.

      Specified by:
      executeInternal in class ModifyReturningCommand<InsertQuery,RESULT>
      Parameters:
      preparedStatement - the prepared statement containing the SQL INSERT with RETURNING clause
      Returns:
      the result processed from the result set returned by the RETURNING clause
      Throws:
      SQLException - if a database access error occurs during execution