-
1. Re: multiple database servers for a multi-tenant environment
brian.stansberry Sep 10, 2007 7:08 PM (in response to lent)Maybe an approach to your #1 is to write a custom subclass of javax.naming.LinkRef and bind it into JNDI under "jdbc/myDatasource". The impl would override getLinkName() to read user context info from a ThreadLocal and use that context info to return the name of the correct customer-specific datasource.
-
2. Re: multiple database servers for a multi-tenant environment
lent Sep 12, 2007 12:42 PM (in response to lent)Hi Brian,
Thanks for your suggestion on option 1. I've been playing with it and it looks like the reference is resolved when a LinkRef is bound to JNDI so that subclassing LinkRef doesn't help (i.e. the JNDI entry is bound to a specific DS and not my LinkRef). Either that or JNDI lookups are being cached. Is there any way to disable JNDI caching if there is caching?
Regards,
Len -
3. Re: multiple database servers for a multi-tenant environment
brian.stansberry Sep 12, 2007 1:16 PM (in response to lent)There shouldn't be caching of lookup results.
Not sure why this isn't working for you; a cursory look at the relevant code makes me think it should. But I'm not a guru in this area.
Suggest you get the AS source code and have a look in the 'naming' module; classes org.jnp.interfaces.NamingContext and org.jnp.server.NamingServer. Those are the relevant client-side and server-side classes. -
4. Re: multiple database servers for a multi-tenant environment
lent Sep 12, 2007 6:54 PM (in response to lent)I took a look at the JNDI code and the problem wasn't there. In looking at the code, I believe the problem is that when the persistence-unit configuration which specifies the jta-data-source is processed, the datasource is looked up and stored as part of the persistence-unit information. It doesn't keep looking up the entry specified in jta-data-source.
I'm now thinking that I need to do something at the datasource level. Is there something there that I can subclass to introduce my own code for getting the connection?
Len -
5. Re: multiple database servers for a multi-tenant environment
brian.stansberry Sep 12, 2007 10:18 PM (in response to lent)(Palm smacks head) Of course! In the modern world there are always frameworks involved and they're for sure likely to do the lookup and cache the result. Sorry; for some reason your question shifted my thinking back to 2001. :(
Re: solving this at the datasource level, suggest you post on the JCA forums. -
6. Re: multiple database servers for a multi-tenant environment
lent Sep 14, 2007 1:08 PM (in response to lent)Okay, thanks Brian, I will try the other forums. BTW, does JBoss have a vendor specific way of getting the logged in user (some vendors do have it). Or is my only option to get the caller principal from the sesison context and save it in a thread local for use by my datasource (which I believe you alluded to in your first reply).
Regards,
Len -
7. Re: multiple database servers for a multi-tenant environment
brian.stansberry Sep 14, 2007 1:14 PM (in response to lent)See http://wiki.jboss.org/wiki/Wiki.jsp?page=SecurityFAQ, question 9.
Good luck!