Project

General

Profile

« Previous | Next » 

Revision 2f02081c

Added by Andreas Kohlbecker over 6 years ago

ref #7046 completely removing open session per view implementation and adding init strategies for Name and Typedesignation editor

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
18 18
import com.vaadin.ui.UI;
19 19

  
20 20
import eu.etaxonomy.cdm.api.application.CdmRepository;
21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 21
import eu.etaxonomy.cdm.api.service.DeleteResult;
23 22
import eu.etaxonomy.cdm.api.service.IService;
24 23
import eu.etaxonomy.cdm.model.common.CdmBase;
......
41 40

  
42 41
    private S service;
43 42

  
44
    TransactionStatus txNonConversational = null;
43
    TransactionStatus txStatus = null;
45 44

  
46
    ConversationHolder conversationHolder = null;
47

  
48
    /**
49
     * @return the conversationHolder
50
     */
51
    public ConversationHolder getConversationHolder() {
52
        return conversationHolder;
53
    }
45
//    ConversationHolder conversationHolder = null;
46
//
47
//    /**
48
//     * @return the conversationHolder
49
//     */
50
//    public ConversationHolder getConversationHolder() {
51
//        return conversationHolder;
52
//    }
54 53

  
55 54
    protected DefaultTransactionDefinition txDefinition = null;
56 55

  
......
68 67

  
69 68
    }
70 69

  
71
    /**
72
     * constructor which takes a ConversationHolder. The supplying class of the conversationHolder needs
73
     * to care for <code>bind()</code>, <code>unbind()</code> and <code>close()</code> since the store is
74
     * only responsible for starting and committing of transactions.
75
     *
76
     * @param repo
77
     * @param service
78
     * @param conversationHolder
79
     */
80
    public CdmStore(CdmRepository repo, S service, ConversationHolder conversationHolder) {
81

  
82
        this.repo = repo;
83
        this.service = service;
84
        this.conversationHolder = conversationHolder;
85

  
86
    }
70
//    /**
71
//     * constructor which takes a ConversationHolder. The supplying class of the conversationHolder needs
72
//     * to care for <code>bind()</code>, <code>unbind()</code> and <code>close()</code> since the store is
73
//     * only responsible for starting and committing of transactions.
74
//     *
75
//     * @param repo
76
//     * @param service
77
//     * @param conversationHolder
78
//     */
79
//    public CdmStore(CdmRepository repo, S service, ConversationHolder conversationHolder) {
80
//
81
//        this.repo = repo;
82
//        this.service = service;
83
//        this.conversationHolder = conversationHolder;
84
//
85
//    }
87 86

  
88 87
    /**
89 88
     * @return
90 89
     *
91 90
     */
92 91
    public TransactionStatus startTransaction() {
93
        if(conversationHolder != null && !conversationHolder.isTransactionActive()){
94
            //conversationHolder.setDefinition(getTransactionDefinition());
95
            return conversationHolder.startTransaction();
96
        } else {
92
//        if(conversationHolder != null && !conversationHolder.isTransactionActive()){
93
//            //conversationHolder.setDefinition(getTransactionDefinition());
94
//            return conversationHolder.startTransaction();
95
//        } else {
97 96
            checkExistingTransaction();
98
            txNonConversational = repo.startTransaction();
99
            return txNonConversational;
100
        }
97
            txStatus = repo.startTransaction();
98
            return txStatus;
99
//        }
101 100
    }
102 101

  
103 102
    /**
104 103
     *
105 104
     */
106 105
    protected void checkExistingTransaction() {
107
        if (txNonConversational != null) {
106
        if (txStatus != null) {
108 107
            // @formatter:off
109 108
            // holding the TransactionStatus as state is not good design. we
110 109
            // should change the save operation
......
159 158
    private Session getSession() {
160 159

  
161 160
        Session session;
162
        if(conversationHolder != null){
163
            session = conversationHolder.getSession();
164
        } else {
161
//        if(conversationHolder != null){
162
//            session = conversationHolder.getSession();
163
//        } else {
165 164
            session = repo.getSession();
166
        }
165
//        }
167 166
        logger.trace(this._toString() + ".getSession() - session:" + session.hashCode() + ", persistenceContext: "
168 167
                + ((SessionImplementor) session).getPersistenceContext() + " - " + session.toString());
169 168

  
......
193 192
        Session session = getSession();
194 193
        logger.trace(this._toString() + ".onEditorSaveEvent - session: " + session.hashCode());
195 194

  
196
        if(txNonConversational == null || (conversationHolder != null && !conversationHolder.isTransactionActive())){
195
        if(txStatus == null
196
//                || (conversationHolder != null && !conversationHolder.isTransactionActive())
197
                ){
197 198
            // no running transaction, start one ...
198 199
            startTransaction();
199 200
        }
......
259 260
            Notification notification = new Notification(notificationTitle, messageBody.toString(),
260 261
                    com.vaadin.ui.Notification.Type.ERROR_MESSAGE, true);
261 262
            notification.show(UI.getCurrent().getPage());
262
            txNonConversational = null;
263
            txStatus = null;
263 264
        }
264 265
        return null;
265 266
    }
......
267 268

  
268 269
    protected void commitTransction() {
269 270

  
270
        if(conversationHolder != null){
271
            conversationHolder.commit();
272
        } else {
273
            repo.commitTransaction(txNonConversational);
274
            txNonConversational = null;
275
        }
271
//        if(conversationHolder != null){
272
//            conversationHolder.commit();
273
//        } else {
274
            repo.commitTransaction(txStatus);
275
            txStatus = null;
276
//        }
276 277
    }
277 278

  
278 279
    /**
279 280
     * @param entityId
280 281
     */
281 282
    public T loadBean(int entityId) {
282
        conversationHolder.startTransaction();
283
//        conversationHolder.startTransaction();
283 284
        return service.find(entityId);
284 285
    }
285 286

  

Also available in: Unified diff