- Type Parameters:
ENTITY- the entity type
- All Implemented Interfaces:
BatchModifyQuery,BatchUpdateQuery,Query
This class implements BatchUpdateQuery to provide batch UPDATE operations for
entities. It handles version checking for optimistic locking and supports tenant ID-based
isolation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA context class for post-update processing in batch update operations.protected static classA context class for pre-update processing in batch update operations. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BatchUpdateQueryHelper<ENTITY>Helper for batch update queries.protected booleanWhether to suppress optimistic lock exceptions.protected booleanWhether to ignore the version property for optimistic locking.Fields inherited from class org.seasar.doma.jdbc.query.AutoBatchModifyQuery
autoGeneratedKeysSupported, batchSize, currentEntity, EMPTY_STRINGS, entities, entityType, excludedPropertyNames, executable, idPropertyTypes, includedPropertyNames, optimisticLockCheckRequired, sqlExecutionSkipCause, sqlLogType, sqls, 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 by performing post-update processing for all entities.voidIncrements the version property values of all entities.protected voidExecutes post-update processing for the current entity.voidprepare()Prepares this query for execution.protected voidPrepares optimistic locking settings for this query.protected voidPrepares the SQL statement for the current entity.protected voidPrepares the target property types for this query.protected voidExecutes pre-update processing for the current entity.voidsetOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed) Sets whether to suppress optimistic lock exceptions.protected voidSets up the batch update query helper.voidsetVersionIgnored(boolean versionIgnored) Sets whether to ignore the version property for optimistic locking.Methods inherited from class org.seasar.doma.jdbc.query.AutoBatchModifyQuery
getBatchSize, getEntities, getSql, getSqlExecutionSkipCause, getSqlLogType, getSqls, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequired, isTargetPropertyName, prepareIdAndVersionPropertyTypes, prepareOptions, setBatchSize, setEntities, setExcludedPropertyNames, setIncludedPropertyNames, 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.BatchModifyQuery
getBatchSize, getSql, getSqlExecutionSkipCause, getSqlLogType, getSqls, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequiredMethods inherited from interface org.seasar.doma.jdbc.query.Query
comment, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
versionIgnored
protected boolean versionIgnoredWhether to ignore the version property for optimistic locking. -
optimisticLockExceptionSuppressed
protected boolean optimisticLockExceptionSuppressedWhether to suppress optimistic lock exceptions. -
helper
Helper for batch update queries.
-
-
Constructor Details
-
AutoBatchUpdateQuery
-
-
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:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
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:
incrementVersionsin interfaceBatchUpdateQuery
-
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.
-
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
-