java


Dynamic association with multiple datasource JNDI entries with Spring


I have an existing simple Spring application with a DAO class that extends NamedParameterJdbcDaoSupport.
In the Spring context file, I have a "p:dataSource-ref" attribute that refers to a "jee:jndi-lookup" element, which references the JNDI name defined in the container.
Something like this:
<jee:jndi-lookup jndi-name="${jndiPrefix}/specificdb" id="mydb"/>
<bean class="com...dao.OrdersDAO" p:name="ordersDAO" p:dataSource-ref="mydb"/>
This all works fine. I've deployed this to both WebLogic and TomEE successfully.
I now need to consider a new application that has a slightly more dynamic relationship with its datasources. The overall dataflow of the new application will be very similar to the existing application.
The new application will have N datasources, all with the same data model. The container will have definitions for the JNDI names for all of the datasources, and I imagine I'll have to have an additional JNDI name that just contains a comma-separated string containing all of the JNDI names for the datasources.
What are some effective strategies for doing something like this in Spring?
Update:
One thing I didn't make clear in my original post is what kind of algorithm I would be using to "select" which datasource to use under the covers.
The point is, I'm not selecting a single datasource, I'm using all of them. The application requires the query to be run on all of the datasources and the resultset is the union of all of them.
The first answer describes a strategy that essentially connects a "facade" datasource to one of a set of other datasources. That's an interesting problem, but not what I'm looking for here.
In any case, I believe I understand how to do this, but I've yet to implement it yet. My intention is to dynamically create the set of datasources and associate them with a DAO (not sure whether I want a single DAO with a set of datasources or a 1-1 relationship between DAOs and datasources). An encompassing service will read a JNDI environment string at startup that contains a list of JNDI names for datasources, and dynamically create the DataSource objects. The query process will simply collect the results from each DataSource and union them together.
TomEE has the same kind of routing capabilities than Spring.
check these links out:
http://tomee.apache.org/dynamic-datasource.html
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/

Related Links

doClick(), and Simon: All buttons will unpress at the same time instead of individually
Java Algorithms: comparing each *thing* to every other [closed]
Whats causing this NullPointerException in AWT-EventQueue-0?
Gradle + Dropwizard + Shadow -> Could not find or load main class
Android - Try to send fake sms to myself without mobile network usage
Selenium, open new window
Using Android TCP Client app to interface with sensor
Normal distribution function:determine probability of a given point in Java
Set object reference to null or call the finalize() method?
Are there alternatives to String.format that use cached formatting? [closed]
Can't register portlets on Liferay
Could not find or load main class SDK -jar
Change Eclipse's tooltip/hint/sugestions/overlay window color
Get GZIPped file attributes (like 'gzip -l', basically compression ratio)
Possible Interview Java .equals [duplicate]
No selenium tests run during mvn integration test

Categories

HOME
maven
variables
asp.net-core
lodash
electron
tesseract
google-docs
spring-cloud-stream
jsrender
umd
sql-server-2016
cross-browser
primary-key
communication
vifm
spring-xd
remote-access
windows-phone-7
dtrace
telephony
kudan
trading
javacv
centos6.5
url-scheme
jaxb2
objectanimator
primitive
gsoap
nouislider
phonegap
pim
windows-dev-center
subset-sum
picasso
jmonkeyengine
suricata
dosbox
galen
google-closure
glew
bootstrap-dialog
http-redirect
gpx
sencha-touch-2.3
wptoolkit
long-polling
strptime
dotnetzip
nstextview
memory-alignment
flow-control
nxt
infix-notation
probability-density
log4c
bstr
python-stackless
dlna
suffix-tree
iad
rtbkit
qtableview
cannon.js
spidermonkey
event-bubbling
bigbluebutton
file-copying
rdtsc
responsive-slides
meteor-velocity
mbr
apc
google-cloud-save
opcache
qt-faststart
cassini-dev
referrer
rdoc
bluepill
datawindow
doh
horizontal-accordion
recent-documents
xfbml
remember-me
lpeg
visitor-statistic
google-friend-connect
sudzc
subviews
asp.net-mvc-areas
gallio
sustainable-pace
nerddinner
defensive-programming
grid-system
caching-application-block

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App