Class AutoUpdateQuery<ENTITY>

Type Parameters:
ENTITY - the entity type
All Implemented Interfaces:
ModifyQuery, Query, UpdateQuery

public class AutoUpdateQuery<ENTITY> extends AutoModifyQuery<ENTITY> implements UpdateQuery
A query implementation for automatically updating an entity.

This class handles the automatic generation of SQL UPDATE statements based on entity definitions and configuration settings. It provides support for optimistic concurrency control through version properties, and allows customization of which properties are included in the update operation.

  • Field Details

    • nullExcluded

      protected boolean nullExcluded
      Indicates whether null properties should be excluded from the UPDATE statement.
    • versionIgnored

      protected boolean versionIgnored
      Indicates whether the version property should be ignored for optimistic locking.
    • optimisticLockExceptionSuppressed

      protected boolean optimisticLockExceptionSuppressed
      Indicates whether optimistic lock exceptions should be suppressed.
    • unchangedPropertyIncluded

      protected boolean unchangedPropertyIncluded
      Indicates whether unchanged properties should be included in the UPDATE statement.
    • helper

      protected UpdateQueryHelper<ENTITY> helper
      Helper for building the update query.
  • Constructor Details

    • AutoUpdateQuery

      public AutoUpdateQuery(EntityType<ENTITY> entityType)
      Constructs an instance.
      Parameters:
      entityType - the entity type
  • 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.

      This method prepares the query for execution by setting up the helper, calling pre-update hooks, preparing property types, validating entity IDs, setting up optimistic locking, and generating the SQL statement.

      Specified by:
      prepare in interface Query
      Overrides:
      prepare in class AutoModifyQuery<ENTITY>
    • setupHelper

      protected void setupHelper()
      Sets up the helper for this query.

      This method initializes the UpdateQueryHelper with the current configuration and settings for property inclusion/exclusion, null handling, version handling, optimistic lock exception handling, and unchanged property handling.

    • preUpdate

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

      This method calls the entity's pre-update hooks with the appropriate context, allowing the entity to perform any necessary operations before the update is executed. If the pre-update hook returns a new entity instance, it will replace the current one.

    • prepareOptimisticLock

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

      This method sets up optimistic concurrency control based on the version property and configuration settings. If version checking is enabled and not suppressed, the query will be configured to check for optimistic lock violations.

    • prepareTargetPropertyTypes

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

      This method determines which entity properties will be included in the UPDATE statement based on the configuration and entity definition. If there are properties to update, the query is marked as executable.

    • prepareSql

      protected void prepareSql()
      Prepares the SQL statement for this query.

      This method builds the SQL UPDATE statement using the dialect-specific assembler and the configured property types. It creates a context with all necessary information for the assembler to generate the appropriate SQL for the current database dialect.

    • incrementVersion

      public void incrementVersion()
      Increments the version number for the entity being updated.

      This method is called after executing the UPDATE statement to update the version number in the entity object, ensuring it matches the value in the database after the update. This is important for optimistic concurrency control.

      This method increments the version number of the entity if optimistic concurrency control is enabled. The version property is used to detect concurrent modifications and prevent lost updates.

      Specified by:
      incrementVersion in interface UpdateQuery
    • complete

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

      This method completes the query execution by performing post-update processing.

      Specified by:
      complete in interface Query
    • postUpdate

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

      This method calls the entity's post-update hooks with the appropriate context, allowing the entity to perform any necessary operations after the update is executed. If the post-update hook returns a new entity instance, it will replace the current one. Finally, the current state of the entity is saved to track future changes.

    • setNullExcluded

      public void setNullExcluded(boolean nullExcluded)
      Sets whether null properties should be excluded from the UPDATE statement.
      Parameters:
      nullExcluded - true to exclude null properties, false otherwise
    • setVersionIgnored

      public void setVersionIgnored(boolean versionIgnored)
      Sets whether the version property should be ignored for optimistic locking.

      This method uses a bitwise OR operation to combine the current setting with the new value, ensuring that once version checking is ignored, it remains ignored.

      Parameters:
      versionIgnored - true to ignore the version property, false otherwise
    • setOptimisticLockExceptionSuppressed

      public void setOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed)
      Sets whether optimistic lock exceptions should be suppressed.
      Parameters:
      optimisticLockExceptionSuppressed - true to suppress optimistic lock exceptions, false otherwise
    • setUnchangedPropertyIncluded

      public void setUnchangedPropertyIncluded(Boolean unchangedPropertyIncluded)
      Sets whether unchanged properties should be included in the UPDATE statement.
      Parameters:
      unchangedPropertyIncluded - true to include unchanged properties, false otherwise