Module org.seasar.doma.core
Package org.seasar.doma.jdbc.command
Class ModifyReturningCommand<QUERY extends ModifyQuery,RESULT>
java.lang.Object
org.seasar.doma.jdbc.command.ModifyReturningCommand<QUERY,RESULT>
- Type Parameters:
QUERY- the type of queryRESULT- 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 Summary
FieldsModifier and TypeFieldDescriptionThe supplier of empty result.protected final QUERYThe query to execute.protected final ResultSetHandler<RESULT>The handler for the result set.protected final PreparedSqlThe SQL to execute. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModifyReturningCommand(QUERY query, ResultSetHandler<RESULT> resultSetHandler, Supplier<RESULT> emptyResultSupplier) Creates an instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindParameters(PreparedStatement preparedStatement) Binds parameters to the prepared statement.execute()Executes the SQL statement and retrieves the result.protected abstract RESULTexecuteInternal(PreparedStatement preparedStatement) Executes the SQL statement and handles the result set.protected RESULTexecuteQuery(PreparedStatement preparedStatement) Executes the query and processes the result set.getQuery()Returns the query.handleResultSet(ResultSet resultSet) Handles the result set.protected voidlog()Logs the SQL statement.protected PreparedStatementprepareStatement(Connection connection) Prepares a statement.protected voidsetupOptions(PreparedStatement preparedStatement) Sets up options for the prepared statement.
-
Field Details
-
query
The query to execute. -
sql
The SQL to execute. -
resultSetHandler
The handler for the result set. -
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 executeresultSetHandler- the handler for the result setemptyResultSupplier- the supplier of empty result
-
-
Method Details
-
getQuery
Returns the query.- Specified by:
getQueryin interfaceCommand<QUERY extends ModifyQuery>- Returns:
- the query
-
execute
Executes the SQL statement and retrieves the result.- Specified by:
executein interfaceCommand<QUERY extends ModifyQuery>- Returns:
- the result
- Throws:
SqlExecutionException- if a database access error occurs
-
prepareStatement
Prepares a statement.- Parameters:
connection- the connection- Returns:
- the prepared statement
-
executeInternal
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
Sets up options for the prepared statement.- Parameters:
preparedStatement- the prepared statement- Throws:
SQLException- if a database access error occurs
-
bindParameters
Binds parameters to the prepared statement.- Parameters:
preparedStatement- the prepared statement- Throws:
SQLException- if a database access error occurs
-
executeQuery
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
Handles the result set.- Parameters:
resultSet- the result set- Returns:
- the supplier of result
- Throws:
SQLException- if a database access error occursOptimisticLockException- if no rows are affected and optimistic lock checking is enabled
-