/** * Ensure that conflicts have been resolved (via ({@link #detectConflicts}). If not, an instance of {@link * ConflictingModificationException} (or subtype) should be thrown if there have been any unseen changes. */ public void ensureConflictsResolved() { if (!conflictsResolved) { throw new ConflictingAggregateVersionException(aggregateIdentifier, expectedVersion, actualVersion); } }
/** * Checks the aggregate for concurrent changes. Throws a * {@link ConflictingModificationException} when conflicting changes have been * detected. * <p> * This implementation throws a {@link ConflictingAggregateVersionException} if the expected version is not null * and the version number of the aggregate does not match the expected version * * @param aggregate The loaded aggregate * @param expectedVersion The expected version of the aggregate * @throws ConflictingModificationException when conflicting changes have been detected * @throws ConflictingAggregateVersionException the expected version is not {@code null} * and the version number of the aggregate does not match the expected * version */ protected void validateOnLoad(Aggregate<T> aggregate, Long expectedVersion) { if (expectedVersion != null && aggregate.version() != null && !expectedVersion.equals(aggregate.version())) { throw new ConflictingAggregateVersionException(aggregate.identifierAsString(), expectedVersion, aggregate.version()); } }
@Override public Aggregate<T> load(String aggregateIdentifier, Long expectedVersion) { ((CommandHandlingEntry) CurrentUnitOfWork.get()).registerAggregateIdentifier(aggregateIdentifier); Aggregate<T> aggregate = load(aggregateIdentifier); if (expectedVersion != null && aggregate.version() > expectedVersion) { throw new ConflictingAggregateVersionException(aggregateIdentifier, expectedVersion, aggregate.version()); } return aggregate; }