Nandan
Nandan

Reputation: 557

How to implement chunk processing using custom ItemReader

I am using Spring batch 2.1.9.RELEASE

I need to configure a job-step which reads the data from Mysql DB, process it and write back to Mysql. I want to do it in chunks.

I considered using JdbcCursorItemReader but the SQL is a complex one. I need to fetch data from three other tables to create the actual SQL to use in the reader.

But if I use a customItemReader with JdbcTemplate/NamedParameterJdbcTemplate, how can i make sure the step processes the data in chunk? I am not using JPA/DAOs.

Many thanks,

Upvotes: 0

Views: 2232

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18403

In Spring-batch data are normally processed as chunk; the easy way is to declare a commit-interval in step definition; see Configuring a step.

Another way to define a custom chunk policy is to implements your own CompletionPolicy.

To answer your question use the Driving Query Based ItemReaders to read from main table and build complex object (reading from other tables), define a commit-interval and use the standard read/process/write step pattern.

I hope I was clear, English is not my language.

Upvotes: 1

Related Questions