Class SqlFileBatchModifyQuery<ELEMENT>

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.SqlFileBatchModifyQuery<ELEMENT>
Type Parameters:
ELEMENT - the type of elements in the batch
All Implemented Interfaces:
BatchModifyQuery, Query
Direct Known Subclasses:
SqlFileBatchDeleteQuery, SqlFileBatchInsertQuery, SqlFileBatchUpdateQuery

public abstract class SqlFileBatchModifyQuery<ELEMENT> extends AbstractQuery implements BatchModifyQuery
An abstract base class for SQL file-based batch modification queries.

This class provides common functionality for executing batch operations using SQL files. It handles SQL file loading, parameter binding, and batch execution for INSERT, UPDATE, and DELETE operations.

  • Field Details

    • EMPTY_STRINGS

      protected static final String[] EMPTY_STRINGS
      Empty string array used as default for property name arrays.
    • elementClass

      protected final Class<ELEMENT> elementClass
      The class of elements in the batch.
    • kind

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

      protected String sqlFilePath
      The path to the SQL file.
    • parameterName

      protected String parameterName
      The parameter name used in the SQL file.
    • sqlFile

      protected SqlFile sqlFile
      The SQL file.
    • optimisticLockCheckRequired

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

      protected boolean executable
      Whether this query is executable.
    • sqlExecutionSkipCause

      protected SqlExecutionSkipCause sqlExecutionSkipCause
      The cause for skipping SQL execution, if applicable.
    • batchSize

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

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

      protected String[] includedPropertyNames
      The property names to be included in the operation.
    • excludedPropertyNames

      protected String[] excludedPropertyNames
      The property names to be excluded from the operation.
    • elements

      protected List<ELEMENT> elements
      The elements to be processed in the batch.
    • currentEntity

      protected ELEMENT currentEntity
      The current element being processed.
    • sqls

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

    • SqlFileBatchModifyQuery

      protected SqlFileBatchModifyQuery(Class<ELEMENT> elementClass, SqlKind kind)
      Constructs a new instance with the specified element class and SQL kind.
      Parameters:
      elementClass - the class of elements in the batch
      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 validates that required components are not null.

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

      protected void prepareSqlFile()
      Prepares the SQL file for this query.

      This method loads the SQL file from the repository using the configured dialect.

    • 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 statement for the current entity.

      This method creates an expression evaluator and SQL builder to generate the SQL statement for the current entity, then adds it to the list of SQL statements for the batch.

    • expandColumns

      protected List<String> expandColumns(ExpandNode node)
      Expands columns in the SQL statement.

      This method is called when an expand node is encountered in the SQL file.

      Parameters:
      node - the expand node
      Returns:
      the expanded column list
      Throws:
      UnsupportedOperationException - if this operation is not supported by the implementing class
    • populateValues

      protected void populateValues(PopulateNode node, SqlContext context)
      Populates values in the SQL context.

      This method is called when a populate node is encountered in the SQL file.

      Parameters:
      node - the populate node
      context - the SQL context
      Throws:
      UnsupportedOperationException - if this operation is not supported by the implementing class
    • setSqlFilePath

      public void setSqlFilePath(String sqlFilePath)
      Sets the path to the SQL file.
      Parameters:
      sqlFilePath - the SQL file path
    • setParameterName

      public void setParameterName(String parameterName)
      Sets the parameter name used in the SQL file.
      Parameters:
      parameterName - the parameter name
    • setElements

      public void setElements(Iterable<ELEMENT> elements)
      Sets the elements to be processed in the batch.
      Parameters:
      elements - the elements
    • getEntities

      public List<ELEMENT> getEntities()
      Returns the elements to be processed in the batch.
      Returns:
      the elements
    • 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
    • setIncludedPropertyNames

      public void setIncludedPropertyNames(String... includedPropertyNames)
      Sets the property names to be included in the operation.
      Parameters:
      includedPropertyNames - the property names to be included
    • setExcludedPropertyNames

      public void setExcludedPropertyNames(String... excludedPropertyNames)
      Sets the property names to be excluded from the operation.
      Parameters:
      excludedPropertyNames - the property names to be excluded
    • setEntityType

      public abstract void setEntityType(EntityType<ELEMENT> entityType)
      Sets the entity type for this query.
      Parameters:
      entityType - the entity type
    • getSql

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

      This method is typically used for logging purposes.

      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.
      Specified by:
      getSqls in interface BatchModifyQuery
      Returns:
      the list of prepared SQL statements
    • getConfig

      public Config getConfig()
      Returns the configuration for this query.
      Specified by:
      getConfig in interface Query
      Overrides:
      getConfig in class AbstractQuery
      Returns:
      the configuration
    • isOptimisticLockCheckRequired

      public boolean isOptimisticLockCheckRequired()
      Returns whether optimistic lock checking is required for this batch query.
      Specified by:
      isOptimisticLockCheckRequired in interface BatchModifyQuery
      Returns:
      true if optimistic lock checking is required
    • isAutoGeneratedKeysSupported

      public boolean isAutoGeneratedKeysSupported()
      Returns whether auto-generated keys are supported for this batch query.
      Specified by:
      isAutoGeneratedKeysSupported in interface BatchModifyQuery
      Returns:
      true if auto-generated keys are supported
    • isExecutable

      public boolean isExecutable()
      Returns whether this batch query is 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.
      Specified by:
      getSqlExecutionSkipCause in interface BatchModifyQuery
      Returns:
      the cause of SQL execution skip, or null if execution should not be skipped
    • getBatchSize

      public int getBatchSize()
      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.
      Specified by:
      getSqlLogType in interface BatchModifyQuery
      Returns:
      the SQL log type
    • toString

      public String toString()
      Overrides:
      toString in class Object