Class AutoBatchModifyQuery<ENTITY>

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.AutoBatchModifyQuery<ENTITY>
Type Parameters:
ENTITY - the entity type
All Implemented Interfaces:
BatchModifyQuery, Query
Direct Known Subclasses:
AutoBatchDeleteQuery, AutoBatchInsertQuery, AutoBatchUpdateQuery

public abstract class AutoBatchModifyQuery<ENTITY> extends AbstractQuery implements BatchModifyQuery
An abstract base class for auto batch modification queries.

This class provides common functionality for batch operations that modify entities in the database, such as batch insert, update, and delete operations. It manages entity properties, optimistic locking, and SQL generation for batch operations.

  • Field Details

    • EMPTY_STRINGS

      protected static final String[] EMPTY_STRINGS
      Empty string array constant.
    • targetPropertyTypes

      protected List<EntityPropertyType<ENTITY,?>> targetPropertyTypes
      The property types targeted by this query.
    • idPropertyTypes

      protected List<EntityPropertyType<ENTITY,?>> idPropertyTypes
      The ID property types of the entity.
    • includedPropertyNames

      protected String[] includedPropertyNames
      The names of properties to be included in the query.
    • excludedPropertyNames

      protected String[] excludedPropertyNames
      The names of properties to be excluded from the query.
    • entityType

      protected final EntityType<ENTITY> entityType
      The entity type.
    • versionPropertyType

      protected VersionPropertyType<ENTITY,?,?> versionPropertyType
      The version property type for optimistic locking.
    • tenantIdPropertyType

      protected TenantIdPropertyType<ENTITY,?,?> tenantIdPropertyType
      The tenant ID property type for multi-tenancy.
    • optimisticLockCheckRequired

      protected boolean optimisticLockCheckRequired
      Whether optimistic lock checking is required.
    • autoGeneratedKeysSupported

      protected boolean autoGeneratedKeysSupported
      Whether auto-generated keys are supported.
    • executable

      protected boolean executable
      Whether this query is executable.
    • sqlExecutionSkipCause

      protected SqlExecutionSkipCause sqlExecutionSkipCause
      The cause of SQL execution skip if the query is not executable.
    • sqls

      protected List<PreparedSql> sqls
      The list of SQL statements to be executed in batch.
    • entities

      protected List<ENTITY> entities
      The list of entities to be processed.
    • currentEntity

      protected ENTITY currentEntity
      The current entity being processed.
    • batchSize

      protected int batchSize
      The batch size.
    • sqlLogType

      protected SqlLogType sqlLogType
      The SQL log type.
  • Constructor Details

    • AutoBatchModifyQuery

      public AutoBatchModifyQuery(EntityType<ENTITY> entityType)
  • Method Details

    • prepareIdAndVersionPropertyTypes

      protected void prepareIdAndVersionPropertyTypes()
      Prepares the ID, version, and tenant ID property types from the entity type.

      This method initializes the property types that are used for identifying entities and handling optimistic locking and multi-tenancy.

    • validateIdExistent

      protected void validateIdExistent()
      Validates that the entity has at least one ID property.

      This method throws a JdbcException if the entity doesn't have any ID properties, as batch operations require entities to be identifiable.

      Throws:
      JdbcException - if the entity doesn't have any ID properties
    • prepareOptions

      protected void prepareOptions()
      Prepares the query options.

      This method initializes the query timeout and batch size from the configuration if they haven't been explicitly set or if they have invalid values.

    • isTargetPropertyName

      protected boolean isTargetPropertyName(String name)
      Determines if a property should be included in the query based on its name.

      This method checks if the property name is in the included properties list and not in the excluded properties list. If no included properties are specified, all properties except those explicitly excluded are considered targets.

      Parameters:
      name - the property name to check
      Returns:
      true if the property should be included, false otherwise
    • setEntities

      public void setEntities(Iterable<ENTITY> entities)
      Sets the entities to be processed by this batch query.

      This method initializes the internal list of entities and prepares the SQL statements list with the same size as the entities list.

      Parameters:
      entities - the entities to be processed
      Throws:
      NullPointerException - if entities is null
    • getEntities

      public List<ENTITY> getEntities()
      Returns the list of entities to be processed by this batch query.
      Returns:
      the list of entities
    • setBatchSize

      public void setBatchSize(int batchSize)
      Sets the batch size for this query.

      The batch size determines how many entities are processed in a single batch operation.

      Parameters:
      batchSize - the batch size
    • setIncludedPropertyNames

      public void setIncludedPropertyNames(String... includedPropertyNames)
      Sets the names of properties to be included in the query.

      If this is set, only the specified properties will be included in the query, unless they are also in the excluded properties list.

      Parameters:
      includedPropertyNames - the names of properties to include
    • setExcludedPropertyNames

      public void setExcludedPropertyNames(String... excludedPropertyNames)
      Sets the names of properties to be excluded from the query.

      If this is set, the specified properties will be excluded from the query, even if they are in the included properties list.

      Parameters:
      excludedPropertyNames - the names of properties to exclude
    • setSqlLogType

      public void setSqlLogType(SqlLogType sqlLogType)
      Sets the SQL log type for this query.

      The SQL log type determines how SQL statements are logged.

      Parameters:
      sqlLogType - the SQL log type
    • getSql

      public PreparedSql getSql()
      Returns the first SQL statement in the batch.
      Specified by:
      getSql in interface BatchModifyQuery
      Specified by:
      getSql in interface Query
      Returns:
      the first SQL statement
    • getSqls

      public List<PreparedSql> getSqls()
      Returns all SQL statements in the batch.
      Specified by:
      getSqls in interface BatchModifyQuery
      Returns:
      the list of SQL statements
    • isOptimisticLockCheckRequired

      public boolean isOptimisticLockCheckRequired()
      Indicates whether optimistic lock checking is required.
      Specified by:
      isOptimisticLockCheckRequired in interface BatchModifyQuery
      Returns:
      true if optimistic lock checking is required, false otherwise
    • isAutoGeneratedKeysSupported

      public boolean isAutoGeneratedKeysSupported()
      Indicates whether auto-generated keys are supported.
      Specified by:
      isAutoGeneratedKeysSupported in interface BatchModifyQuery
      Returns:
      true if auto-generated keys are supported, false otherwise
    • isExecutable

      public boolean isExecutable()
      Indicates whether this query is executable.
      Specified by:
      isExecutable in interface BatchModifyQuery
      Returns:
      true if this query is executable, false otherwise
    • getSqlExecutionSkipCause

      public SqlExecutionSkipCause getSqlExecutionSkipCause()
      Returns the cause of SQL execution skip if the query is not executable.
      Specified by:
      getSqlExecutionSkipCause in interface BatchModifyQuery
      Returns:
      the cause of SQL execution skip, or null if the query is executable
    • 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 query.
      Specified by:
      getSqlLogType in interface BatchModifyQuery
      Returns:
      the SQL log type
    • toString

      public String toString()
      Returns a string representation of this query.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this query