• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change jta-data-source

 
Manuel Buck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi together,

Is it possible to change the jta-data-source dynamically? Background as follows:
I have an application which should be deployed on multiple server. On each server is a property file containing a data source, which is different on each server.
So there should always be an other jta-data-source respectively to the server.

Is it possible to do that, once the application is deployed on the server? Or is there any other way how to solve that.

Thanks in advance
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manuel,

I guess you are talking about JEE application?? Also it doesn't sound as you would like to change the JTA datasource dynamically but to use a server-specific datasource, right? That would be exactly what the jta-data-source tag in the persistence.xml descriptor is for. You use a JNDI name here which does NOT change across servers and is used as a reference by your application. Then in the application server configuration you can configure to which datasource this JNDI name should point. That means you shouldn't store the properties of your datasources in a separate properties file or whatever. Just use these information to configure your different servers accordingly. If you have any questions feel free to tell us a little bit more about what you are trying to achieve.

And of course: Welcome to JavaRanch

Marco
 
Manuel Buck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,

thanks for the response and the welcome greetings.

I have a datasource file with all the possible DB connections on the AS. So each server has all the datasources to every DB.
If I use the same JNDI name for each server it would always point to the same DB. The best solution would be a workaround to load the property file and to add the datasource out of this file.

Is there a way to achieve that, or do I have to add only one datasource configuration to each server?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend to keep the same JNDI name inside the persistence.xml descriptor for all application servers! So from the application's point of view environmental configuration differences wouldn't matter because the application only knows the identical name for the datasource(s) no matter to which server the application is being deployed. Another big advantage here is that you can deploy exactly the same artifact on all your servers. Everything else will sooner or later lead to much confusion because you would have to build server-specific EAR or WAR files and ensure that each server gets the correct artifact.

In my opinion there's one easy and clean solution to this problem. You should take the your property file with the configuration data for all datasources and use it to configure each application server with this information - preferably with an automated script. How this can be done depends on your application server. I guess most application servers provide some kind of command line interface which you could use from such a configuration script. Another way would be to create a template from your app server config (usually one or a few files) and populate the template with the data from your property file to generate the individual configuration file(s) for each server. As I said I would automate this process so that you are able to configure the whole cluster of application servers with one click or command.

Marco


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic