Skip to content

Commit 69c6839

Browse files
committed
Add support to specify the database type with EnableBatchProcessing
Resolves #4320
1 parent f64d6e8 commit 69c6839

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.core.log.LogMessage;
3636
import org.springframework.core.type.AnnotationMetadata;
3737
import org.springframework.util.StopWatch;
38+
import org.springframework.util.StringUtils;
3839

3940
/**
4041
* Base registrar that provides common infrastructure beans for enabling and using Spring
@@ -135,6 +136,11 @@ private void registerJobRepository(BeanDefinitionRegistry registry, EnableBatchP
135136
beanDefinitionBuilder.addPropertyValue("isolationLevelForCreate", isolationLevelForCreate);
136137
}
137138

139+
String databaseType = batchAnnotation.databaseType();
140+
if (StringUtils.hasText(databaseType)) {
141+
beanDefinitionBuilder.addPropertyValue("databaseType", databaseType);
142+
}
143+
138144
beanDefinitionBuilder.addPropertyValue("maxVarCharLength", batchAnnotation.maxVarCharLength());
139145
beanDefinitionBuilder.addPropertyValue("clobType", batchAnnotation.clobType());
140146
registry.registerBeanDefinition("jobRepository", beanDefinitionBuilder.getBeanDefinition());

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.batch.core.launch.support.TaskExecutorJobLauncher;
3333
import org.springframework.batch.core.repository.JobRepository;
3434
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
35+
import org.springframework.batch.support.DatabaseType;
3536
import org.springframework.context.annotation.Import;
3637
import org.springframework.transaction.PlatformTransactionManager;
3738

@@ -179,6 +180,15 @@
179180
*/
180181
String dataSourceRef() default "dataSource";
181182

183+
/**
184+
* Set the type of the data source to use in the job repository. The default type will
185+
* be introspected from the datasource's metadata.
186+
* @since 5.1
187+
* @see DatabaseType
188+
* @return the type of data source.
189+
*/
190+
String databaseType() default "";
191+
182192
/**
183193
* Set the transaction manager to use in the job repository.
184194
* @return the bean name of the transaction manager to use. Defaults to

0 commit comments

Comments
 (0)