- Type Parameters:
ENTITY- the entity type
- All Implemented Interfaces:
ModifyQuery,Query
- Direct Known Subclasses:
AutoDeleteQuery,AutoInsertQuery,AutoMultiInsertQuery,AutoUpdateQuery
This class provides common functionality for entity-based modification operations such as INSERT, UPDATE, and DELETE. It handles:
- Entity property filtering (inclusion/exclusion)
- ID property management
- Version property handling for optimistic locking
- Tenant ID property handling for multi-tenancy
- SQL generation and execution control
Subclasses implement specific modification operations by extending this class and providing operation-specific logic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIndicates whether auto-generated keys are supported for this query.protected static final String[]An empty string array used as default for property name filters.protected ENTITYThe entity instance to be modified.protected final EntityType<ENTITY>The entity type metadata.protected String[]Names of properties to be excluded from the modification operation.protected booleanIndicates whether this query is executable.protected List<EntityPropertyType<ENTITY,?>> The ID property types of the entity.protected String[]Names of properties to be included in the modification operation.protected booleanIndicates whether optimistic lock checking is required for this query.protected ReturningPropertiesThe properties to be returned from the modification operation.protected PreparedSqlThe prepared SQL for this query.protected SqlExecutionSkipCauseThe cause if SQL execution should be skipped.protected SqlLogTypeThe SQL log type for this query.protected List<EntityPropertyType<ENTITY,?>> The property types targeted by this modification operation.protected TenantIdPropertyType<ENTITY,?, ?> The tenant ID property type for multi-tenancy, if the entity has one.protected VersionPropertyType<ENTITY,?, ?> The version property type for optimistic locking, if the entity has one.Fields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAutoModifyQuery(EntityType<ENTITY> entityType) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the entity instance to be modified.getSql()Returns the prepared SQL for this modification query.Returns the cause if SQL execution should be skipped.Returns the SQL log type for this query.booleanReturns whether auto-generated keys are supported for this query.booleanReturns whether this query is executable.booleanReturns whether optimistic lock checking is required for this query.protected booleanisTargetPropertyName(String name) Determines whether a property should be included in the modification operation.voidprepare()Prepares this query for execution.protected voidPrepares query options.protected voidPrepares special property types for this query.voidSets the entity instance to be modified.voidsetExcludedPropertyNames(String... excludedPropertyNames) Sets the names of properties to be excluded from the modification operation.voidsetIncludedPropertyNames(String... includedPropertyNames) Sets the names of properties to be included in the modification operation.voidsetReturning(ReturningProperties returning) Sets the properties to be returned from the modification operation.voidsetSqlLogType(SqlLogType sqlLogType) Sets the SQL log type for this query.toString()Returns a string representation of this query.protected voidValidates that the entity has at least one ID property.Methods 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.Query
comment, complete, getClassName, getConfig, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
EMPTY_STRINGS
An empty string array used as default for property name filters. -
includedPropertyNames
Names of properties to be included in the modification operation. -
excludedPropertyNames
Names of properties to be excluded from the modification operation. -
entityType
The entity type metadata. -
entity
The entity instance to be modified. -
sql
The prepared SQL for this query. -
targetPropertyTypes
The property types targeted by this modification operation. -
idPropertyTypes
The ID property types of the entity. -
versionPropertyType
The version property type for optimistic locking, if the entity has one. -
tenantIdPropertyType
The tenant ID property type for multi-tenancy, if the entity has one. -
optimisticLockCheckRequired
protected boolean optimisticLockCheckRequiredIndicates whether optimistic lock checking is required for this query. -
autoGeneratedKeysSupported
protected boolean autoGeneratedKeysSupportedIndicates whether auto-generated keys are supported for this query. -
executable
protected boolean executableIndicates whether this query is executable. -
sqlExecutionSkipCause
The cause if SQL execution should be skipped. -
sqlLogType
The SQL log type for this query. -
returning
The properties to be returned from the modification operation.
-
-
Constructor Details
-
AutoModifyQuery
Constructs an instance.- Parameters:
entityType- the entity type metadata
-
-
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.- Specified by:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery- Throws:
JdbcException- if returning properties are specified but not supported by the dialect
-
prepareSpecialPropertyTypes
protected void prepareSpecialPropertyTypes()Prepares special property types for this query.This method initializes the ID, version, and tenant ID property types from the entity type metadata.
-
validateIdExistent
protected void validateIdExistent()Validates that the entity has at least one ID property.This method is typically called by operations that require an ID property, such as UPDATE and DELETE.
- Throws:
JdbcException- if the entity has no ID properties
-
prepareOptions
protected void prepareOptions()Prepares query options.This method sets the query timeout from the configuration if it's not already set.
-
isTargetPropertyName
Determines whether a property should be included in the modification operation.This method applies the include and exclude filters to determine if a property should be targeted by the operation. The rules are:
- If includedPropertyNames is not empty, only properties in that list are included, unless they are also in excludedPropertyNames
- If includedPropertyNames is empty but excludedPropertyNames is not, all properties except those in excludedPropertyNames are included
- If both lists are empty, all properties are included
- Parameters:
name- the property name to check- Returns:
- true if the property should be included, false otherwise
-
setEntity
Sets the entity instance to be modified.- Parameters:
entity- the entity instance
-
getEntity
Returns the entity instance to be modified.- Returns:
- the entity instance
-
setIncludedPropertyNames
Sets the names of properties to be included in the modification operation.If this is set, only the specified properties will be included in the operation, unless they are also in the excluded property names.
- Parameters:
includedPropertyNames- the property names to include
-
setExcludedPropertyNames
Sets the names of properties to be excluded from the modification operation.If this is set, the specified properties will be excluded from the operation.
- Parameters:
excludedPropertyNames- the property names to exclude
-
setSqlLogType
Sets the SQL log type for this query.- Parameters:
sqlLogType- the SQL log type
-
setReturning
Sets the properties to be returned from the modification operation.This is used for database systems that support returning clause in modification statements.
- Parameters:
returning- the returning properties
-
getSql
Returns the prepared SQL for this modification query.- Specified by:
getSqlin interfaceModifyQuery- Specified by:
getSqlin interfaceQuery- Returns:
- the prepared SQL
-
isOptimisticLockCheckRequired
public boolean isOptimisticLockCheckRequired()Returns whether optimistic lock checking is required for this query.- Specified by:
isOptimisticLockCheckRequiredin interfaceModifyQuery- Returns:
trueif optimistic lock checking is required
-
isExecutable
public boolean isExecutable()Returns whether this query is executable.- Specified by:
isExecutablein interfaceModifyQuery- Returns:
trueif this query is executable
-
getSqlExecutionSkipCause
Returns the cause if SQL execution should be skipped.- Specified by:
getSqlExecutionSkipCausein interfaceModifyQuery- Returns:
- the cause of SQL execution skip, or
nullif execution should not be skipped
-
isAutoGeneratedKeysSupported
public boolean isAutoGeneratedKeysSupported()Returns whether auto-generated keys are supported for this query.- Specified by:
isAutoGeneratedKeysSupportedin interfaceModifyQuery- Returns:
trueif auto-generated keys are supported
-
getSqlLogType
Returns the SQL log type for this query.- Specified by:
getSqlLogTypein interfaceModifyQuery- Returns:
- the SQL log type
-
toString
Returns a string representation of this query.This method returns the string representation of the SQL statement if it has been prepared, or null otherwise.
-