| Author |
Dynamic Datasource Routing
|
Jans Daniels
Greenhorn
Joined: Jun 28, 2011
Posts: 3
|
|
Hi, i'm stuck with this:
Our application is going to be a plain EJB app with SAP JPA Persistence (arrgh...)
What I'm trying to do is to switch the EntityManager's underlying datasource during application runtime.
I tried to implement my own DataSource (as SLSB), which does the lookup on the 'real' DataSources.
This works so far, but now I have to inject that custom DataSource into my Persistencecontext somehow.
Hope someone of you has some ideas for me,
TIA
Jans
|
 |
James Sutherland
Ranch Hand
Joined: Oct 01, 2007
Posts: 550
|
|
Why are you trying to do this?
Do you want to change it once on startup, or per query/transaction?
If you are trying to do some kind of dynamic data partitioning, you may wish to look at EclipseLink's data partitioning, replication and load balancing support,
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Data_Partitioning
Otherwise, you may wish to use an application managed EntityManager/Factory instead of container managed. Then you have control of its creation and can pass the data source in the properties map.
|
TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
|
 |
Jans Daniels
Greenhorn
Joined: Jun 28, 2011
Posts: 3
|
|
Hi, thanks for your quick reply.
No, I do not want to partition my data, I'd like to be able to change the DataSource per query.
The use case is: User logs on to web, gets a combobox with all available Datasources displayed
and chooses one. The user must be able to switch to another datasource during his session.
Meanwhile I found something which contains a solution I will try tomorrow.
It's sort of an application managed solution, but I thought of something more elegant, like a dynamic DataSource implementation that
will be fed to an EntityManager or EntityManagerFactory...
Thanks fo your help,
Jans
|
 |
 |
|
|
subject: Dynamic Datasource Routing
|
|
|