Revision 7e488d1b
Added by Andreas Kohlbecker over 6 years ago
- ID 7e488d1bb2f09a0bc4c282c8694b3c1e54bd04ba
- Parent 475ec4ee
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java | ||
---|---|---|
5 | 5 |
import org.apache.log4j.Logger; |
6 | 6 |
import org.hibernate.Session; |
7 | 7 |
import org.hibernate.engine.spi.SessionImplementor; |
8 |
import org.springframework.beans.factory.DisposableBean; |
|
8 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 10 |
import org.springframework.beans.factory.annotation.Qualifier; |
10 | 11 |
import org.springframework.security.core.context.SecurityContext; |
... | ... | |
37 | 38 |
* @param <V> |
38 | 39 |
* type of the view this presenter governs |
39 | 40 |
*/ |
40 |
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable, IntraViewConversationDirector, RequestStartListener { |
|
41 |
public abstract class AbstractPresenter<V extends ApplicationView> implements Serializable, IntraViewConversationDirector, |
|
42 |
RequestStartListener, DisposableBean { |
|
41 | 43 |
|
42 | 44 |
|
43 | 45 |
private static final long serialVersionUID = 5260910510283481832L; |
... | ... | |
272 | 274 |
logger.trace(String.format("%s onViewExit()", _toString())); |
273 | 275 |
handleViewExit(); |
274 | 276 |
// un-register as request start and end listener |
275 |
if(conversationBound){ |
|
276 |
logger.trace(String.format("<<<<< %s onViewExit() unbind()", _toString())); |
|
277 |
conversationHolder.unbind(); |
|
278 |
conversationBound = false; |
|
279 |
} |
|
280 |
logger.trace(String.format("<<<<< %s onViewExit() close()", _toString())); |
|
281 |
conversationHolder.close(); |
|
277 |
cleanupConversation(); |
|
278 |
cleanupRequestListeners(); |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public void destroy() { |
|
283 |
cleanupConversation(); |
|
284 |
cleanupRequestListeners(); |
|
285 |
view = null; |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* |
|
290 |
*/ |
|
291 |
protected void cleanupRequestListeners() { |
|
282 | 292 |
VaadinService service = UI.getCurrent().getSession().getService(); |
283 | 293 |
if(service instanceof CdmSpringVaadinServletService){ |
284 | 294 |
logger.trace(String.format("~~~~~ %s un-register as request listener", _toString())); |
... | ... | |
289 | 299 |
} else { |
290 | 300 |
throw new RuntimeException("Using the CdmSpringVaadinServletService is required for proper per view conversation handling"); |
291 | 301 |
} |
292 |
} |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* |
|
306 |
*/ |
|
307 |
protected void cleanupConversation() { |
|
308 |
if(conversationBound){ |
|
309 |
logger.trace(String.format("<<<<< %s cleanupConversation() unbind()", _toString())); |
|
310 |
conversationHolder.unbind(); // TODO remove, unbind is done on close below |
|
311 |
conversationBound = false; |
|
312 |
} |
|
313 |
logger.trace(String.format("<<<<< %s cleanupConversation() close()", _toString())); |
|
314 |
conversationHolder.close(); |
|
315 |
} |
|
293 | 316 |
|
294 | 317 |
/** |
295 | 318 |
* Extending classes should overwrite this method to react to the event when |
Also available in: Unified diff
ref #7036 disposing resources in mvp beans