Add support to specify the database type with EnableBatchProcessing

Resolves #4320
This commit is contained in:
Mahmoud Ben Hassine
2023-09-18 10:26:46 +02:00
parent f64d6e88a5
commit 69c6839415
2 changed files with 16 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.log.LogMessage;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
/**
* Base registrar that provides common infrastructure beans for enabling and using Spring
@@ -135,6 +136,11 @@ class BatchRegistrar implements ImportBeanDefinitionRegistrar {
beanDefinitionBuilder.addPropertyValue("isolationLevelForCreate", isolationLevelForCreate);
}
String databaseType = batchAnnotation.databaseType();
if (StringUtils.hasText(databaseType)) {
beanDefinitionBuilder.addPropertyValue("databaseType", databaseType);
}
beanDefinitionBuilder.addPropertyValue("maxVarCharLength", batchAnnotation.maxVarCharLength());
beanDefinitionBuilder.addPropertyValue("clobType", batchAnnotation.clobType());
registry.registerBeanDefinition("jobRepository", beanDefinitionBuilder.getBeanDefinition());

View File

@@ -32,6 +32,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.TaskExecutorJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
import org.springframework.batch.support.DatabaseType;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.PlatformTransactionManager;
@@ -179,6 +180,15 @@ public @interface EnableBatchProcessing {
*/
String dataSourceRef() default "dataSource";
/**
* Set the type of the data source to use in the job repository. The default type will
* be introspected from the datasource's metadata.
* @since 5.1
* @see DatabaseType
* @return the type of data source.
*/
String databaseType() default "";
/**
* Set the transaction manager to use in the job repository.
* @return the bean name of the transaction manager to use. Defaults to