• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Factory concept to provide DB transparency

 
Neha Yadav
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

My software needs to connect to any database, whose name is provided dynamically at run time. I have java prg packaged as .jar files for kind of database which provide connection to it.

The problem is i need to present a generic interface using Factory concept which should take care of interacting with the appropriate .jar file depending upon the DB dynamically.

Could someone please tell me how this can be done?
My code needs to independent of database xml/relational and also independent of any JDBC code. I have not implemented this abstraction.

Thank you
Regards
Neha
[ August 27, 2004: Message edited by: Neha Yadav ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Neha,

If you've already implemented your DB connectivity code then I think the optimum solution will be somewhat dependent on how you've done it.

The basic idea of a class factory is that, based on some information you supply either as a parameter or through some kind of configuration, it will manufacture that right kind of object of a given type.

If your database code (SQL & JDBC) are completely platform neutral then the only differences between databases will be the JDBC Driver and the connection string. You can abstract this further by using a javax.sql.DataSource (a Connection factory) with JNDI.

Otherwise you'll probably need to map your DAOs to the appropriate database, say in a properties file, and create a factory class which performs the lookup for the requested DAO, creating your object with something like Class.forName("com.myorg.myapp.dao.MyDAO").newInstance().

Does that make any sense?

Jules
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic