Class ModuleCommand<QUERY extends ModuleQuery,RESULT>

java.lang.Object
org.seasar.doma.jdbc.command.ModuleCommand<QUERY,RESULT>
Type Parameters:
QUERY - the query type
RESULT - 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 Details

    • query

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

      protected final CallableSql sql
      The SQL to be executed.
  • Constructor Details

    • ModuleCommand

      protected ModuleCommand(QUERY query)
      Creates a new instance.
      Parameters:
      query - the query to execute
      Throws:
      NullPointerException - if the query is null
  • Method Details

    • getQuery

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

      public RESULT 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:
      execute in interface Command<QUERY extends ModuleQuery>
      Returns:
      the result of the execution
      Throws:
      SqlExecutionException - if a database access error occurs
    • executeInternal

      protected abstract RESULT executeInternal(CallableStatement callableStatement) throws SQLException
      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

      protected void setupOptions(CallableStatement preparedStatement) throws SQLException
      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

      protected void bindParameters(CallableStatement callableStatement) throws SQLException
      Binds parameters to the callable statement.
      Parameters:
      callableStatement - the statement to bind parameters to
      Throws:
      SQLException - if a database access error occurs
    • fetchParameters

      protected void fetchParameters(CallableStatement callableStatement) throws SQLException
      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.