ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: Dynamically Discovering DataSource
Date Thu, 21 Apr 2005 16:15:17 GMT
This is such an unusual case that IMO, the DataSourceFactory should not be 
changed to accommodate it.

You could probably use a ThreadLocal class to set the parameter, then in 
your datasource, examine it to decide the real datasource to use.


On 4/21/05, Rafiq, Adnan <arafiq@carreker.com> wrote:
> Larry,
>  Thanks for the suggestion.
>  I looked at the DataSourceFactory. The method getDataSource() does not 
> take any parameters. The flow of our application is like this:
>  1 - Contact the system datasource and get a list of all companies and 
> their associated datasource jndi names
> 2 - When the user logs in, we get its company id and using it as a key we 
> find the corresponding datasource jndi name
> 3 - The company datasource jndi name is then returned and used for all 
> connections.
>  What seems like a good solution is to extend the JNDIDataSourceFactory 
> and overload the method getDataSource so that it can accept a company id as 
> an argument: getDataSource(int companyId). Internally, we have a map of 
> companyid (key) and datasource name (value).
>  However, what I can't figure out is where that method is actually called 
> in iBatis.
>  Thanks,
>  - Adnan
> -----Original Message-----
> *From:* Larry Meadors [mailto:larry.meadors@gmail.com]
> *Sent:* Thursday, April 21, 2005 10:26 AM
> *To:* ibatis-user-java@incubator.apache.org
> *Subject:* Re: Dynamically Discovering DataSource
> Roll your own javax.sql.DataSource (6 methods) and 
> com.ibatis.sqlmap.engine.datasource.DataSourceFactory (2 methods).
> Larry
> On 4/21/05, Rafiq, Adnan <arafiq@carreker.com> wrote: 
> > 
> > I have a situation where we have an ASP-like environment. There is one 
> > system database and several customer-specific databases. Each customer 
> > database is mapped to a different datasource. In iBatis we have to hardcode 
> > the JNDI name for the datasource in the sql-map-confi.xml file. Is there 
> > anyway to make this dynamic? In other words, I want to query the customer 
> > datasource name (the names are stored in the system database) at run time 
> > based on the user id, and then use that name for getting my connections.
> >  Any help is greatly appreciated.
> > 

View raw message