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

Java Byte Operation - Converting 3 Byte To Integer Data
Apache Karaf 3rd party jar without bundle
Java array of constants
Returning the number of unique numbers in a sorted array [duplicate]
Java: given a HashMap, how can I use containsKey() to tell if key is explicitly mapped to a null value?
How to check if a host is reachable?
How do I transfer data from one scene to another in JavaFx?
sender's address displayed rather than his name while sending with SimpleMailMessage in java
Java Temperature Conversion Swing [closed]
Why I still get “http://localhost:8080” when I start my app by tomcat?
JAX-RS: Tomcat runs normally but root not found (404)
Why does my code not run?
Access Denied Error when Initializing a Thread in Java
Java 8 for-loop inconsistency: List of BinaryOperator vs List of Integer
Read array list from file text. (Loop, format for day and first/last day hot of temperature)
Difficulties with updating my Mac to the latest Java JDK

Categories

HOME
sendgrid
image
atom-editor
cookies
reflection
stock
bpmn
react-router
v8
sql-server-2016
google-project-tango
alpha
podio
webrequest
gitpitch
mapserver
django-simple-history
propel
reactcsstransitiongroup
connection-string
grails3
visjs
mps
sox
php-openssl
user-interaction
info.plist
tooltipster
filezilla
social-media
vision
procdump
flink-streaming
tinymce-4
preg-match
stormpath
bcd
oracle-fusion-middleware
titanium-mobile
column-family
openoffice.org
nssegmentedcontrol
bytecode-manipulation
adobe-premiere
az-application-insights
ws-security
powershell-dsc
fakeiteasy
menuitem
flickr-api
taffy
network-flow
multipeer-connectivity
python-c-api
python-webbrowser
alphabet
tizen-native-app
knpmenubundle
linode
mcafee
titanium-android
mediaelement
eventkit
nested-sets
static-ip-address
elements
azure-virtual-network
xml-attribute
testng-dataprovider
master-slave
hexdump
captivenetwork
oauth2client
system.management
r-tree
reactive-banana
cartesian-product
feedback
content-length
coveralls
service-accounts
vstest.console.exe
ami
composite
pretty-print
ng-animate
jscript.net
contenttype
p4java
mechanize-ruby
oracle-warehouse-builder
mbr
page-layout
opcache
eclipse-memory-analyzer
jelly
e4x
gil
appconkit
cufon
javax.script
file-comparison
winbugs14
iphone-web-app
vc90
sef
iweb

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