Refactoring Code: For DB Efficiency
Hi,
Need to refactor these codes due to anticipated performance reasons.
Please lend me your advice or suggestions for minimal change.
1) BaseDAO.java
public BaseDAO() throws ConnectionException {
conn = ConnectionManager.getConnection();
}
public BaseDAO(String ORACLE_DRIVER, String HOST_NAME, String PORT, String DB_NAME, String USER_NAME, String PASSWORD) throws ConnectionException {
conn = ConnectionManager.getConnection(ORACLE_DRIVER, HOST_NAME, PORT, DB_NAME, USER_NAME, PASSWORD);
}
public void closeConnection() {
try {
ConnectionManager.closeConnection();
}
catch (ConnectionException ex) {
}
}
At constructor level, it automatically get a direct db connection on-demand.
There is no connection pooling.
2) MyDAO.java
public class MyDAO extends BaseDAO {
public String[] retrieveFromTableA(String input) {}
public String[] retrieveFromTableB(String input) {}
}
Each DAO can have multiple methods which access the db via the parent class's conn variable.
3) BatchProgram.java
In the business logic for each batch program, there can be multiple instantiation of different DAOs.
Risk: This has the potential to take up numerous db connections, especially if the program does a loop and new() the DAOs within it.
The connection is released when the DAO object is NOT needed, i.e. myDAO.closeConnection().
Risk: The connection(s) will still be held in the progams unless specifically closed.
Any suggestions on how to abstract out the getConnection() and closeConnection() logic?
This is to reduce the number of concurrent db sessions @ any time.
Thanks.

