Jul 25th, 2008, 08:23 PM
DB copy job
I am a fresh man to here, our project need such a job,
step1. read some data from db1 and write to db2
delete those copied data from db1
Can I assign tow datasources with different transaction managers for one step?
Or, maybe I should do delete task in another step if which should be deleted can be transfered from step1.
Jul 26th, 2008, 03:07 AM
It doesn't really matter if you do the delete in one step or another. What matters is that the two databases share a transaction manager. It either has to be JTA or else you need to synchronize commits between the two data sources, and have some business logic in place to detect data that have already been processed and ignore them (in case one side commits and the other rolls back). You could ask in the Data Access forum about the general problem of setting up a transaction manager in this scenario, since it isn't batch specific.
Jul 27th, 2008, 10:34 AM
Thank you for your reply.
I would lik to know how to set up a JtaTransactionManager with 2 datasources in spring batch? Could you tell me?
Thanks a lot.
Jul 28th, 2008, 12:52 AM
Like I said there is nothing batch specific about your question. You could try the Spring Reference Guide (http://static.springframework.org/sp...ansaction.html), or the Data Access forum (http://forum.springframework.org/forumdisplay.php?f=27) to get more detailed information.
Jul 28th, 2008, 05:16 AM
OK, so could you tell me whether datas can be shared between different steps in spring batch?
Jul 28th, 2008, 10:59 AM
To answer your question, any bean can be injected into the various configurable properties of any other bean any number of times, including those that belong to your steps. When used in a "singleton" scope, this means that your steps will share the "information" represented by that (or those) bean(s). Bear in mind that if you are running a multi-threaded job, this raises synchronization issues.
Additionally, the current trunk (I'm not sure if this has been in a release yet) allows the notion of job level execution contexts, which would further allow you to foster inter-step communication.
As more general advise, you may want to look into the official "replication" technology for your database solution as the means of copying the data on a regular basis. This will substantially decrease the risks involved in copying the data from one database to another. Then, you can use Spring Batch solely for the deletion aspect of your requirements.
Jul 30th, 2008, 09:50 AM
Thanks for your kind advice.
I just want to know whether spring batch can now or is going to support mutil-threads safety inter-step communication as you said in framework level.
And replication is so ok, but we need to do some transform between our DBs, one is for comsumer and the other is for our backoffice.
Jul 30th, 2008, 11:10 AM
Inter-step communication is supported through the job-level ExecutionContext as Doug already said. I think you might have misunderstood what a Step is though, because there would be no need for steps in multiple threads to communicate this way. Steps in 1.x are sequential anyway. I will have a think about parallel steps in 2.0 if you can explain your use case a bit, instead of focusing on framework features.
Jul 31st, 2008, 08:40 AM
I tried the JTA and failured at the latest sunday.
I thought I have to seperate the INSERT and DELETE to different step, so I need to share messages between INSERT step and the DELETE step.
But I found out the 2 phase commite solution by using JTA+JTOM+SpringBath at the day before yesterday.
Thanks both of you.