Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to specify the database type through EnableBatchProcessing #4320

Closed
fmbenhassine opened this issue Mar 6, 2023 · 2 comments
Closed

Comments

@fmbenhassine
Copy link
Contributor

fmbenhassine commented Mar 6, 2023

As of v5.0.1, there is no way to specify the database type through @EnableBatchProcessing. It should be possible to specify that parameter like other parameters, for example:

@Configuration
@EnableBatchProcessing(tablePrefix="Test", databaseType="Oracle")
public class MyBatchJobConfiguration {

}

The workaround to this is to manually customize the job repository bean by using JobRepositoryFactoryBean#setDatabaseType.


Reference: https://stackoverflow.com/questions/75622056/issue-during-spring-batch-upgrade/75625032?noredirect=1#comment133462153_75625032

@seonWKim
Copy link
Contributor

seonWKim commented Jun 29, 2023

Hi @fmbenhassine, after reviewing this issue, I worry if this feature might be confusing to users 🤔 . As far as I know, spring batch can determine the databaseType by utilizing the dataSource through the getDatabaseType() method in the DefaultBatchConfiguration class.

/**
* Return the database type. The default will be introspected from the JDBC meta-data
* of the data source.
* @return the database type
* @throws MetaDataAccessException if an error occurs when trying to get the database
* type of JDBC meta-data
*
*/
protected String getDatabaseType() throws MetaDataAccessException {
  return DatabaseType.fromMetaData(getDataSource()).name();
}

If users are able to specify databaseType in @EnableBatchProcessing, I think spring batch will require extra steps to validate whether the user given databaseType matches the dataSource's dataType registered in application context. If not, it might confuse users because now it's able to specify databaseType which doesn't match dataSource's true database type.

@fmbenhassine
Copy link
Contributor Author

@seonwoo960000

In Spring Batch 5, there are two ways to configure infrastructure beans: the declarative approach through the @EnableBatchProcessing annotation, or the programmatic approach by extending DefaultBatchConfiguration. These approaches should not be mixed.

What you are referring to is the programmatic way of configuring Spring Batch by extending DefaultBatchConfiguration.
This issue addresses the declarative way through the @EnableBatchProcessing annotation, in which specifying the database type is missing (ie the equivalent of overriding DefaultBatchConfiguration#getDatabaseType()) .

Either ways, detecting the database type from the datasource's metadata should be done when the type is not specified (will be addressed in this issue for the annotation).

spring batch will require extra steps to validate whether the user given databaseType matches the dataSource's dataType registered in application context

This extra validation is out of the scope of this issue.

@fmbenhassine fmbenhassine modified the milestones: 5.1.0, 5.1.0-M3 Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants