Thursday, June 30, 2011

eclipse replace multiple lines


Problem: Hibernate Tools DAO generation generates SeeionFactory with getter via JNDI

private final SessionFactory sessionFactory = getSessionFactory();


protected SessionFactory getSessionFactory() {

try {

return (SessionFactory) new InitialContext()

.lookup("SessionFactory");

} catch (Exception e) {

log.error("Could not locate SessionFactory in JNDI", e);

throw new IllegalStateException(

"Could not locate SessionFactory in JNDI");

}

}


while I need the regular java bean getter setter without JNDI context

private SessionFactory sessionFactory;


public SessionFactory getSessionFactory() {

return sessionFactory;

}


public void setSessionFactory(SessionFactory sessionFactory) {

this.sessionFactory = sessionFactory;

}


Solution: use Eclipse search+replace function, on the GUI, looks like it supports only 1 single line replacement, in fact it isn't, but multiple lines cannot be entered at the search field using the keyboard's Enter key, it requires using copy+paste


No comments:

Post a Comment