/** * @throws AggregateNotFoundException if aggregate with given id cannot be found * @throws RuntimeException any exception thrown by implementing classes */ @Override public A load(String aggregateIdentifier, Long expectedVersion) { UnitOfWork<?> uow = CurrentUnitOfWork.get(); Map<String, A> aggregates = managedAggregates(uow); A aggregate = aggregates.computeIfAbsent(aggregateIdentifier, s -> doLoad(aggregateIdentifier, expectedVersion)); uow.onRollback(u -> aggregates.remove(aggregateIdentifier)); validateOnLoad(aggregate, expectedVersion); prepareForCommit(aggregate); return aggregate; }