As this forum is dedicated for Java Design related issues, I would like to start a small discussion about a system. My intention is to share my views and get the opinions from the group from their experiences.
I was just thinking of a simle system that will connect to different databases (Oracle, As/400) and execute some query. After the query execution, there will be a report generating facility. Now, this may be developed in swing or might be in JSP, but what matters most is the base class structure. I guess, that will remain same for any type of front end you develop.
I have started with some idea and putting it below. I would like to have group's views/suggestions on it (positive/ negative both ).
Here it goes:
Requirements of the system: 1. There should be some file in the system that would store data about different database profiles. Here profile means, data required to connect to a database. e.g. To connect to oracle you need : DbDriver Name, Machine Ip, Port number, Db Instance Name, User Name, Password. So, I have thought of a XML file to store this info. Structure of the XML file would be --> <DbProfiles> <Profile id=1 DbType="Oracle"> <ServerName>sgp</ ServerName> <ServerIP>xx.xx.xx.xx</ServerIP> <port>1234</port> <DbInstanceName>seca</DbInstanceName> <UserName>name</UserName> <Password>pass< /Password> </Profile>
3. There will be classes implenting this interface. There could be 1 class for 1 Db type. i.e. Currently I have thought of like public class OraProfile implements DbProfile {} public class As400Profile implements DbProfile {} .. .. so on.
The XML file defined in the step 1 will be read when the utilty starts and it will create instances of classes equal to the number of profiles defined in file. All such instances created will be stored at some global place and then will be used for creating connections.
3. I have thought of 1 more class that will define a method as below:
public class DoDbTask{ public Connection getConnection(DbProfile objDbPRofile){ }
public ResultSet execute(Connection con, String query) { } }
Though the complete concept of the system contains reporting facility also, for now only this much I have put on the paper. I know, it is not too much. But, before going ahead I thought of doing validation by sharing my ideas with the group.
Here is a small change from myself only. All the String fields in the "interface DbProfile" are now in "abstract class DbProfileImpl". And the class OraProfile, As400Profile will extend from DbProfileImpl class. This will force the subclasses 1. to give implementation to getURL() method and 2. To use the inhertited fields in the superclass
Here is the abstarct class: public abstract class DbProfileImple implements DbProfile { String dbMachineName; String dbMachineIp; String dbMachinePort; String dbInstanceName;
String strUserName; String strPassword;
public abstract String getURL();
public String getUserName() { return strUserName; }
public String getPassword() { return strPassword; } } // End of class