so I have the following concerns.
Imagine I have 3 different Profile Entities (meant for different databases) in my application. They differ in some minor details for example.
Now I am creating a Spring Batch Job that will run once every 24h. and update the profile entities Status(ACTIF/INACTIF).
Each entity uses its own Repository(JPA). The logic to update a profile is similar to all profiles, it is based on an activation date. If the current date matches the activation date -> activate the profile. That is it.
Is it possible to create some kind of abstraction when creating the Reader, Processor and Writer? Currently I have 3 similar implementations right now and for example the Reader only differs in the DataSource provided and the Class to which the BeanRowMapper maps. The processors are one for each of the three types. And the writer only differs in the injected Repository to which I am saving the items.
I thought of introducing an Interface that all 3 Profiles implement and go from there, but is this possible and can you give me some tips on how to do it?
Here is some examples with the ItemReader for example:
public JdbcPagingItemReader<**MiProfile**> transportProfileReader() throws Exception {
final var jdbcReader = "transportProfileReader";
JdbcPagingItemReader<MiProfile> reader = new JdbcPagingItemReaderBuilder<MiProfile>().name(jdbcReader)
.dataSource(**transportDataSource**)
.fetchSize(100)
.pageSize(1000)
.beanRowMapper(**MiProfile.class**)
.queryProvider(createQuery())
// .parameterValues() -- use if you need query params
.build();
reader.afterPropertiesSet();
return reader;
}
public JdbcPagingItemReader<**Profile**> hospitalProfileReader() throws Exception {
final var jdbcReader = "hospitalProfileReader";
JdbcPagingItemReader<Profile> reader = new JdbcPagingItemReaderBuilder<Profile>().name(jdbcReader)
.dataSource(**hospitalDataSource**)
.fetchSize(100)
.pageSize(1000)
.beanRowMapper(**Profile.class**)
.queryProvider(createQuery())
// .parameterValues() -- use if you need query params
.build();
reader.afterPropertiesSet();
return reader;
}
I am fairly new to Spring Batch, so don't be too harsh :)
Thank you in advance!