Results 1 to 9 of 9

Thread: DB copy job

  1. #1
    Join Date
    Jul 2008
    Posts
    7

    Default 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.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

  3. #3
    Join Date
    Jul 2008
    Posts
    7

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

  5. #5
    Join Date
    Jul 2008
    Posts
    7

    Default

    Thanks.
    OK, so could you tell me whether datas can be shared between different steps in spring batch?

  6. #6

    Default

    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.

  7. #7
    Join Date
    Jul 2008
    Posts
    7

    Default

    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.

  8. #8
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

  9. #9
    Join Date
    Jul 2008
    Posts
    7

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •