You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Chris Lamey <cl...@localmatters.com> on 2007/04/06 18:03:15 UTC

AbstractRoutingDataSource & cache

Hello all,

I'm looking at using Spring's new-ish AbstractRoutingDataSource to hit
multiple DataSources with iBATIS.  I think it'll work fine in terms of
routing to the right DataSource via a ThreadLocal, but I'm concerned
about the iBATIS caching mechanism.

Specifically, it seems to me that if I have a single
SqlMapClientFactoryBean with RoutingDataSource as the DataSource, the
cache in the SqlMapClient won't know which 'real' DataSource the results
came from and mix them all together.  So if the databases in question
have the same schemas and some overlapping OIDs, the cache would be
messed up.

Does that sound about right?  Is there a way to avoid that other than
not using cache?  Is there a better way to use Spring and iBATIS with
multiple DataSources?

Thanks,
Chris

Re: AbstractRoutingDataSource & cache

Posted by Chris Lamey <cl...@localmatters.com>.
Hello again,

I've started writing a RoutingSqlMapClient that implements the
SqlMapInterface and delegates all calls to Map of SqlMapClients based on
a ThreadLocal.  Each target SqlMapClient will have its own specific
datasource.

My concern with this approach is the Spring declarative transaction
handling, but I think it will work.  Transactions are handled on a
per-thread basis, so as along as the key to the routing sqlmapclient
says the same on a per-thread call it should all work.

I would really appreciate any thoughts on this.

Thanks,
Chris

On Fri, 2007-04-06 at 10:03 -0600, Chris Lamey wrote:
> Hello all,
> 
> I'm looking at using Spring's new-ish AbstractRoutingDataSource to hit
> multiple DataSources with iBATIS.  I think it'll work fine in terms of
> routing to the right DataSource via a ThreadLocal, but I'm concerned
> about the iBATIS caching mechanism.
> 
> Specifically, it seems to me that if I have a single
> SqlMapClientFactoryBean with RoutingDataSource as the DataSource, the
> cache in the SqlMapClient won't know which 'real' DataSource the results
> came from and mix them all together.  So if the databases in question
> have the same schemas and some overlapping OIDs, the cache would be
> messed up.
> 
> Does that sound about right?  Is there a way to avoid that other than
> not using cache?  Is there a better way to use Spring and iBATIS with
> multiple DataSources?
> 
> Thanks,
> Chris