I'm working on a Spring Batch job that creates a string that is based off of sql insert, delete, or update statements. It reads in a flatfile where the first three characters of each line are either add
, chg
, or del
.
Example:
ADD123456001SOUTHLAND PAPER INCORPORATED ... //more info
CHG123456002GUERNSEY BIG DEAL FAIRFAX ...//more info
DEL123456002GUERNSEY BIG DEAL FAIRFAX ...//more info
From the above statements my ItemReader will generate three strings: insert into ...
, update ...
and delete ...
. The reader reads in the entire flatfile, returns an arraylist of these strings to my writer, and my writer will take these strings and write to my database.
Here's my problem. What happens if there's a chg
requested before an add
is requested? What if I try changing something that's already deleted?
I read up on ItemProcessor on SpringDocs and the description of filtering processes is exactly what I'm trying to do:
For example, consider a batch job that reads a file containing three different types of records: records to insert, records to update, and records to delete. If record deletion is not supported by the system, then we would not want to send any "delete" records to the ItemWriter. But, since these records are not actually bad records, we would want to filter them out, rather than skip. As a result, the ItemWriter would receive only "insert" and "update" records.
But the examples of ItemProcessor
listed on the docs don't really make sense to me. Can someone make sense of the process to me? Or show me some examples of good ItemProcessing?
Edit: the 6 characters following the command are the id associated in the SQL database.