PDA

View Full Version : Code Duplication


Martin Kersten
Aug 13th, 2004, 03:21 AM
I have found a code duplication, I stumble across several times. The code duplication I have noticed looks like:

HibernateDaoSupport:
protected final Session getSession(boolean allowCreate)
throws DataAccessResourceFailureException, IllegalStateException {
return (!allowCreate ?
SessionFactoryUtils.getSession(getSessionFactory() , false) :
SessionFactoryUtils.getSession(getSessionFactory() ,
this.hibernateTemplate.getEntityInterceptor(),
this.hibernateTemplate.getJdbcExceptionTranslator( )));
}


And is repeated in HibernateTemplate:
public Object execute(HibernateCallback action) throws DataAccessException {
Session session = (!isAllowCreate() ?
SessionFactoryUtils.getSession(getSessionFactory() , false) :
SessionFactoryUtils.getSession(getSessionFactory() , getEntityInterceptor(),
getJdbcExceptionTranslator()));
.....}


I would like to see this changed, because code duplication makes me nervous :).