Class InsertReturningCommand<RESULT>
- Type Parameters:
RESULT- the type of result returned from the RETURNING clause
- All Implemented Interfaces:
Command<RESULT>
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.
-
Field Summary
Fields inherited from class org.seasar.doma.jdbc.command.ModifyReturningCommand
emptyResultSupplier, query, resultSetHandler, sql -
Constructor Summary
ConstructorsConstructorDescriptionInsertReturningCommand(InsertQuery query, ResultSetHandler<RESULT> resultSetHandler, Supplier<RESULT> emptyResultSupplier) Creates an instance of the InsertReturningCommand. -
Method Summary
Modifier and TypeMethodDescriptionprotected RESULTexecuteInternal(PreparedStatement preparedStatement) Executes the SQL INSERT statement with a RETURNING clause and processes the returned result set.Methods inherited from class org.seasar.doma.jdbc.command.ModifyReturningCommand
bindParameters, execute, executeQuery, getQuery, handleResultSet, log, prepareStatement, setupOptions
-
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 clauseresultSetHandler- the handler for processing the result set returned by the RETURNING clauseemptyResultSupplier- 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
Executes the SQL INSERT statement with a RETURNING clause and processes the returned result set.This method uses the
StatisticManagerto track execution statistics and delegates to theexecuteQuerymethod 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:
executeInternalin classModifyReturningCommand<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
-