persistence module doc. update

This commit is contained in:
zemo
2020-08-16 15:41:52 +02:00
parent feb89d108e
commit 98748f9aa3
5 changed files with 88 additions and 72 deletions

View File

@@ -6,6 +6,11 @@ import reactor.core.publisher.Mono;
import java.util.function.Function;
/**
* Contract definition for Aggregate wrapper
* @param <A> - Aggregate type
* @param <C> - Command type
*/
public interface AggregateActor<A, C extends Command> {
<S> Mono<S> getState(Function<A, S> stateFactory);

View File

@@ -4,6 +4,12 @@ import com.mz.reactor.ddd.common.api.command.Command;
import com.mz.reactor.ddd.common.api.event.DomainEvent;
import reactor.core.publisher.Mono;
/**
* Aggregate facade contract for operations related with aggregate.
* @param <A> - Aggregate type
* @param <C> - Command type
* @param <S> - State type, representing a state of aggregate
*/
public interface AggregateFacade<A, C extends Command,S> {
Mono<S> execute(C command, String aggregateID);

View File

@@ -1,4 +0,0 @@
package com.mz.reactor.ddd.reactorddd.persistance.aggregate;
public interface AggregateFactory {
}

View File

@@ -5,6 +5,12 @@ import com.mz.reactor.ddd.common.api.command.CommandResult;
import com.mz.reactor.ddd.common.api.valueobject.Id;
import reactor.core.publisher.Mono;
/**
* {@link AggregateRepository} contract definition.
* @param <A> - Aggregate type
* @param <C> - Command type
* @param <S> - State type, representing a state of aggregate
*/
public interface AggregateRepository<A, C extends Command,S> {
Mono<CommandResult> execute(C cmd, Id aggregateId);

View File

@@ -78,7 +78,9 @@ public class AggregateRepositoryImpl<A, C extends Command, S> implements Aggrega
eventHandler,
aggregateFactory,
Optional.ofNullable(eventSource.get().get(id)).orElseGet(List::of),
this::persistAll));
this::persistAll
)
);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -100,7 +102,8 @@ public class AggregateRepositoryImpl<A, C extends Command, S> implements Aggrega
return Mono.just(id)
.flatMap(i -> Optional.ofNullable(cache.getIfPresent(i))
.map(a -> a.getState(this.stateFactory))
.orElseGet(Mono::empty));
.orElseGet(Mono::empty)
);
}
}