Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Spring Batch an overkill

Tags:

spring-batch

I need to load a CSV into a database once a week. There is some data massaging required as the CSV file has data for 2 tables. So I will have to process the CSV file a bit, probably convert it into 2 different CSV files and load it into a database.

I already have quartz configured in place. Do you think it would be an overkill to use spring batch to do the job? I am wondering when should I use it and when should I just do away with quartz bean do the processing itself.

like image 308
Jinesh Parekh Avatar asked Mar 09 '11 04:03

Jinesh Parekh


1 Answers

Spring Batch is perfect for these kinds of jobs because it reduces the parts that you have to care about. In this case, all you care about is massaging the data and then inserting into two different tables. You could read the data using the FileItemReader. Then use an ItemProcessor to change any incoming data and output the correct data, properly massaged. You supply the itemProcessor since it's your custom Java logic. Then you can use the JdbcItemWriter or simply plug in your own.

The nicest part about this is that it's [a] super commonplace so there's lots and lots and lots of examples (see: Spring Batch 2.0 – Part II – Flat File To Database or joshlong/joshlong-examples/spring-batch-starter or the samples in Spring batch itself for inspiration) and [b] it's mostly declarative. You don't have to worry about the things you don't care about - you're not in the business of figuring out how to correctly parse CSV files, or even how to read files in in a scalable way. You just want to make sure the data is valid and make sure it ends up where it's supposed to end up.

like image 150
Josh Long Avatar answered Sep 28 '22 15:09

Josh Long