|
|
|
|
@ -118,30 +118,37 @@ class DefaultJdbcInterpreter implements Interpreter {
@@ -118,30 +118,37 @@ class DefaultJdbcInterpreter implements Interpreter {
|
|
|
|
|
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(update.getEntityType()); |
|
|
|
|
|
|
|
|
|
if (persistentEntity.hasVersionProperty()) { |
|
|
|
|
updateWithVersion(update, persistentEntity); |
|
|
|
|
} else { |
|
|
|
|
updateWithoutVersion(update); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private <T> void updateWithoutVersion(UpdateRoot<T> update) { |
|
|
|
|
|
|
|
|
|
if (!accessStrategy.update(update.getEntity(), update.getEntityType())) { |
|
|
|
|
|
|
|
|
|
throw new IncorrectUpdateSemanticsDataAccessException( |
|
|
|
|
String.format(UPDATE_FAILED, update.getEntity(), getIdFrom(update))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If the root aggregate has a version property, increment it.
|
|
|
|
|
Number previousVersion = RelationalEntityVersionUtils.getVersionNumberFromEntity(update.getEntity(), |
|
|
|
|
persistentEntity, converter); |
|
|
|
|
private <T> void updateWithVersion(UpdateRoot<T> update, RelationalPersistentEntity<T> persistentEntity) { |
|
|
|
|
|
|
|
|
|
Assert.notNull(previousVersion, "The root aggregate cannot be updated because the version property is null."); |
|
|
|
|
// If the root aggregate has a version property, increment it.
|
|
|
|
|
Number previousVersion = RelationalEntityVersionUtils.getVersionNumberFromEntity(update.getEntity(), |
|
|
|
|
persistentEntity, converter); |
|
|
|
|
|
|
|
|
|
T rootEntity = RelationalEntityVersionUtils.setVersionNumberOnEntity(update.getEntity(), |
|
|
|
|
previousVersion.longValue() + 1, persistentEntity, converter); |
|
|
|
|
Assert.notNull(previousVersion, "The root aggregate cannot be updated because the version property is null."); |
|
|
|
|
|
|
|
|
|
if (accessStrategy.updateWithVersion(rootEntity, update.getEntityType(), previousVersion)) { |
|
|
|
|
// Successful update, set the in-memory version on the action.
|
|
|
|
|
update.setNextVersion(previousVersion); |
|
|
|
|
} else { |
|
|
|
|
throw new OptimisticLockingFailureException( |
|
|
|
|
String.format(UPDATE_FAILED_OPTIMISTIC_LOCKING, update.getEntity())); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
update.setNextVersion(previousVersion.longValue() + 1); |
|
|
|
|
T rootEntity = RelationalEntityVersionUtils.setVersionNumberOnEntity(update.getEntity(), update.getNextVersion(), |
|
|
|
|
persistentEntity, converter); |
|
|
|
|
|
|
|
|
|
if (!accessStrategy.update(update.getEntity(), update.getEntityType())) { |
|
|
|
|
if (!accessStrategy.updateWithVersion(rootEntity, update.getEntityType(), previousVersion)) { |
|
|
|
|
|
|
|
|
|
throw new IncorrectUpdateSemanticsDataAccessException( |
|
|
|
|
String.format(UPDATE_FAILED, update.getEntity(), getIdFrom(update))); |
|
|
|
|
} |
|
|
|
|
throw new OptimisticLockingFailureException( |
|
|
|
|
String.format(UPDATE_FAILED_OPTIMISTIC_LOCKING, update.getEntity())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|