Class SqlFileUpdateQuery

All Implemented Interfaces:
ModifyQuery, Query, UpdateQuery

public class SqlFileUpdateQuery extends SqlFileModifyQuery implements UpdateQuery
A query that updates data in a database using an external SQL file.

This class extends SqlFileModifyQuery to provide functionality for executing UPDATE statements defined in external SQL files. It handles entity lifecycle callbacks, optimistic locking, and SQL file execution.

  • Field Details

    • entityHandler

      protected SqlFileUpdateQuery.EntityHandler<?> entityHandler
      The entity handler for this query.
    • nullExcluded

      protected boolean nullExcluded
      Whether to exclude null properties from the update operation.
    • versionIgnored

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

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

      protected boolean unchangedPropertyIncluded
      Whether to include properties that haven't changed in the update operation.
  • Constructor Details

    • SqlFileUpdateQuery

      public SqlFileUpdateQuery()
      Constructs a new instance.

      This constructor initializes the query with SqlKind.UPDATE to indicate that it performs an UPDATE operation.

  • Method Details

    • prepare

      public void prepare()
      Prepares this query for execution. This method must be called before the query is executed.

      This implementation prepares the SQL statement by processing the SQL file and handling entity lifecycle callbacks and optimistic locking.

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

      protected void initEntityHandler()
      Initializes the entity handler.

      This method delegates to the entity handler if one is available.

    • preUpdate

      protected void preUpdate()
      Executes pre-update entity lifecycle callbacks.

      This method delegates to the entity handler if one is available.

    • prepareTargetPropertyTypes

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

      This method delegates to the entity handler if one is available.

    • prepareExecutable

      protected void prepareExecutable()
      Prepares the executable state for this query.

      This method sets the query as executable if there is no entity handler or if the entity handler has target property types.

    • 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.

      This implementation delegates to the entity handler to populate values in the SQL context.

      Overrides:
      populateValues in class SqlFileModifyQuery
      Parameters:
      node - the populate node
      context - the SQL context
      Throws:
      UnsupportedOperationException - if no entity handler is available
    • prepareOptimisticLock

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

      This method delegates to the entity handler if one is available.

    • 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 implementation delegates to the entity handler to increment the version property.

      Specified by:
      incrementVersion in interface UpdateQuery
    • getEntity

      public <E> E getEntity(Class<E> entityType)
      Returns the entity associated with this query.
      Type Parameters:
      E - the entity type
      Parameters:
      entityType - the entity class
      Returns:
      the entity, or null if no entity is associated with this query
    • complete

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

      This implementation executes post-update entity lifecycle callbacks.

      Specified by:
      complete in interface Query
    • setEntityAndEntityType

      public <E> void setEntityAndEntityType(String name, E entity, EntityType<E> entityType)
      Sets the entity and entity type for this query.

      This implementation creates an entity handler for the specified entity.

      Specified by:
      setEntityAndEntityType in class SqlFileModifyQuery
      Type Parameters:
      E - the entity type
      Parameters:
      name - the parameter name for the entity
      entity - the entity
      entityType - the entity type
    • setNullExcluded

      public void setNullExcluded(boolean nullExcluded)
      Sets whether to exclude null properties from the update operation.
      Parameters:
      nullExcluded - whether to exclude null properties
    • setVersionIgnored

      public void setVersionIgnored(boolean versionIgnored)
      Sets whether to ignore the version property for optimistic locking.
      Parameters:
      versionIgnored - whether to ignore the version property
    • setOptimisticLockExceptionSuppressed

      public void setOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed)
      Sets whether to suppress optimistic lock exceptions.
      Parameters:
      optimisticLockExceptionSuppressed - whether to suppress optimistic lock exceptions
    • setUnchangedPropertyIncluded

      public void setUnchangedPropertyIncluded(Boolean unchangedPropertyIncluded)
      Sets whether to include properties that haven't changed in the update operation.
      Parameters:
      unchangedPropertyIncluded - whether to include unchanged properties