- Type Parameters:
E- the entity type being updated
- All Known Implementing Classes:
AbstractPreUpdateContext,AutoBatchUpdateQuery.AutoBatchPreUpdateContext,AutoUpdateQuery.AutoPreUpdateContext,SqlFileBatchUpdateQuery.SqlFileBatchPreUpdateContext,SqlFileUpdateQuery.SqlFilePreUpdateContext
This interface provides methods to check if an entity or its properties have changed since the last database read, as well as methods to access and modify the entity being updated. It is typically used in entity listener implementations to perform custom logic before an update operation.
The context is passed to the preUpdate method of entity listeners.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the Doma configuration associated with this update operation.EntityType<?>Returns the entity type metadata for the entity being updated.Returns the DAO method that is annotated withUpdateand triggered this update operation.Returns the entity instance that is being updated.default ReturningPropertiesReturns the returning properties configuration for this update operation.booleanDetermines whether the entity has been changed since it was last read from the database.booleanisPropertyChanged(String propertyName) Determines whether a specific property of the entity has been changed.voidsetNewEntity(E newEntity) Sets a new entity instance to be used for the update operation.
-
Method Details
-
isEntityChanged
boolean isEntityChanged()Determines whether the entity has been changed since it was last read from the database.This method checks if any property of the entity has been modified by comparing the current values with the original values stored in the
OriginalStatesfield.This method always returns
truewhenUpdate.sqlFile()returnstrue, as SQL file-based updates do not perform change detection.- Returns:
trueif the entity has been changed,falseotherwise- See Also:
-
isPropertyChanged
Determines whether a specific property of the entity has been changed.This method checks if the specified property has been modified by comparing its current value with the original value stored in the
OriginalStatesfield.This method always returns
truewhenUpdate.sqlFile()returnstrue, as SQL file-based updates do not perform change detection.- Parameters:
propertyName- the name of the property to check- Returns:
trueif the property has been changed,falseotherwise- Throws:
EntityPropertyNotDefinedException- if the property is not defined in the entity- See Also:
-
getEntityType
EntityType<?> getEntityType()Returns the entity type metadata for the entity being updated.The entity type provides access to metadata about the entity class, including its properties, naming conventions, and other configuration.
- Returns:
- the entity type metadata
-
getMethod
Method getMethod()Returns the DAO method that is annotated withUpdateand triggered this update operation.This method provides access to the reflection Method object representing the DAO method that initiated the update operation.
- Returns:
- the Method object representing the DAO method
-
getConfig
Config getConfig()Returns the Doma configuration associated with this update operation.The configuration provides access to database connection, dialect, and other runtime settings for the current operation.
- Returns:
- the Doma configuration
-
getNewEntity
E getNewEntity()Returns the entity instance that is being updated.This is the entity instance after any modifications made by entity listeners in their preUpdate methods.
- Returns:
- the entity instance being updated
-
setNewEntity
Sets a new entity instance to be used for the update operation.This method is primarily used with immutable entity classes, allowing entity listeners to replace the entity instance with a modified version.
- Parameters:
newEntity- the new entity instance to use for the update- Throws:
DomaNullPointerException- ifnewEntityisnull
-
getReturningProperties
Returns the returning properties configuration for this update operation.Returning properties specify which columns should be returned by the database after an update operation, typically used with the RETURNING clause in SQL.
- Returns:
- the returning properties configuration, never
null - See Also:
-