Project

General

Profile

« Previous | Next » 

Revision 51886e05

Added by Andreas Kohlbecker over 5 years ago

ref #7559 removing commented code which also includes old conversationHolder stuff

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmStore.java
44 44

  
45 45
    TransactionStatus txStatus = null;
46 46

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

  
56 47
    protected DefaultTransactionDefinition txDefinition = null;
57 48

  
58 49
    /**
......
63 54
     *            a NullPointerException in this case.
64 55
     */
65 56
    public CdmStore(CdmRepository repo, S service) {
66

  
67 57
        this.repo = repo;
68 58
        this.service = service;
69

  
70 59
    }
71 60

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

  
89 62
    /**
90 63
     * @return
91 64
     *
92 65
     */
93 66
    public TransactionStatus startTransaction() {
94
//        if(conversationHolder != null && !conversationHolder.isTransactionActive()){
95
//            //conversationHolder.setDefinition(getTransactionDefinition());
96
//            return conversationHolder.startTransaction();
97
//        } else {
98
            checkExistingTransaction();
99
            txStatus = repo.startTransaction();
100
            return txStatus;
101
//        }
67
        checkExistingTransaction();
68
        txStatus = repo.startTransaction();
69
        return txStatus;
102 70
    }
103 71

  
104 72
    /**
......
135 103

  
136 104
        Session session = getSession();
137 105

  
138
        // session.clear();
139 106
        if (session.contains(bean)) {
140 107
            // evict bean before merge to avoid duplicate beans in same session
141 108
            logger.trace(this._toString() + ".mergedBean() - evict " + bean.toString());
......
143 110
        }
144 111

  
145 112
        logger.trace(this._toString() + ".mergedBean() - doing merge of" + bean.toString());
146
        // to avoid merge problems as described in
147
        // https://dev.e-taxonomy.eu/redmine/issues/6687
148
        // we are set the hibernate property
149
        // hibernate.event.merge.entity_copy_observer=allow
113
        // to avoid merge problems as described in https://dev.e-taxonomy.eu/redmine/issues/6687
114
        // we are set the hibernate property hibernate.event.merge.entity_copy_observer=allow
150 115
        @SuppressWarnings("unchecked")
151 116
        T mergedBean = (T) session.merge(bean);
152 117
        logger.trace(this._toString() + ".mergedBean() - bean after merge " + bean.toString());
......
159 124
     */
160 125
    private Session getSession() {
161 126

  
162
        Session session;
163
//        if(conversationHolder != null){
164
//            session = conversationHolder.getSession();
165
//        } else {
166
            session = repo.getSession();
167
//        }
127
        Session session = repo.getSession();
128

  
168 129
        logger.trace(this._toString() + ".getSession() - session:" + session.hashCode() + ", persistenceContext: "
169 130
                + ((SessionImplementor) session).getPersistenceContext() + " - " + session.toString());
170 131

  
......
195 156
        try {
196 157
            logger.trace(this._toString() + ".onEditorSaveEvent - session: " + session.hashCode());
197 158

  
198
            if(txStatus == null
199
    //                || (conversationHolder != null && !conversationHolder.isTransactionActive())
200
                    ){
159
            if(txStatus == null){
201 160
                // no running transaction, start one ...
202 161
                startTransaction();
203 162
            }
204 163

  
205 164
            logger.trace(this._toString() + ".onEditorSaveEvent - merging bean into session");
206 165
            // merge the changes into the session, ...
207

  
208 166
            T mergedBean = mergedBean(bean);
209

  
210
            // NOTE: saveOrUpdate is really needed here even if we to a merge before
211
            // repo.getCommonService().saveOrUpdate(mergedBean);
212 167
            session.flush();
213 168
            commitTransaction();
214 169
            return new EntityChangeEvent(mergedBean, changeEventType, view);
......
216 171
            session.clear(); // #7559
217 172
            throw e;
218 173
        }
219
//        finally {
220
//            try {
221
////                session.close(); // #7559
222
//                session.clear();
223
//            } catch (HibernateException e2) {
224
//                /* IGNORE HERE */
225
//            }
226
//        }
227

  
228 174
    }
229 175

  
230 176
    /**
......
253 199
            session.clear(); // #7559
254 200
            throw e;
255 201
        }
256
//        finally {
257
//            try {
258
////                session.close(); // #7559
259
//                session.clear(); // #7559
260
//            } catch (HibernateException e2) {
261
//                /* IGNORE HERE */
262
//            }
263
//        }
264 202
        return null;
265 203
    }
266 204

  
......
304 242

  
305 243

  
306 244
    protected void commitTransaction() {
307

  
308
//        if(conversationHolder != null){
309
//            conversationHolder.commit();
310
//        } else {
311
            repo.commitTransaction(txStatus);
312
            txStatus = null;
313
//        }
245
        repo.commitTransaction(txStatus);
246
        txStatus = null;
314 247
    }
315 248

  
316 249
    /**
317 250
     * @param entityId
318 251
     */
319 252
    public T loadBean(int entityId) {
320
//        conversationHolder.startTransaction();
321 253
        return service.find(entityId);
322 254
    }
323 255

  

Also available in: Unified diff