Revision 99583d95
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/cdm/service/CdmStore.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
private S service; |
43 | 43 |
|
44 |
TransactionStatus txStatus = null; |
|
44 |
// TransactionStatus txStatus = null;
|
|
45 | 45 |
|
46 | 46 |
protected DefaultTransactionDefinition txDefinition = null; |
47 | 47 |
|
... | ... | |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
|
61 |
/** |
|
62 |
* @return |
|
63 |
* |
|
64 |
*/ |
|
65 |
public TransactionStatus startTransaction() { |
|
66 |
checkExistingTransaction(); |
|
67 |
txStatus = repo.startTransaction(); |
|
68 |
return txStatus; |
|
69 |
} |
|
61 |
// /**
|
|
62 |
// * @return
|
|
63 |
// *
|
|
64 |
// */
|
|
65 |
// public TransactionStatus startTransaction() {
|
|
66 |
// checkExistingTransaction();
|
|
67 |
// txStatus = repo.startTransaction();
|
|
68 |
// return txStatus;
|
|
69 |
// }
|
|
70 | 70 |
|
71 |
/** |
|
72 |
* |
|
73 |
*/ |
|
74 |
protected void checkExistingTransaction() { |
|
75 |
if (txStatus != null) { |
|
76 |
// @formatter:off |
|
77 |
// holding the TransactionStatus as state is not good design. we |
|
78 |
// should change the save operation |
|
79 |
// in the EditorView so that the presenter can process the save in |
|
80 |
// one method call. |
|
81 |
// Problems: |
|
82 |
// 1. the fieldGroup needs a open session and read transaction |
|
83 |
// during the validation, otherwise |
|
84 |
// LazyInitialisationExceptions occur. |
|
85 |
// 2. passing the TransactionState to the view also doesn't seem |
|
86 |
// like a good idea. |
|
87 |
// @formatter:on |
|
88 |
throw new RuntimeException("Opening a second transaction in the same" + this.getClass().getSimpleName() + " is not supported"); |
|
89 |
} |
|
90 |
} |
|
91 | 71 |
|
92 | 72 |
/** |
93 | 73 |
* If the bean is contained in the session it is being updated by doing an |
... | ... | |
154 | 134 |
Session session = getSession(); |
155 | 135 |
try { |
156 | 136 |
logger.trace(this._toString() + ".onEditorSaveEvent - session: " + session.hashCode()); |
157 |
|
|
158 |
if(txStatus == null){ |
|
159 |
// no running transaction, start one ... |
|
160 |
startTransaction(); |
|
161 |
} |
|
162 |
|
|
163 |
logger.trace(this._toString() + ".onEditorSaveEvent - merging bean into session"); |
|
164 |
// merge the changes into the session, ... |
|
165 |
T mergedBean = mergedBean(bean); |
|
166 |
session.flush(); |
|
167 |
commitTransaction(); |
|
137 |
TransactionStatus txStatus = repo.startTransaction(); |
|
138 |
try { |
|
139 |
logger.trace(this._toString() + ".onEditorSaveEvent - merging bean into session"); |
|
140 |
// merge the changes into the session, ... |
|
141 |
T mergedBean = mergedBean(bean); |
|
142 |
session.flush(); |
|
143 |
repo.commitTransaction(txStatus); |
|
168 | 144 |
return new EntityChangeEvent(mergedBean, changeEventType, view); |
145 |
} catch(Exception e){ |
|
146 |
repo.getTransactionManager().rollback(txStatus); |
|
147 |
throw e; |
|
148 |
} |
|
169 | 149 |
} finally { |
170 | 150 |
session.clear(); // #7559 |
171 | 151 |
} |
... | ... | |
181 | 161 |
logger.trace(this._toString() + ".onEditorPreSaveEvent - starting transaction"); |
182 | 162 |
Session session = getSession(); |
183 | 163 |
try { |
184 |
startTransaction(); |
|
185 | 164 |
logger.trace(this._toString() + ".deleteBean - deleting" + bean.toString()); |
186 | 165 |
DeleteResult result = service.delete(bean); |
187 | 166 |
if (result.isOk()) { |
188 | 167 |
session.flush(); |
189 |
commitTransaction(); |
|
190 |
logger.trace(this._toString() + ".deleteBean - transaction comitted"); |
|
191 | 168 |
return new EntityChangeEvent(bean, Type.REMOVED, view); |
192 | 169 |
} else { |
193 | 170 |
handleDeleteresultInError(result, session); |
194 |
txStatus = null; |
|
195 | 171 |
} |
196 | 172 |
} finally { |
197 | 173 |
session.clear(); // #7559 |
... | ... | |
240 | 216 |
notification.show(UI.getCurrent().getPage()); |
241 | 217 |
} |
242 | 218 |
|
243 |
|
|
244 |
protected void commitTransaction() { |
|
245 |
repo.commitTransaction(txStatus); |
|
246 |
txStatus = null; |
|
247 |
} |
|
248 |
|
|
249 | 219 |
/** |
250 | 220 |
* @param entityId |
251 | 221 |
*/ |
Also available in: Unified diff
ref #8132 proper transaction rollback in CdmStore