Module org.seasar.doma.core
Package org.seasar.doma.jdbc.command
Class ModuleCommand<QUERY extends ModuleQuery,RESULT>
java.lang.Object
org.seasar.doma.jdbc.command.ModuleCommand<QUERY,RESULT>
- Type Parameters:
QUERY- the query typeRESULT- the result type
- All Implemented Interfaces:
Command<RESULT>
- Direct Known Subclasses:
FunctionCommand,ProcedureCommand
public abstract class ModuleCommand<QUERY extends ModuleQuery,RESULT>
extends Object
implements Command<RESULT>
An abstract command that executes database modules such as stored procedures and functions.
This class provides common functionality for executing database modules using JDBC's CallableStatement. It handles connection management, parameter binding, and execution of SQL
statements.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final QUERYThe query to execute.protected final CallableSqlThe SQL to be executed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbindParameters(CallableStatement callableStatement) Binds parameters to the callable statement.execute()Executes this command.protected abstract RESULTexecuteInternal(CallableStatement callableStatement) Executes the internal operation with the given callable statement.protected voidfetchParameters(CallableStatement callableStatement) Fetches output parameters from the callable statement after execution.getQuery()Returns the query.protected voidlog()Logs the SQL statement before execution.protected voidsetupOptions(CallableStatement preparedStatement) Sets up options for the callable statement.
-
Field Details
-
query
The query to execute. -
sql
The SQL to be executed.
-
-
Constructor Details
-
ModuleCommand
Creates a new instance.- Parameters:
query- the query to execute- Throws:
NullPointerException- if the query is null
-
-
Method Details
-
getQuery
Returns the query.- Specified by:
getQueryin interfaceCommand<QUERY extends ModuleQuery>- Returns:
- the query
-
execute
Executes this command.This method handles the lifecycle of JDBC resources, including obtaining a connection, creating a statement, binding parameters, executing the SQL, and closing resources.
- Specified by:
executein interfaceCommand<QUERY extends ModuleQuery>- Returns:
- the result of the execution
- Throws:
SqlExecutionException- if a database access error occurs
-
executeInternal
Executes the internal operation with the given callable statement.This method is called by
execute()after setting up the statement and binding parameters. Subclasses must implement this method to define the specific execution behavior.- Parameters:
callableStatement- the statement to execute- Returns:
- the result of the execution
- Throws:
SQLException- if a database access error occurs
-
setupOptions
Sets up options for the callable statement.This implementation sets the query timeout if specified.
- Parameters:
preparedStatement- the statement to set options on- Throws:
SQLException- if a database access error occurs
-
bindParameters
Binds parameters to the callable statement.- Parameters:
callableStatement- the statement to bind parameters to- Throws:
SQLException- if a database access error occurs
-
fetchParameters
Fetches output parameters from the callable statement after execution.- Parameters:
callableStatement- the statement to fetch parameters from- Throws:
SQLException- if a database access error occurs
-
log
protected void log()Logs the SQL statement before execution.
-