- Type Parameters:
ENTITY- the entity type
- All Implemented Interfaces:
BatchModifyQuery,Query
- Direct Known Subclasses:
AutoBatchDeleteQuery,AutoBatchInsertQuery,AutoBatchUpdateQuery
This class provides common functionality for batch operations that modify entities in the database, such as batch insert, update, and delete operations. It manages entity properties, optimistic locking, and SQL generation for batch operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether auto-generated keys are supported.protected intThe batch size.protected ENTITYThe current entity being processed.protected static final String[]Empty string array constant.The list of entities to be processed.protected final EntityType<ENTITY>The entity type.protected String[]The names of properties to be excluded from the query.protected booleanWhether this query is executable.protected List<EntityPropertyType<ENTITY,?>> The ID property types of the entity.protected String[]The names of properties to be included in the query.protected booleanWhether optimistic lock checking is required.protected SqlExecutionSkipCauseThe cause of SQL execution skip if the query is not executable.protected SqlLogTypeThe SQL log type.protected List<PreparedSql>The list of SQL statements to be executed in batch.protected List<EntityPropertyType<ENTITY,?>> The property types targeted by this query.protected TenantIdPropertyType<ENTITY,?, ?> The tenant ID property type for multi-tenancy.protected VersionPropertyType<ENTITY,?, ?> The version property type for optimistic locking.Fields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the batch size for this query.Returns the list of entities to be processed by this batch query.getSql()Returns the first SQL statement in the batch.Returns the cause of SQL execution skip if the query is not executable.Returns the SQL log type for this query.getSqls()Returns all SQL statements in the batch.booleanIndicates whether auto-generated keys are supported.booleanIndicates whether this query is executable.booleanIndicates whether optimistic lock checking is required.protected booleanisTargetPropertyName(String name) Determines if a property should be included in the query based on its name.protected voidPrepares the ID, version, and tenant ID property types from the entity type.protected voidPrepares the query options.voidsetBatchSize(int batchSize) Sets the batch size for this query.voidsetEntities(Iterable<ENTITY> entities) Sets the entities to be processed by this batch query.voidsetExcludedPropertyNames(String... excludedPropertyNames) Sets the names of properties to be excluded from the query.voidsetIncludedPropertyNames(String... includedPropertyNames) Sets the names of properties to be included in the query.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, prepare, 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, prepare
-
Field Details
-
EMPTY_STRINGS
Empty string array constant. -
targetPropertyTypes
The property types targeted by this query. -
idPropertyTypes
The ID property types of the entity. -
includedPropertyNames
The names of properties to be included in the query. -
excludedPropertyNames
The names of properties to be excluded from the query. -
entityType
The entity type. -
versionPropertyType
The version property type for optimistic locking. -
tenantIdPropertyType
The tenant ID property type for multi-tenancy. -
optimisticLockCheckRequired
protected boolean optimisticLockCheckRequiredWhether optimistic lock checking is required. -
autoGeneratedKeysSupported
protected boolean autoGeneratedKeysSupportedWhether auto-generated keys are supported. -
executable
protected boolean executableWhether this query is executable. -
sqlExecutionSkipCause
The cause of SQL execution skip if the query is not executable. -
sqls
The list of SQL statements to be executed in batch. -
entities
The list of entities to be processed. -
currentEntity
The current entity being processed. -
batchSize
protected int batchSizeThe batch size. -
sqlLogType
The SQL log type.
-
-
Constructor Details
-
AutoBatchModifyQuery
-
-
Method Details
-
prepareIdAndVersionPropertyTypes
protected void prepareIdAndVersionPropertyTypes()Prepares the ID, version, and tenant ID property types from the entity type.This method initializes the property types that are used for identifying entities and handling optimistic locking and multi-tenancy.
-
validateIdExistent
protected void validateIdExistent()Validates that the entity has at least one ID property.This method throws a
JdbcExceptionif the entity doesn't have any ID properties, as batch operations require entities to be identifiable.- Throws:
JdbcException- if the entity doesn't have any ID properties
-
prepareOptions
protected void prepareOptions()Prepares the query options.This method initializes the query timeout and batch size from the configuration if they haven't been explicitly set or if they have invalid values.
-
isTargetPropertyName
Determines if a property should be included in the query based on its name.This method checks if the property name is in the included properties list and not in the excluded properties list. If no included properties are specified, all properties except those explicitly excluded are considered targets.
- Parameters:
name- the property name to check- Returns:
trueif the property should be included,falseotherwise
-
setEntities
Sets the entities to be processed by this batch query.This method initializes the internal list of entities and prepares the SQL statements list with the same size as the entities list.
- Parameters:
entities- the entities to be processed- Throws:
NullPointerException- ifentitiesisnull
-
getEntities
Returns the list of entities to be processed by this batch query.- Returns:
- the list of entities
-
setBatchSize
public void setBatchSize(int batchSize) Sets the batch size for this query.The batch size determines how many entities are processed in a single batch operation.
- Parameters:
batchSize- the batch size
-
setIncludedPropertyNames
Sets the names of properties to be included in the query.If this is set, only the specified properties will be included in the query, unless they are also in the excluded properties list.
- Parameters:
includedPropertyNames- the names of properties to include
-
setExcludedPropertyNames
Sets the names of properties to be excluded from the query.If this is set, the specified properties will be excluded from the query, even if they are in the included properties list.
- Parameters:
excludedPropertyNames- the names of properties to exclude
-
setSqlLogType
Sets the SQL log type for this query.The SQL log type determines how SQL statements are logged.
- Parameters:
sqlLogType- the SQL log type
-
getSql
Returns the first SQL statement in the batch.- Specified by:
getSqlin interfaceBatchModifyQuery- Specified by:
getSqlin interfaceQuery- Returns:
- the first SQL statement
-
getSqls
Returns all SQL statements in the batch.- Specified by:
getSqlsin interfaceBatchModifyQuery- Returns:
- the list of SQL statements
-
isOptimisticLockCheckRequired
public boolean isOptimisticLockCheckRequired()Indicates whether optimistic lock checking is required.- Specified by:
isOptimisticLockCheckRequiredin interfaceBatchModifyQuery- Returns:
trueif optimistic lock checking is required,falseotherwise
-
isAutoGeneratedKeysSupported
public boolean isAutoGeneratedKeysSupported()Indicates whether auto-generated keys are supported.- Specified by:
isAutoGeneratedKeysSupportedin interfaceBatchModifyQuery- Returns:
trueif auto-generated keys are supported,falseotherwise
-
isExecutable
public boolean isExecutable()Indicates whether this query is executable.- Specified by:
isExecutablein interfaceBatchModifyQuery- Returns:
trueif this query is executable,falseotherwise
-
getSqlExecutionSkipCause
Returns the cause of SQL execution skip if the query is not executable.- Specified by:
getSqlExecutionSkipCausein interfaceBatchModifyQuery- Returns:
- the cause of SQL execution skip, or
nullif the query is executable
-
getBatchSize
public int getBatchSize()Returns the batch size for this query.- Specified by:
getBatchSizein interfaceBatchModifyQuery- Returns:
- the batch size
-
getSqlLogType
Returns the SQL log type for this query.- Specified by:
getSqlLogTypein interfaceBatchModifyQuery- Returns:
- the SQL log type
-
toString
Returns a string representation of this query.
-