Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically connection to multiple databases from single J2ee Application

 
Sudheesh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sirs,

I have a J2ee application which is running in JBOSS Server. The Data tier is MySql. We are using CMP
Now the scenario is like this,
We are having two clients, and the clients have different sub users. The clients are using two seperate database for the same application. Now the application is working in two different servers assigned for each clients. Now we are planning to integrate it to a single application . I would like to know whether
1. Is it possible to specify the JNDI names for more than one database in the deployement descriptor?
2. if it is then, how can we instruct the container to lookup dynamically for the appropriate database based on the user logged in to the application .
I am planning to setup a new DB for the users information sothat the container can select the appropriate DB based on the user logged in...

Thankyou,
Sudheesh K S,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudheesh,
You can't have the same CMP point to different databases at the same time. Why not deploy the application twice and have each user point to a different one?
 
deepak jawa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing this problem now and have a solution for this...

same CMP class can be used but deployed with different ejb-name/jndi-name/datasource

so if u have 2 clients to support, the class remains same, but the deployment descriptors deploy the same CMP with 2 different names, 2 diff JNDI.. & they have different datasources...
Now in your code, u have the client info, which can be used to lookup the appropriate JNDI name.. (the jndi-name has a prefix of client name, which can be used during lookup..)

If you can write the DD by hand, well & gud.. because none of existing EJB doclet probably support such feature... i wud be writing a doclet for my code soon, as the number of CMPs is 100+ ..

I would like to have more suggestions on same from experts..

-thnx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic