Project

General

Profile

Revision 7328ae26

ID7328ae26aee22c45a6a596afafe4b04dbf80d9fa
Parent f1e94220
Child fffc8abd

Added by Andreas Kohlbecker about 3 years ago

ref #6687 using read-only transactions in non editor view presenters

View differences:

src/main/java/eu/etaxonomy/vaadin/mvp/AbstractEditorPresenter.java
12 12
import org.springframework.beans.factory.annotation.Autowired;
13 13
import org.springframework.context.ApplicationEventPublisher;
14 14
import org.springframework.context.event.EventListener;
15
import org.springframework.transaction.TransactionDefinition;
15 16

  
16 17
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
17 18
import eu.etaxonomy.cdm.vaadin.session.ViewScopeConversationHolder;
......
60 61
        return bean;
61 62
    }
62 63

  
64
    @Override
65
    protected TransactionDefinition getTransactionDefinition(){
66
        super.getTransactionDefinition();
67
        if(definition.isReadOnly()){
68
            definition.setReadOnly(false);
69
        }
70
        return definition;
71
    }
72

  
63 73
    /**
64 74
     * Regarding changing the Flush mode see see also {@link ViewScopeConversationHolder}
65 75
     *
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java
10 10
import org.springframework.security.core.context.SecurityContext;
11 11
import org.springframework.security.core.context.SecurityContextHolder;
12 12
import org.springframework.transaction.IllegalTransactionStateException;
13
import org.springframework.transaction.TransactionDefinition;
14
import org.springframework.transaction.support.DefaultTransactionDefinition;
13 15

  
14 16
import com.vaadin.server.ServletPortletHelper;
15 17
import com.vaadin.server.VaadinRequest;
......
59 61
	@Autowired
60 62
	private NavigationManager navigationManager;
61 63

  
62
	@Autowired
63 64
	private ViewScopeConversationHolder conversationHolder;
64 65

  
66
	protected DefaultTransactionDefinition definition = null;
67

  
65 68
    protected boolean conversationBound;
66 69

  
70
	@Autowired
71
	private void setConversationHolder(ViewScopeConversationHolder conversationHolder){
72
	    this.conversationHolder = conversationHolder;
73
	    this.conversationHolder.setDefinition(getTransactionDefinition());
74
	}
75

  
76
	protected TransactionDefinition getTransactionDefinition(){
77
	    if(definition == null){
78
    	    definition = new DefaultTransactionDefinition();
79
    	    definition.setReadOnly(true);
80
	    }
81
	    return definition;
82
	}
83

  
84

  
85

  
67 86

  
68 87
	/**
69 88
	 * @return the repo
src/main/java/eu/etaxonomy/vaadin/ui/view/PopupEditorFactory.java
74 74

  
75 75
    private Method viewInitMethod;
76 76

  
77
    private Field conversationHolderField;
77
    private Method conversationHolderMethod;
78 78

  
79 79
    public PopupEditorFactory(){
80 80
        initFieldsAccess();
......
96 96
            presenterEventBusField = AbstractEditorPresenter.class.getDeclaredField("eventBus");
97 97
            presenterEventBusField.setAccessible(true);
98 98

  
99
            conversationHolderField = AbstractPresenter.class.getDeclaredField("conversationHolder");
100
            conversationHolderField.setAccessible(true);
99
            conversationHolderMethod = AbstractPresenter.class.getDeclaredMethod("setConversationHolder", ViewScopeConversationHolder.class);
100
            conversationHolderMethod.setAccessible(true);
101 101

  
102 102
            viewEventBusField = AbstractView.class.getDeclaredField("eventBus");
103 103
            viewEventBusField.setAccessible(true);
......
148 148
     * @param presenterClass
149 149
     * @param presenter
150 150
     * @throws IllegalAccessException
151
     * @throws InvocationTargetException
152
     * @throws IllegalArgumentException
151 153
     */
152 154
    public <P extends AbstractPresenter> void injectPresenterBeans(
153
            Class<? extends AbstractPresenter<?>> presenterClass, P presenter) throws IllegalAccessException {
155
            Class<? extends AbstractPresenter<?>> presenterClass, P presenter) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
154 156
        presenterRepoField.set(presenter, repo);
155 157
        presenterNavigationManagerField.set(presenter, navigationManager);
156
        conversationHolderField.set(presenter, new ViewScopeConversationHolder(dataSource, sessionFactory, transactionManager));
158
        conversationHolderMethod.invoke(presenter, new ViewScopeConversationHolder(dataSource, sessionFactory, transactionManager));
157 159

  
158 160
        if(AbstractEditorPresenter.class.isAssignableFrom(presenterClass)){
159 161
            presenterEventBusField.set(presenter, eventBus);
src/test/java/eu/etaxonomy/vaadin/mvp/CdmEditorPresenterTest.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.mvp;
10 10

  
11
import java.lang.reflect.InvocationTargetException;
12

  
11 13
import org.apache.log4j.Logger;
12 14
import org.springframework.context.ApplicationEventPublisher;
13 15
import org.unitils.dbunit.annotation.DataSet;
......
46 48

  
47 49
    @DataSet
48 50
    // @Test test setup not jet working :(
49
    public void testSaveReference() throws IllegalAccessException {
51
    public void testSaveReference() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
50 52

  
51 53
        ReferenceEditorPresenter referencePresenter = new ReferenceEditorPresenter();
52 54
        factory.injectPresenterBeans(ReferenceEditorPresenter.class, referencePresenter);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)