- All Implemented Interfaces:
ModifyQuery,Query,UpdateQuery
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA handler for entity lifecycle callbacks and optimistic locking.protected static classA context for post-update entity lifecycle callbacks.protected static classA context for pre-update entity lifecycle callbacks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SqlFileUpdateQuery.EntityHandler<?>The entity handler for this query.protected booleanWhether to exclude null properties from the update operation.protected booleanWhether to suppress optimistic lock exceptions.protected booleanWhether to include properties that haven't changed in the update operation.protected booleanWhether to ignore the version property for optimistic locking.Fields inherited from class org.seasar.doma.jdbc.query.SqlFileModifyQuery
EMPTY_STRINGS, excludedPropertyNames, executable, includedPropertyNames, kind, optimisticLockCheckRequired, parameters, sql, sqlExecutionSkipCause, sqlFilePath, sqlLogTypeFields 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.<E> EReturns the entity associated with this query.voidIncrements the version number for the entity being updated.protected voidInitializes the entity handler.protected voidpopulateValues(PopulateNode node, SqlContext context) Populates values in the SQL context.voidprepare()Prepares this query for execution.protected voidPrepares the executable state for this query.protected voidPrepares optimistic locking for this query.protected voidPrepares the target property types for this query.protected voidExecutes pre-update entity lifecycle callbacks.<E> voidsetEntityAndEntityType(String name, E entity, EntityType<E> entityType) Sets the entity and entity type for this query.voidsetNullExcluded(boolean nullExcluded) Sets whether to exclude null properties from the update operation.voidsetOptimisticLockExceptionSuppressed(boolean optimisticLockExceptionSuppressed) Sets whether to suppress optimistic lock exceptions.voidsetUnchangedPropertyIncluded(Boolean unchangedPropertyIncluded) Sets whether to include properties that haven't changed in the update operation.voidsetVersionIgnored(boolean versionIgnored) Sets whether to ignore the version property for optimistic locking.Methods inherited from class org.seasar.doma.jdbc.query.SqlFileModifyQuery
addParameter, addParameterInternal, expandColumns, getSql, getSqlExecutionSkipCause, getSqlLogType, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequired, prepareOptions, prepareSql, setExcludedPropertyNames, setIncludedPropertyNames, setSqlFilePath, setSqlLogType, toStringMethods 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
-
entityHandler
The entity handler for this query. -
nullExcluded
protected boolean nullExcludedWhether to exclude null properties from the update operation. -
versionIgnored
protected boolean versionIgnoredWhether to ignore the version property for optimistic locking. -
optimisticLockExceptionSuppressed
protected boolean optimisticLockExceptionSuppressedWhether to suppress optimistic lock exceptions. -
unchangedPropertyIncluded
protected boolean unchangedPropertyIncludedWhether 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.UPDATEto 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:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
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
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:
populateValuesin classSqlFileModifyQuery- Parameters:
node- the populate nodecontext- 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:
incrementVersionin interfaceUpdateQuery
-
getEntity
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.
-
setEntityAndEntityType
Sets the entity and entity type for this query.This implementation creates an entity handler for the specified entity.
- Specified by:
setEntityAndEntityTypein classSqlFileModifyQuery- Type Parameters:
E- the entity type- Parameters:
name- the parameter name for the entityentity- the entityentityType- 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
Sets whether to include properties that haven't changed in the update operation.- Parameters:
unchangedPropertyIncluded- whether to include unchanged properties
-