I am using the 'Data Access Object' java pattern for my application.
- Posted by: Kapil Mistry
- Posted on: May 24 2005 02:50 EDT
I have to talk to different types of DBs at a time. I mean, the DB which is solely to my new application will be one, say Oracle, but the application talks to a few other systems whose DB may be different.
In such a situation, how DAOs can be effectively used?
Actually I have made a design for a single database access at runtime. Now I need to enhance the design for a multiple database access. Is it possible to avoid looking at a completely different design ?
Thanks a lot.
Your real issue here is how well you have abstracted other systems with the use of DAO's
If you have a set of DAO's that abstracts away say one system, then those DAO's could be pointed at a particular DataSource that represents that system's database (via XML descriptor or whatever facility that you have designed into your DAO framework). Its fine to have cohesive groups of DAO's pointed at different DataSources.
If your abstractions aren't quite right, then you will run into the issue where a single DAO may have to point at multiple DataSource's, and thats where the trouble really begins because you have leakage between callers and the DAO implementation
Jason ,Thank you for the prompt reply. I intend get back to this thread with a few more ideas pertaining to the DAO.
Sometime indirection is verbose and slow but in your case you could use below the DAO an OR mapping framework like hibernate. So your DAO will be more far from the DB and probably need no change at all when supporting other database. Also Spring provides useful abstraction level, one of them is the exceptions around db access, they are not DB vendor specific and still provide all the information you need.
I think for this purpose u should implement a factory for your DAO's, take a look at the Abstract Factory Pattern strategy for implementing it at this link:
Data Access Object
I think it would help you! :)