저의 실수를 이야기 하고자 합니다.
몇일간 Source 수정을 하다 생성자가 하나 더 필요해서 어떻게 하면 중복 되지 않게 만들까 하고 고민 했습니다.
그런데 별다른 수가 생각나지 않아서 아래와 같이 하였습니다.
public Connection getConnection(){
try {
loadDriver();
Connection conn = DriverManager.getConnection(StandAloneBatchConstants.getDRIVER_URL(),
StandAloneBatchConstants.getDATABASE_USER(), StandAloneBatchConstants.getDATABASE_PASSWD());
preMethodCallProcedure(conn);
return conn;
} catch (Exception ex) {
log.error(ex.getMessage(),ex);
throw new DAOException(new StandAloneErrorHandler("FRM10501").getMessage());
}
}
public Connection getConnection(module){
try {
loadDriver();
Connection conn = DriverManager.getConnection(StandAloneBatchConstants.getDRIVER_URL(),
StandAloneBatchConstants.getDATABASE_USER(module), StandAloneBatchConstants.getDATABASE_PASSWD(module));
preMethodCallProcedure(conn);
return conn;
} catch (Exception ex) {
log.error(ex.getMessage(),ex);
throw new DAOException(new StandAloneErrorHandler("FRM10501").getMessage());
}
}
중복된 모습이 정말 아름답지 못합니다.
이걸 다음과 같이 바꾸면 좋습니다.
public Connection getConnection(){
getConnection("default");
}
public Connection getConnection(module){
#$^#$%
}