Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

suggestions for a "user selectable database" design

 
j po
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inherited a big jumbled, messy, old java application. Currently the app overview is like this:

-some Struts 2 that we added but, 75% old legacy stupidly written java that is total spaghetti and almost non-existent OO design implementation. (Don't even have a 'user' object for example)
-running on Tomcat 6 which handles the connection pooling
*upon login, the user selects the database out of a dropdown. his datasource, based upon user selection, is then passed around in every method signature all the way back to the DAO where it is then used. Don't even ask *why?*, let's just say...it's the government

All the designs I have previously worked on never had any kind of selectable database/datasource requirement like this. So, I'm looking for some design input on how this could be refactored in a more efficient/elegent way.

Let me know if more detail is needed. I appreciate in advance, everyone's time.

J
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have init method that will set data source to every services that require data source.
When user login just call the init method.
 
j po
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. Could you explain this a little more?

"set data source to every services that require data source".

It's just a ton of classes that have the need for the datasource. So, how do you get the datasource from the login (or init method, as you mentioned, to the back end dao's (and other legacy classes that hit the db)?

thanks again!
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do something like:



I hope you get some idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic