Class DeleteReturningCommand<RESULT>

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

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

This command extends ModifyReturningCommand to provide specific functionality for executing DELETE operations that return data via a RETURNING clause. This is useful for retrieving values from rows before they are deleted, allowing access to data that would otherwise be lost after the deletion.

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

  • Constructor Details

    • DeleteReturningCommand

      public DeleteReturningCommand(DeleteQuery query, ResultSetHandler<RESULT> resultSetHandler, Supplier<RESULT> emptyResultSupplier)
      Creates an instance of the DeleteReturningCommand.
      Parameters:
      query - the delete 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 DELETE 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 DELETE commands that return the number of affected rows, this method returns data from the RETURNING clause, allowing access to values from the deleted rows.

      Specified by:
      executeInternal in class ModifyReturningCommand<DeleteQuery,RESULT>
      Parameters:
      preparedStatement - the prepared statement containing the SQL DELETE 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