- Type Parameters:
ENTITY- the entity type
- All Implemented Interfaces:
BatchInsertQuery,BatchModifyQuery,Query
This class implements BatchInsertQuery to provide batch INSERT operations for
entities. It handles ID generation, version initialization, and supports various duplicate key
handling strategies.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe context class for post-insert batch processing.protected static classThe context class for pre-insert batch processing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether batch operations are supported.protected String[]The names of columns that may cause duplicate key violations.protected DuplicateKeyTypeThe strategy for handling duplicate keys.protected GeneratedIdPropertyType<ENTITY,?, ?> The property type for the generated ID.protected booleanWhether to ignore auto-generated keys.protected IdGenerationConfigThe configuration for ID generation.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 the batch insert operation.voidgenerateId(Statement statement, int index) Generates an ID for the entity at the specified index using auto-generated keys.voidgenerateIds(Statement statement, int position, int size) Generates IDs for a range of entities using auto-generated keys.booleanDetermines whether batch operations are supported for this query.protected voidExecutes post-insert hooks on the current entity.protected voidExecutes pre-insert hooks on the current entity.voidprepare()Prepares this query for execution.protected voidPrepares ID and version property types for this query.protected voidPrepares the ID value for the current entity.protected voidPrepares the SQL statement for the current entity.protected voidPrepares the target property types for this query.protected voidPrepares the version value for the current entity.voidsetDuplicateKeyNames(String... duplicateKeyNames) Sets the names of columns that may cause duplicate key violations.voidsetDuplicateKeyType(DuplicateKeyType duplicateKeyType) Sets the strategy for handling duplicate keys.voidsetGeneratedKeysIgnored(boolean generatedKeysIgnored) Sets whether to ignore auto-generated keys.Methods inherited from class org.seasar.doma.jdbc.query.AutoBatchModifyQuery
getBatchSize, getEntities, getSql, getSqlExecutionSkipCause, getSqlLogType, getSqls, isAutoGeneratedKeysSupported, isExecutable, isOptimisticLockCheckRequired, isTargetPropertyName, 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
-
generatedIdPropertyType
The property type for the generated ID. -
idGenerationConfig
The configuration for ID generation. -
batchSupported
protected boolean batchSupportedWhether batch operations are supported. -
generatedKeysIgnored
protected boolean generatedKeysIgnoredWhether to ignore auto-generated keys. -
duplicateKeyType
The strategy for handling duplicate keys. -
duplicateKeyNames
The names of columns that may cause duplicate key violations.
-
-
Constructor Details
-
AutoBatchInsertQuery
Constructs an instance.- Parameters:
entityType- the entity type
-
-
Method Details
-
setGeneratedKeysIgnored
public void setGeneratedKeysIgnored(boolean generatedKeysIgnored) Sets whether to ignore auto-generated keys.- Parameters:
generatedKeysIgnored- whether to ignore auto-generated keys
-
setDuplicateKeyType
Sets the strategy for handling duplicate keys.- Parameters:
duplicateKeyType- the strategy for handling duplicate keys
-
setDuplicateKeyNames
Sets the names of columns that may cause duplicate key violations.- Parameters:
duplicateKeyNames- the names of columns that may cause duplicate key violations
-
prepare
public void prepare()Prepares this query for execution.This method processes all entities in the batch, applying pre-insert hooks, preparing ID and version values, and generating SQL statements for each entity.
- Specified by:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
preInsert
protected void preInsert()Executes pre-insert hooks on the current entity.This method creates a context for pre-insert processing and applies entity-specific pre-insert logic to the current entity.
-
prepareIdAndVersionPropertyTypes
protected void prepareIdAndVersionPropertyTypes()Prepares ID and version property types for this query.This method initializes the generated ID property type and configures ID generation settings, including whether batch operations and auto-generated keys are supported.
- Overrides:
prepareIdAndVersionPropertyTypesin classAutoBatchModifyQuery<ENTITY>
-
prepareTargetPropertyTypes
protected void prepareTargetPropertyTypes()Prepares the target property types for this query.This method determines which entity properties should be included in the INSERT statement based on their insertability, ID status, and other criteria. It also validates that non-generated ID properties have non-null values.
-
prepareIdValue
protected void prepareIdValue()Prepares the ID value for the current entity.If a generated ID property type is configured, this method applies pre-insert ID generation logic to the current entity.
-
prepareVersionValue
protected void prepareVersionValue()Prepares the version value for the current entity.If a version property type is configured, this method initializes the version value to 1 for the current entity.
-
prepareSql
protected void prepareSql()Prepares the SQL statement for the current entity.This method builds the appropriate SQL statement (INSERT or UPSERT) based on the duplicate key handling strategy and dialect capabilities.
-
isBatchSupported
public boolean isBatchSupported()Determines whether batch operations are supported for this query.- Specified by:
isBatchSupportedin interfaceBatchInsertQuery- Returns:
- true if batch operations are supported, false otherwise
-
generateId
Generates an ID for the entity at the specified index using auto-generated keys.This method retrieves the auto-generated key from the statement and updates the entity with the generated ID value.
- Specified by:
generateIdin interfaceBatchInsertQuery- Parameters:
statement- the statement that executed the insertindex- the index of the entity in the batch
-
generateIds
Generates IDs for a range of entities using auto-generated keys.This method retrieves auto-generated keys from the statement and updates the specified range of entities with the generated ID values.
- Specified by:
generateIdsin interfaceBatchInsertQuery- Parameters:
statement- the statement that executed the batch insertposition- the starting position in the entities listsize- the number of entities to process- Throws:
DomaIllegalArgumentException- if the position and size parameters are invalid
-
complete
public void complete()Completes the batch insert operation.This method applies post-insert hooks to all entities in the batch after the database operation has been executed.
-
postInsert
protected void postInsert()Executes post-insert hooks on the current entity.This method creates a context for post-insert processing and applies entity-specific post-insert logic to the current entity.
-