The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Database migration

Posted by Jay on January 22, 2002 at 1:22 PM

Well, I have been there once. We moved from Oracle to MS SQL and believe me its a nightmare of unimaginable magnitude! Oracle does not support TOP keyword, calling stored procedures is different, what not.

So, I proppsed a design and my boss kinda likes it. Thought I'd share and argue.

To sum up, its a mix of Singleton and Abstract Factory.

I have an interface SQLFactory which has a bunch of methods that promise a certain behaviour. For example,


public interface SQLFactory
{
public string getPassword(String userID);
//and a few more ...
}

Now I have classes that implement this interface, specific to a database vendor. For example,


public class OracleSQLFactory implements SQLFactory
{
public String getPassword(String userID)
{
//get connection from a pool.
//call stored procedure or execute SQL statement.
//heres where Oracle is different from MS SQL (to me anyways)
//return passwordForThisUserID.
}
}

And another class, MSSQLFactory which has statements specific to MS SQL.

Now all this is of no good with out this last part. create a reference of SQLFactory which can be accessed through out the application.
and 'take care' that at any point of time this reference refers to just one of the implementing classes (obviously it depends on the database in use.)

Now, all calls will be made to this reference. So, one who concentrates on business logic, is happy with the promise of interface and doesnt need to care about database calls or whatever.

So to move to IBM DB2, I just need to implement SQLFactory thingee and I am happy. Take a step further and create this instance at runtime.


Note that if the application changes, interface changes too.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us