I got 'USING THE STEP EXECUTION CONTEXT AND PROMOTING THE DATA TO THE JOB EXECUTION CONTEXT' (Chapter 10 Spring Batch in Action) working by creating the db name in
TrackImportFromJobContextTasklet and retrieving it in VerifyStoreInStepContextTasklet.
I tweaked VerifyStoreInStepContextTasklet to see if I could set the udydb datasource url.
In launch-context I have
i.e. The datasource has not been instantiated yet (I think).
The next section in the book 'WRITING IN THE JOB EXECUTION CONTEXT AND READING USING LATE BINDING' won't work as in a different step.
So I am wrong in my thinking about the datasource and I think the code in VerifyStoreInStepContextTasklet breaches the whole separation of concerns?
I like the Dynamic Datasource Routing but can't figure out how to assign the db name which has been determined from an earlier step in the batch.
Not sure if this is correct. But I would think then in the early step when you get the name, that you put that value into the JobExecutionContext, so that it can be available for later steps, readers/writers/processors. Would that help?
As far as TransactionManagers, if you are using a transactionManager that support XA/two-phase commits, like JTA, then you can have just one TransactionManager, as long as your DataSources are XA compliant. Otherwise, yes you would have to have a transactionManager per DataSource.
Joined: Sep 26, 2008
Hi Mark - thanks for the help / pointers.
and on run it is giving me:
so will keep reading / experimenting...
Per the transactionManager - if I am not using the transactional atm concept (i.e. money must be debited at the same time as withdrawn across different databases) but inserts / updates are single database specific I am thinking I can use the 1 transactionManager?
[Within a step might be an insert to a db on another machine but since that step will be tied to a jdbc writer and so its dataSource, commits / rollbacks should be handled by the 1 transactionManager, right?]
So far my ideas are half-baked! ;-)
Joined: Sep 26, 2008
Okay - I got the Datasource url database name not known until after a Batch step - fixed.
Here is what I have:
In my launch-context.xml (relevant parts)
The 'envTarget' is to allow the job to read different properties files e.g. development / production. I did have to put
a legitimate jdbc url string for the client.udy.url entry as otherwise I got sql errors. (As a precaution I have
created an empty dummy db so nothing returned on reads etc.)
The next step in the job 'udytranStep' is my check to see what records are actually returned - it correctly connects to the batch job assigned db url and returns expected results.
Thanks to Mark for his help and hope this helps another newbie.