Class AutoModifyQuery<ENTITY>

java.lang.Object
org.seasar.doma.jdbc.query.AbstractQuery
org.seasar.doma.jdbc.query.AutoModifyQuery<ENTITY>
Type Parameters:
ENTITY - the entity type
All Implemented Interfaces:
ModifyQuery, Query
Direct Known Subclasses:
AutoDeleteQuery, AutoInsertQuery, AutoMultiInsertQuery, AutoUpdateQuery

public abstract class AutoModifyQuery<ENTITY> extends AbstractQuery implements ModifyQuery
An abstract base class for queries that automatically modify entities in a database.

This class provides common functionality for entity-based modification operations such as INSERT, UPDATE, and DELETE. It handles:

  • Entity property filtering (inclusion/exclusion)
  • ID property management
  • Version property handling for optimistic locking
  • Tenant ID property handling for multi-tenancy
  • SQL generation and execution control

Subclasses implement specific modification operations by extending this class and providing operation-specific logic.

  • Field Details

    • EMPTY_STRINGS

      protected static final String[] EMPTY_STRINGS
      An empty string array used as default for property name filters.
    • includedPropertyNames

      protected String[] includedPropertyNames
      Names of properties to be included in the modification operation.
    • excludedPropertyNames

      protected String[] excludedPropertyNames
      Names of properties to be excluded from the modification operation.
    • entityType

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

      protected ENTITY entity
      The entity instance to be modified.
    • sql

      protected PreparedSql sql
      The prepared SQL for this query.
    • targetPropertyTypes

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

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

      protected VersionPropertyType<ENTITY,?,?> versionPropertyType
      The version property type for optimistic locking, if the entity has one.
    • tenantIdPropertyType

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

      protected boolean optimisticLockCheckRequired
      Indicates whether optimistic lock checking is required for this query.
    • autoGeneratedKeysSupported

      protected boolean autoGeneratedKeysSupported
      Indicates whether auto-generated keys are supported for this query.
    • executable

      protected boolean executable
      Indicates whether this query is executable.
    • sqlExecutionSkipCause

      protected SqlExecutionSkipCause sqlExecutionSkipCause
      The cause if SQL execution should be skipped.
    • sqlLogType

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

      protected ReturningProperties returning
      The properties to be returned from the modification operation.
  • Constructor Details

    • AutoModifyQuery

      protected AutoModifyQuery(EntityType<ENTITY> entityType)
      Constructs an instance.
      Parameters:
      entityType - the entity type metadata
  • Method Details

    • prepare

      public void prepare()
      Prepares this query for execution.

      This method performs basic preparation steps and validates that the dialect supports returning properties if they are specified.

      Subclasses should override this method to perform additional preparation steps, but must call super.prepare() first.

      Specified by:
      prepare in interface Query
      Overrides:
      prepare in class AbstractQuery
      Throws:
      JdbcException - if returning properties are specified but not supported by the dialect
    • prepareSpecialPropertyTypes

      protected void prepareSpecialPropertyTypes()
      Prepares special property types for this query.

      This method initializes the ID, version, and tenant ID property types from the entity type metadata.

    • validateIdExistent

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

      This method is typically called by operations that require an ID property, such as UPDATE and DELETE.

      Throws:
      JdbcException - if the entity has no ID properties
    • prepareOptions

      protected void prepareOptions()
      Prepares query options.

      This method sets the query timeout from the configuration if it's not already set.

    • isTargetPropertyName

      protected boolean isTargetPropertyName(String name)
      Determines whether a property should be included in the modification operation.

      This method applies the include and exclude filters to determine if a property should be targeted by the operation. The rules are:

      1. If includedPropertyNames is not empty, only properties in that list are included, unless they are also in excludedPropertyNames
      2. If includedPropertyNames is empty but excludedPropertyNames is not, all properties except those in excludedPropertyNames are included
      3. If both lists are empty, all properties are included
      Parameters:
      name - the property name to check
      Returns:
      true if the property should be included, false otherwise
    • setEntity

      public void setEntity(ENTITY entity)
      Sets the entity instance to be modified.
      Parameters:
      entity - the entity instance
    • getEntity

      public ENTITY getEntity()
      Returns the entity instance to be modified.
      Returns:
      the entity instance
    • setIncludedPropertyNames

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

      If this is set, only the specified properties will be included in the operation, unless they are also in the excluded property names.

      Parameters:
      includedPropertyNames - the property names to include
    • setExcludedPropertyNames

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

      If this is set, the specified properties will be excluded from the operation.

      Parameters:
      excludedPropertyNames - the property names to exclude
    • setSqlLogType

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

      public void setReturning(ReturningProperties returning)
      Sets the properties to be returned from the modification operation.

      This is used for database systems that support returning clause in modification statements.

      Parameters:
      returning - the returning properties
    • getSql

      public PreparedSql getSql()
      Returns the prepared SQL for this modification query.
      Specified by:
      getSql in interface ModifyQuery
      Specified by:
      getSql in interface Query
      Returns:
      the prepared SQL
    • isOptimisticLockCheckRequired

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

      public boolean isExecutable()
      Returns whether this query is executable.
      Specified by:
      isExecutable in interface ModifyQuery
      Returns:
      true if this query is executable
    • getSqlExecutionSkipCause

      public SqlExecutionSkipCause getSqlExecutionSkipCause()
      Returns the cause if SQL execution should be skipped.
      Specified by:
      getSqlExecutionSkipCause in interface ModifyQuery
      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 query.
      Specified by:
      isAutoGeneratedKeysSupported in interface ModifyQuery
      Returns:
      true if auto-generated keys are supported
    • getSqlLogType

      public SqlLogType getSqlLogType()
      Returns the SQL log type for this query.
      Specified by:
      getSqlLogType in interface ModifyQuery
      Returns:
      the SQL log type
    • toString

      public String toString()
      Returns a string representation of this query.

      This method returns the string representation of the SQL statement if it has been prepared, or null otherwise.

      Overrides:
      toString in class Object
      Returns:
      the string representation