Class SqlBatchModifyQuery

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.SqlBatchModifyQuery
All Implemented Interfaces:
BatchModifyQuery, Query
Direct Known Subclasses:
SqlBatchDeleteQuery, SqlBatchInsertQuery, SqlBatchUpdateQuery

public abstract class SqlBatchModifyQuery extends AbstractQuery implements BatchModifyQuery
An abstract base class for SQL-based batch modification queries.

This class provides common functionality for executing batch operations using SQL statements. It handles SQL node processing, parameter binding, and batch execution for INSERT, UPDATE, and DELETE operations.

  • Field Details

    • kind

      protected final SqlKind kind
      The SQL kind (INSERT, UPDATE, or DELETE).
    • sqlNode

      protected SqlNode sqlNode
      The SQL node representing the SQL statement.
    • parameters

      protected final Map<String,List<Value>> parameters
      The parameters for the SQL statement, mapped by name.
    • sqls

      protected List<PreparedSql> sqls
      The prepared SQL statements for the batch.
    • optimisticLockCheckRequired

      protected boolean optimisticLockCheckRequired
      Whether optimistic lock checking is required for this query.
    • batchSize

      protected int batchSize
      The batch size for this query.
    • sqlLogType

      protected SqlLogType sqlLogType
      The SQL log type for this query.
    • parameterSize

      protected int parameterSize
      The size of the parameter lists.
  • Constructor Details

    • SqlBatchModifyQuery

      protected SqlBatchModifyQuery(SqlKind kind)
      Constructs a new instance with the specified SQL kind.
      Parameters:
      kind - the SQL kind
  • Method Details

    • prepare

      public void prepare()
      Prepares this query for execution. This method must be called before the query is executed.

      This implementation prepares the SQL statements for the batch operation by setting options and building SQL statements.

      Specified by:
      prepare in interface Query
      Overrides:
      prepare in class AbstractQuery
    • prepareOptions

      protected void prepareOptions()
      Prepares the query options.

      This method sets the query timeout and batch size from the configuration if they're not already set.

    • prepareSql

      protected void prepareSql()
      Prepares the SQL statements for the batch.

      This method creates a SQL statement for each set of parameter values in the batch.

    • complete

      public void complete()
      Completes this query after execution. This method must be called after the query is executed.

      This implementation does nothing because no post-processing is required.

      Specified by:
      complete in interface Query
    • setSqlNode

      public void setSqlNode(SqlNode sqlNode)
      Sets the SQL node for this query.
      Parameters:
      sqlNode - the SQL node
    • addParameter

      public void addParameter(String name, Class<?> type, List<?> values)
      Adds a parameter to this query.

      This method adds a named parameter with a list of values for batch processing.

      Parameters:
      name - the parameter name
      type - the parameter type
      values - the parameter values
    • clearParameters

      public void clearParameters()
      Clears all parameters from this query.
    • setBatchSize

      public void setBatchSize(int batchSize)
      Sets the batch size for this query.
      Parameters:
      batchSize - the batch size
    • setSqlLogType

      public void setSqlLogType(SqlLogType sqlLogType)
      Sets the SQL log type for this query.
      Parameters:
      sqlLogType - the SQL log type
    • getSql

      public PreparedSql getSql()
      Returns a representative prepared SQL statement for this batch query.

      This method is typically used for logging purposes.

      This implementation returns the first SQL statement in the batch.

      Specified by:
      getSql in interface BatchModifyQuery
      Specified by:
      getSql in interface Query
      Returns:
      a representative prepared SQL statement
    • getSqls

      public List<PreparedSql> getSqls()
      Returns the list of prepared SQL statements for this batch query.

      This implementation returns all SQL statements in the batch.

      Specified by:
      getSqls in interface BatchModifyQuery
      Returns:
      the list of prepared SQL statements
    • isOptimisticLockCheckRequired

      public boolean isOptimisticLockCheckRequired()
      Returns whether optimistic lock checking is required for this batch query.

      This implementation returns whether optimistic lock checking is required for this query.

      Specified by:
      isOptimisticLockCheckRequired in interface BatchModifyQuery
      Returns:
      true if optimistic lock checking is required
    • isExecutable

      public boolean isExecutable()
      Returns whether this batch query is executable.

      This implementation always returns true because SQL batch queries are always executable.

      Specified by:
      isExecutable in interface BatchModifyQuery
      Returns:
      true if this batch query is executable
    • getSqlExecutionSkipCause

      public SqlExecutionSkipCause getSqlExecutionSkipCause()
      Returns the cause if SQL execution should be skipped.

      This implementation always returns null because SQL batch queries are always executable.

      Specified by:
      getSqlExecutionSkipCause in interface BatchModifyQuery
      Returns:
      the cause of SQL execution skip, or null if execution should not be skipped
    • isAutoGeneratedKeysSupported

      public boolean isAutoGeneratedKeysSupported()
      Returns whether auto-generated keys are supported for this batch query.

      This implementation always returns false because SQL batch queries do not support auto-generated keys.

      Specified by:
      isAutoGeneratedKeysSupported in interface BatchModifyQuery
      Returns:
      true if auto-generated keys are supported
    • getBatchSize

      public int getBatchSize()
      Returns the batch size for this query.

      This implementation returns the batch size for this query.

      Specified by:
      getBatchSize in interface BatchModifyQuery
      Returns:
      the batch size
    • getSqlLogType

      public SqlLogType getSqlLogType()
      Returns the SQL log type for this batch query.

      This implementation returns the SQL log type for this query.

      Specified by:
      getSqlLogType in interface BatchModifyQuery
      Returns:
      the SQL log type
    • toString

      public String toString()

      This implementation returns the string representation of the SQL statements.

      Overrides:
      toString in class Object