- Type Parameters:
ENTITY- the entity type
- All Implemented Interfaces:
ModifyQuery,Query,UpdateQuery
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA context class for post-update processing.protected static classA context class for pre-update processing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected UpdateQueryHelper<ENTITY>Helper for building the update query.protected booleanIndicates whether null properties should be excluded from the UPDATE statement.protected booleanIndicates whether optimistic lock exceptions should be suppressed.protected booleanIndicates whether unchanged properties should be included in the UPDATE statement.protected booleanIndicates whether the version property should be ignored for optimistic locking.Fields inherited from class org.seasar.doma.jdbc.query.AutoModifyQuery
autoGeneratedKeysSupported, EMPTY_STRINGS, entity, entityType, excludedPropertyNames, executable, idPropertyTypes, includedPropertyNames, optimisticLockCheckRequired, returning, sql, sqlExecutionSkipCause, sqlLogType, targetPropertyTypes, tenantIdPropertyType, versionPropertyTypeFields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcomplete()Completes this query after execution.voidIncrements the version number for the entity being updated.protected voidExecutes post-update processing for the entity.voidprepare()Prepares this query for execution.protected voidPrepares optimistic locking for this query.protected voidPrepares the SQL statement for this query.protected voidPrepares the target property types for this query.protected voidExecutes pre-update processing for the entity.voidsetNullExcluded(boolean nullExcluded) Sets whether null properties should be excluded from the UPDATE statement.voidsetOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed) Sets whether optimistic lock exceptions should be suppressed.voidsetUnchangedPropertyIncluded(Boolean unchangedPropertyIncluded) Sets whether unchanged properties should be included in the UPDATE statement.protected voidSets up the helper for this query.voidsetVersionIgnored(boolean versionIgnored) Sets whether the version property should be ignored for optimistic locking.Methods inherited from class org.seasar.doma.jdbc.query.AutoModifyQuery
getEntity, getSql, getSqlExecutionSkipCause, getSqlLogType, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequired, isTargetPropertyName, prepareOptions, prepareSpecialPropertyTypes, setEntity, setExcludedPropertyNames, setIncludedPropertyNames, setReturning, setSqlLogType, toString, validateIdExistentMethods inherited from class org.seasar.doma.jdbc.query.AbstractQuery
comment, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout, setCallerClassName, setCallerMethodName, setConfig, setMessage, setMethod, setQueryTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.seasar.doma.jdbc.query.ModifyQuery
getSql, getSqlExecutionSkipCause, getSqlLogType, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequiredMethods inherited from interface org.seasar.doma.jdbc.query.Query
comment, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
nullExcluded
protected boolean nullExcludedIndicates whether null properties should be excluded from the UPDATE statement. -
versionIgnored
protected boolean versionIgnoredIndicates whether the version property should be ignored for optimistic locking. -
optimisticLockExceptionSuppressed
protected boolean optimisticLockExceptionSuppressedIndicates whether optimistic lock exceptions should be suppressed. -
unchangedPropertyIncluded
protected boolean unchangedPropertyIncludedIndicates whether unchanged properties should be included in the UPDATE statement. -
helper
Helper for building the update query.
-
-
Constructor Details
-
AutoUpdateQuery
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:
preparein interfaceQuery- Overrides:
preparein classAutoModifyQuery<ENTITY>
-
setupHelper
protected void setupHelper()Sets up the helper for this query.This method initializes the
UpdateQueryHelperwith 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:
incrementVersionin interfaceUpdateQuery
-
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.
-
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
Sets whether unchanged properties should be included in the UPDATE statement.- Parameters:
unchangedPropertyIncluded- true to include unchanged properties, false otherwise
-