1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.session;
|
10
|
|
11
|
import java.io.Serializable;
|
12
|
|
13
|
import javax.sql.DataSource;
|
14
|
|
15
|
import org.hibernate.FlushMode;
|
16
|
import org.hibernate.SessionFactory;
|
17
|
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
|
18
|
import org.springframework.transaction.PlatformTransactionManager;
|
19
|
import org.springframework.transaction.TransactionDefinition;
|
20
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
21
|
|
22
|
import com.vaadin.spring.annotation.SpringComponent;
|
23
|
import com.vaadin.spring.annotation.ViewScope;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
26
|
import eu.etaxonomy.vaadin.mvp.AbstractEditorPresenter;
|
27
|
|
28
|
/**
|
29
|
* The ViewScopeConversationHolder allows to span conversations over all request threads
|
30
|
* that are involved in the creation, interaction and ending of a View.
|
31
|
*
|
32
|
* <p><b>NOTE</b>: Hibernate sessions created in the conversation created by this holder
|
33
|
* will not fluish automatically. The flush mode is initially
|
34
|
* set to {@code FlushMode.MANUAL}. It assumes to be used
|
35
|
* in combination with service layer transactions that care for the flushing: The
|
36
|
* active transaction manager will temporarily change the flush mode to
|
37
|
* {@code FlushMode.AUTO} during a read-write transaction, with the flush
|
38
|
* mode reset to {@code FlushMode.NEVER} at the end of each transaction.
|
39
|
* This behavior is implemented consistently in the {@link {@link AbstractEditorPresenter} methods
|
40
|
* {@link AbstractEditorPresenter#onEditorPreSaveEvent(eu.etaxonomy.vaadin.mvp.event.EditorPreSaveEvent) onEditorPreSaveEvent},
|
41
|
* {@link AbstractEditorPresenter#onEditorSaveEvent(eu.etaxonomy.vaadin.mvp.event.EditorSaveEvent) onEditorSaveEvent} and
|
42
|
* {@link AbstractEditorPresenter#onEditorDeleteEvent(eu.etaxonomy.vaadin.mvp.event.EditorDeleteEvent) onEditorDeleteEvent}
|
43
|
* In this whole strategy this class follows the ideas of the {@link OpenSessionInViewFilter}.
|
44
|
*
|
45
|
* @author a.kohlbecker
|
46
|
* @since Jun 30, 2017
|
47
|
*
|
48
|
*/
|
49
|
@SpringComponent
|
50
|
@ViewScope
|
51
|
public class ViewScopeConversationHolder extends ConversationHolder implements Serializable {
|
52
|
|
53
|
|
54
|
private static final long serialVersionUID = 1001768184000981106L;
|
55
|
|
56
|
/**
|
57
|
*
|
58
|
*/
|
59
|
public ViewScopeConversationHolder() {
|
60
|
super();
|
61
|
applyDefaultSettings();
|
62
|
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* @param dataSource
|
67
|
* @param sessionFactory
|
68
|
* @param transactionManager
|
69
|
*/
|
70
|
public ViewScopeConversationHolder(DataSource dataSource, SessionFactory sessionFactory,
|
71
|
PlatformTransactionManager transactionManager) {
|
72
|
super(dataSource, sessionFactory, transactionManager, false);
|
73
|
applyDefaultSettings();
|
74
|
}
|
75
|
|
76
|
private void applyDefaultSettings(){
|
77
|
|
78
|
setDefaultFlushMode(FlushMode.MANUAL);
|
79
|
TransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED);
|
80
|
setDefinition(definition );
|
81
|
}
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
}
|