You could create an abstract implementation of EventListener with an abstract execute( ) method (HibernateEventListener). The onWhatever( ) method would open a session and transaction, call perform( ), and then commit/rollback the transaction and close the session, as in the traditional interceptor pattern. All EventListener implementations that deal with Hibernate would extend HibernateEventListener and implement the perform( ) method. Inside the perform( ) method you can instantiate DAOs and perform your business, persistence, and view update logic and trust the underlying onWhatever( ) method(s) to handle the Hibernate concerns.
I've never done Swing development before, but it seems like that would work to approximate a web architecture interceptor pattern.
- Jesse
|