Merge pull request #2372 from FOCONIS/pr/bugfix/optimistic_lock_undo_generated_properties

Undo generated properties on OptimisticLockException
This commit is contained in:
Rob Bygrave
2021-09-16 11:17:55 +12:00
committed by GitHub
2 changed files with 35 additions and 1 deletions
@@ -291,6 +291,13 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
}
}
private void onFailedUpdateUndoGeneratedProperties() {
for (BeanProperty prop : beanDescriptor.propertiesGenUpdate()) {
Object oldVal = intercept.getOrigValue(prop.propertyIndex());
prop.setValue(entityBean, oldVal);
}
}
private void onInsertGeneratedProperties() {
for (BeanProperty prop : beanDescriptor.propertiesGenInsert()) {
Object value = prop.generatedProperty().getInsertValue(prop, entityBean, now());
@@ -807,6 +814,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
public void checkRowCount(int rowCount) {
if (rowCount != 1 && rowCount != Statement.SUCCESS_NO_INFO) {
if (ConcurrencyMode.VERSION == concurrencyMode) {
onFailedUpdateUndoGeneratedProperties();
throw new OptimisticLockException("Data has changed. updated row count " + rowCount, null, bean);
} else if (rowCount == 0 && type == Type.UPDATE) {
throw new EntityNotFoundException("No rows updated");