Class ModifyReturningCommand<QUERY extends ModifyQuery,RESULT>

java.lang.Object
org.seasar.doma.jdbc.command.ModifyReturningCommand<QUERY,RESULT>
Type Parameters:
QUERY - the type of query
RESULT - the type of result
All Implemented Interfaces:
Command<RESULT>
Direct Known Subclasses:
DeleteReturningCommand, InsertReturningCommand, UpdateReturningCommand

public abstract class ModifyReturningCommand<QUERY extends ModifyQuery,RESULT> extends Object implements Command<RESULT>
An abstract command that executes a SQL statement with a RETURNING clause and retrieves a result set. This is the base class for commands that execute INSERT, UPDATE, or DELETE statements with RETURNING clauses.
  • Field Details

    • query

      protected final QUERY extends ModifyQuery query
      The query to execute.
    • sql

      protected final PreparedSql sql
      The SQL to execute.
    • resultSetHandler

      protected final ResultSetHandler<RESULT> resultSetHandler
      The handler for the result set.
    • emptyResultSupplier

      protected final Supplier<RESULT> emptyResultSupplier
      The supplier of empty result.
  • Constructor Details

    • ModifyReturningCommand

      protected ModifyReturningCommand(QUERY query, ResultSetHandler<RESULT> resultSetHandler, Supplier<RESULT> emptyResultSupplier)
      Creates an instance.
      Parameters:
      query - the query to execute
      resultSetHandler - the handler for the result set
      emptyResultSupplier - the supplier of empty result
  • Method Details

    • getQuery

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

      public RESULT execute()
      Executes the SQL statement and retrieves the result.
      Specified by:
      execute in interface Command<QUERY extends ModifyQuery>
      Returns:
      the result
      Throws:
      SqlExecutionException - if a database access error occurs
    • prepareStatement

      protected PreparedStatement prepareStatement(Connection connection)
      Prepares a statement.
      Parameters:
      connection - the connection
      Returns:
      the prepared statement
    • executeInternal

      protected abstract RESULT executeInternal(PreparedStatement preparedStatement) throws SQLException
      Executes the SQL statement and handles the result set.
      Parameters:
      preparedStatement - the prepared statement
      Returns:
      the result
      Throws:
      SQLException - if a database access error occurs
    • log

      protected void log()
      Logs the SQL statement.
    • 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
    • bindParameters

      protected void bindParameters(PreparedStatement preparedStatement) throws SQLException
      Binds parameters to the prepared statement.
      Parameters:
      preparedStatement - the prepared statement
      Throws:
      SQLException - if a database access error occurs
    • executeQuery

      protected RESULT executeQuery(PreparedStatement preparedStatement) throws SQLException
      Executes the query and processes the result set.
      Parameters:
      preparedStatement - the prepared statement
      Returns:
      the result
      Throws:
      SQLException - if a database access error occurs
    • handleResultSet

      protected Supplier<RESULT> handleResultSet(ResultSet resultSet) throws SQLException
      Handles the result set.
      Parameters:
      resultSet - the result set
      Returns:
      the supplier of result
      Throws:
      SQLException - if a database access error occurs
      OptimisticLockException - if no rows are affected and optimistic lock checking is enabled