JPA/Eclipselink - select DataSource/JDBC URL dynamically

Is there a way that I can get JPA (Eclipselink specifically) to dynamically select a connection pool depending on some property bound to the current thread?

The problem I'm trying to solve is scaling a multitenant system, where tenants may be split up over several DB instances. Each DB instance will be multitenant, but to scale, I may not be able to fit all tenants in one DB instance comfortably.

I am familiar with @Multitenant to support single-table multitenancy, and have successfully used Eclipselink session event callbacks to set values in the Eclipselink Session dynamically. I'm trying to take the next step of changing the DataSource that the EntityManager will be using, so I don't have to necessarily use a clustered DB.

Thanks!

Answers


Take a look at this

http://code.google.com/p/jdbc-helper/wiki/LoadBalancingDataSource

It creates a datasource that loadbalances to backend datasources.


You can use an EntitiyManagerFactory which allows the creation of an EntitiyManager for a specific datsasource (via a String property) as explained under

http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/


You might want to check this post. It might be helpful or give you a clue on how to achieve your solution.


Need Your Help

Javascript clearInterval with button click

javascript jquery clearinterval

I'm having issues getting clearInterval to work when I try to bind it to a button click. Also, apparently the function is starting on it's own... Here's my code

Why extract SIFT features on patches instead of the whole image?

image-processing sift

Some people extract SIFT features from patches of an image, such as "128-dimensional SIFT descriptors were computed over 16×16 pixel patches, sampled densely over a grid with a regular spacing of 8