Issue Details (XML | Word | Printable)

Key: SPR-3014
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Marten Deinum
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

HotSwappableTargetSource like behavior based on some value.

Created: 05/Jan/07 03:30 AM   Updated: 05/Jan/07 04:43 AM
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Java Archive File ContextSwappableTargetSource.jar (3 kB)
2. Java Archive File ContextSwappableTargetSource.jar (3 kB)
3. Java Archive File ContextSwappableTargetSource050120071120.jar (3 kB)



 Description  « Hide
For one of my projects I needed to be able to have 1 codebase (1 web application) which connected to 40 different database. We needed something to switch the database connection (and in our case Hibernate SessionFactory) at runtime and per user request. For this we created something we called the ContextSwappableTargetSource. It consists of 3 classes 1 ContextHolder which is a ThreadLocal holder for a property (we set it with a filter) and the real ContextSwappableTargetSource class and an Exception class.

I noticed in the Spring forums that more people need something similair that is why I post my bit of code here. If it is interesting enough to use in the Spring codebase feel free. If not well it is documented for future reference :-).

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Marten Deinum added a comment - 05/Jan/07 03:31 AM
Added jar with classes and sources.

Note: I used SLF4J and Logback as the logging api.

Marten Deinum added a comment - 05/Jan/07 04:20 AM
Fixed minor bug and included readme.

Marten Deinum added a comment - 05/Jan/07 04:43 AM
Another minor bug fixed.

And learned a lesson, after refactoring/migrating code don't create a JIRA issue at once, but first test, test, test, test... :-S.

Can someone delete the other 2 attachments, as they are invalid.

Code can also be grabbed from http://bespring.googlecode.com/svn/trunk/ with your favorite SVN client.