• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Datasource url database name not known until after a Batch step

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Been doing my reading (swirling around right now) and can't fix my current issue.

I have 5 datasources, three of which I can fill in 100% through a property file. The other 2 I have everything but the db name at the end of the url.

(An aside: am I correct in reading that I therefore need 5 Transaction Managers? - If so will follow up with a new question thread)

The schema is the same for db1 so no changes to rowmappers etc - just the db name (same principle for db2).

I came across Dynamic DataSource Routing which I worked through and got working as I try and understand how Spring does things.

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


And the


gives



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.

Any help appreciated. Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Mark
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark - thanks for the help / pointers.

I tried



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! ;-)

Peter
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)

My module-context.xml job section looks like:



VerifyStoreInStepContextTasklet (implements Tasklet) has:



TestBasicDataSource (implements Tasklet) has:



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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic