|
|
Transaction management using jdbc template
Hello ,
I am facing an issue - will explain it as follows:
Step 1 gt;
We are reading records off a database table - there could be N records
This is being done in the reader
Step 2 gt;
Now each record is being fed to the processor
The processor checks for the record type ( in our case RecordType is a field which can have values like quot;Creditquot; and quot;Debitquot;)
If its type is quot;debitquot; - I then need to perform additional business logic
Step 2.1 gt; Business logic in processor
This involves further querying other database tables
So I could get zero or more records in this case
Step 2.2 gt;
Now for each record that I get - I have to do a DML operation on some other tables
So if I get N records - I will perform N DML ( insert / update / delete) operations
Here is my problem - that if I get N records and if (N -1) records succeed but Nth record fails - then I do not see an option to rollback
This is because each of the record is being auto committed using JDBC template
Step 3 gt;
The writer will then delete the record which was fed to the processor from reader
I had two questions :
1 gt;
I would like to know if anyone has faced a similar issue using JDBC template and how they have configured / solved the issue to get a control over the tx management
needless to state - I would like to commit / roll back as one atomic unit the quot;Nquot; records received 2 gt;
Since my database operations are being performed in the processor rather than writer ( steps 2.2 ) wuold this impact the features of batch such as restarting a job ?
Thanks,
shashank
A TaskletStep manages the transaction for you at the chunk boundary. By default it assumes that an ItemProcessor is transactional, so executes it again after a rollback. You shouldn't have to do anything special. |
|