Class SqlFileBatchModifyQuery<ELEMENT>
- Type Parameters:
ELEMENT- the type of elements in the batch
- All Implemented Interfaces:
BatchModifyQuery,Query
- Direct Known Subclasses:
SqlFileBatchDeleteQuery,SqlFileBatchInsertQuery,SqlFileBatchUpdateQuery
This class provides common functionality for executing batch operations using SQL files. It handles SQL file loading, parameter binding, and batch execution for INSERT, UPDATE, and DELETE operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe batch size for this query.protected ELEMENTThe current element being processed.The class of elements in the batch.The elements to be processed in the batch.protected static final String[]Empty string array used as default for property name arrays.protected String[]The property names to be excluded from the operation.protected booleanWhether this query is executable.protected String[]The property names to be included in the operation.protected final SqlKindThe SQL kind (INSERT, UPDATE, or DELETE).protected booleanWhether optimistic lock checking is required for this query.protected StringThe parameter name used in the SQL file.protected SqlExecutionSkipCauseThe cause for skipping SQL execution, if applicable.protected SqlFileThe SQL file.protected StringThe path to the SQL file.protected SqlLogTypeThe SQL log type for this query.protected List<PreparedSql>The prepared SQL statements for the batch.Fields inherited from class org.seasar.doma.jdbc.query.AbstractQuery
callerClassName, callerMethodName, config, message, method, queryTimeout -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSqlFileBatchModifyQuery(Class<ELEMENT> elementClass, SqlKind kind) Constructs a new instance with the specified element class and SQL kind. -
Method Summary
Modifier and TypeMethodDescriptionexpandColumns(ExpandNode node) Expands columns in the SQL statement.intReturns the batch size for this query.Returns the configuration for this query.Returns the elements to be processed in the batch.getSql()Returns a representative prepared SQL statement for this batch query.Returns the cause if SQL execution should be skipped.Returns the SQL log type for this batch query.getSqls()Returns the list of prepared SQL statements for this batch query.booleanReturns whether auto-generated keys are supported for this batch query.booleanReturns whether this batch query is executable.booleanReturns whether optimistic lock checking is required for this batch query.protected voidpopulateValues(PopulateNode node, SqlContext context) Populates values in the SQL context.voidprepare()Prepares this query for execution.protected voidPrepares the query options.protected voidPrepares the SQL statement for the current entity.protected voidPrepares the SQL file for this query.voidsetBatchSize(int batchSize) Sets the batch size for this query.voidsetElements(Iterable<ELEMENT> elements) Sets the elements to be processed in the batch.abstract voidsetEntityType(EntityType<ELEMENT> entityType) Sets the entity type for this query.voidsetExcludedPropertyNames(String... excludedPropertyNames) Sets the property names to be excluded from the operation.voidsetIncludedPropertyNames(String... includedPropertyNames) Sets the property names to be included in the operation.voidsetParameterName(String parameterName) Sets the parameter name used in the SQL file.voidsetSqlFilePath(String sqlFilePath) Sets the path to the SQL file.voidsetSqlLogType(SqlLogType sqlLogType) Sets the SQL log type for this query.toString()Methods inherited from class org.seasar.doma.jdbc.query.AbstractQuery
comment, getClassName, 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, getMethod, getMethodName, getQueryTimeout
-
Field Details
-
EMPTY_STRINGS
Empty string array used as default for property name arrays. -
elementClass
The class of elements in the batch. -
kind
The SQL kind (INSERT, UPDATE, or DELETE). -
sqlFilePath
The path to the SQL file. -
parameterName
The parameter name used in the SQL file. -
sqlFile
The SQL file. -
optimisticLockCheckRequired
protected boolean optimisticLockCheckRequiredWhether optimistic lock checking is required for this query. -
executable
protected boolean executableWhether this query is executable. -
sqlExecutionSkipCause
The cause for skipping SQL execution, if applicable. -
batchSize
protected int batchSizeThe batch size for this query. -
sqlLogType
The SQL log type for this query. -
includedPropertyNames
The property names to be included in the operation. -
excludedPropertyNames
The property names to be excluded from the operation. -
elements
The elements to be processed in the batch. -
currentEntity
The current element being processed. -
sqls
The prepared SQL statements for the batch.
-
-
Constructor Details
-
SqlFileBatchModifyQuery
Constructs a new instance with the specified element class and SQL kind.- Parameters:
elementClass- the class of elements in the batchkind- the SQL kind
-
-
Method Details
-
prepare
public void prepare()Prepares this query for execution. This method must be called before the query is executed.This implementation validates that required components are not null.
- Specified by:
preparein interfaceQuery- Overrides:
preparein classAbstractQuery
-
prepareSqlFile
protected void prepareSqlFile()Prepares the SQL file for this query.This method loads the SQL file from the repository using the configured dialect.
-
prepareOptions
protected void prepareOptions()Prepares the query options.This method sets the query timeout and batch size from the configuration if they're not already set.
-
prepareSql
protected void prepareSql()Prepares the SQL statement for the current entity.This method creates an expression evaluator and SQL builder to generate the SQL statement for the current entity, then adds it to the list of SQL statements for the batch.
-
expandColumns
Expands columns in the SQL statement.This method is called when an expand node is encountered in the SQL file.
- Parameters:
node- the expand node- Returns:
- the expanded column list
- Throws:
UnsupportedOperationException- if this operation is not supported by the implementing class
-
populateValues
Populates values in the SQL context.This method is called when a populate node is encountered in the SQL file.
- Parameters:
node- the populate nodecontext- the SQL context- Throws:
UnsupportedOperationException- if this operation is not supported by the implementing class
-
setSqlFilePath
Sets the path to the SQL file.- Parameters:
sqlFilePath- the SQL file path
-
setParameterName
Sets the parameter name used in the SQL file.- Parameters:
parameterName- the parameter name
-
setElements
Sets the elements to be processed in the batch.- Parameters:
elements- the elements
-
getEntities
Returns the elements to be processed in the batch.- Returns:
- the elements
-
setBatchSize
public void setBatchSize(int batchSize) Sets the batch size for this query.- Parameters:
batchSize- the batch size
-
setSqlLogType
Sets the SQL log type for this query.- Parameters:
sqlLogType- the SQL log type
-
setIncludedPropertyNames
Sets the property names to be included in the operation.- Parameters:
includedPropertyNames- the property names to be included
-
setExcludedPropertyNames
Sets the property names to be excluded from the operation.- Parameters:
excludedPropertyNames- the property names to be excluded
-
setEntityType
Sets the entity type for this query.- Parameters:
entityType- the entity type
-
getSql
Returns a representative prepared SQL statement for this batch query.This method is typically used for logging purposes.
- Specified by:
getSqlin interfaceBatchModifyQuery- Specified by:
getSqlin interfaceQuery- Returns:
- a representative prepared SQL statement
-
getSqls
Returns the list of prepared SQL statements for this batch query.- Specified by:
getSqlsin interfaceBatchModifyQuery- Returns:
- the list of prepared SQL statements
-
getConfig
Returns the configuration for this query.- Specified by:
getConfigin interfaceQuery- Overrides:
getConfigin classAbstractQuery- Returns:
- the configuration
-
isOptimisticLockCheckRequired
public boolean isOptimisticLockCheckRequired()Returns whether optimistic lock checking is required for this batch query.- Specified by:
isOptimisticLockCheckRequiredin interfaceBatchModifyQuery- Returns:
trueif optimistic lock checking is required
-
isAutoGeneratedKeysSupported
public boolean isAutoGeneratedKeysSupported()Returns whether auto-generated keys are supported for this batch query.- Specified by:
isAutoGeneratedKeysSupportedin interfaceBatchModifyQuery- Returns:
trueif auto-generated keys are supported
-
isExecutable
public boolean isExecutable()Returns whether this batch query is executable.- Specified by:
isExecutablein interfaceBatchModifyQuery- Returns:
trueif this batch query is executable
-
getSqlExecutionSkipCause
Returns the cause if SQL execution should be skipped.- Specified by:
getSqlExecutionSkipCausein interfaceBatchModifyQuery- Returns:
- the cause of SQL execution skip, or
nullif execution should not be skipped
-
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 batch query.- Specified by:
getSqlLogTypein interfaceBatchModifyQuery- Returns:
- the SQL log type
-
toString
-