Class AutoBatchUpdateQuery<ENTITY>

Type Parameters:
ENTITY - the entity type
All Implemented Interfaces:
BatchModifyQuery, BatchUpdateQuery, Query

public class AutoBatchUpdateQuery<ENTITY> extends AutoBatchModifyQuery<ENTITY> implements BatchUpdateQuery
An auto batch update query that is executed against an entity class.

This class implements BatchUpdateQuery to provide batch UPDATE operations for entities. It handles version checking for optimistic locking and supports tenant ID-based isolation.

  • Field Details

    • versionIgnored

      protected boolean versionIgnored
      Whether to ignore the version property for optimistic locking.
    • optimisticLockExceptionSuppressed

      protected boolean optimisticLockExceptionSuppressed
      Whether to suppress optimistic lock exceptions.
    • helper

      protected BatchUpdateQueryHelper<ENTITY> helper
      Helper for batch update queries.
  • Constructor Details

    • AutoBatchUpdateQuery

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

    • prepare

      public void prepare()
      Prepares this query for execution.

      This method initializes the query by setting up the helper, preparing the entities, and generating SQL statements for each entity in the batch.

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

      protected void setupHelper()
      Sets up the batch update query helper.

      This method initializes the helper with the configuration, entity type, included and excluded property names, and optimistic locking settings.

    • preUpdate

      protected void preUpdate()
      Executes pre-update processing for the current entity.

      This method calls the entity type's preUpdate method with the current entity and updates the current entity if a new entity is returned from the context.

    • prepareOptimisticLock

      protected void prepareOptimisticLock()
      Prepares optimistic locking settings for this query.

      This method sets the optimistic lock check flag based on the version property type and the version ignored and optimistic lock exception suppressed flags.

    • prepareTargetPropertyTypes

      protected void prepareTargetPropertyTypes()
      Prepares the target property types for this query.

      This method gets the target property types from the helper and sets the executable flag to true if there are any target properties to update.

    • prepareSql

      protected void prepareSql()
      Prepares the SQL statement for the current entity.

      This method builds an UPDATE SQL statement with the appropriate SET clause for the target properties and WHERE clause for the ID properties, version property, and tenant ID property as needed.

    • incrementVersions

      public void incrementVersions()
      Increments the version property values of all entities.

      This method is called after successful execution of the batch update to increment the version values for optimistic locking.

      Specified by:
      incrementVersions in interface BatchUpdateQuery
    • complete

      public void complete()
      Completes this query by performing post-update processing for all entities.

      This method is called after the batch update has been executed to perform any necessary post-processing on the entities.

      Specified by:
      complete in interface Query
    • postUpdate

      protected void postUpdate()
      Executes post-update processing for the current entity.

      This method calls the entity type's postUpdate method with the current entity, updates the current entity if a new entity is returned from the context, and saves the current states of the entity.

    • setVersionIgnored

      public void setVersionIgnored(boolean versionIgnored)
      Sets whether to ignore the version property for optimistic locking.

      If set to true, the version property will not be used for optimistic locking in the WHERE clause of the UPDATE statement, and the version will not be incremented.

      Parameters:
      versionIgnored - whether to ignore the version property
    • setOptimisticLockExceptionSuppressed

      public void setOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed)
      Sets whether to suppress optimistic lock exceptions.

      If set to true, optimistic lock exceptions will not be thrown even if the version check fails during the update operation.

      Parameters:
      optimisticLockExceptionSuppressed - whether to suppress optimistic lock exceptions