Class DelayedAddAndDeleteAggregateSnapshotDelegate
java.lang.Object
dk.cloudcreate.essentials.components.eventsourced.aggregates.snapshot.DelayedAddAndDeleteAggregateSnapshotDelegate
- All Implemented Interfaces:
AggregateSnapshotRepository
public class DelayedAddAndDeleteAggregateSnapshotDelegate
extends Object
implements AggregateSnapshotRepository
Delegating
This ensures that expensive update/clean-up for aggregate snapshots in the database don't affect aggregate persistence performance.
AggregateSnapshotRepository which directly delegates all operations to the provided delegateRepository,
except for AggregateSnapshotRepository.aggregateUpdated(Object, AggregateEventStream), AggregateSnapshotRepository.deleteSnapshots(AggregateType, Object, Class, List), which are performed asynchronously in the background.This ensures that expensive update/clean-up for aggregate snapshots in the database don't affect aggregate persistence performance.
-
Constructor Summary
ConstructorsConstructorDescriptionDelayedAddAndDeleteAggregateSnapshotDelegate(AggregateSnapshotRepository delegateRepository) -
Method Summary
Modifier and TypeMethodDescription<ID,AGGREGATE_IMPL_TYPE>
voidaggregateUpdated(AGGREGATE_IMPL_TYPE aggregate, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateEventStream<ID> persistedEvents) Callback from an Aggregate Repository to notify that the aggregate has been updatedstatic AggregateSnapshotRepositorydelegateTo(AggregateSnapshotRepository delegateRepository) <AGGREGATE_IMPL_TYPE>
voiddeleteAllSnapshots(Class<AGGREGATE_IMPL_TYPE> ofAggregateImplementationType) Delete all snapshots for the given aggregate implementation type<ID,AGGREGATE_IMPL_TYPE>
voiddeleteSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType) Delete all snapshots for the given aggregate instance with the given aggregate implementation type<ID,AGGREGATE_IMPL_TYPE>
voiddeleteSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType, List<dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder> snapshotEventOrdersToDelete) Delete all snapshots with a givenAggregateSnapshot.eventOrderOfLastIncludedEventfor the given aggregate instance, with the given aggregate implementation type<ID,AGGREGATE_IMPL_TYPE>
List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType, boolean includeSnapshotPayload) Load allAggregateSnapshot's related to the given aggregate instance<ID,AGGREGATE_IMPL_TYPE>
Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder withLastIncludedEventOrderLessThanOrEqualTo, Class<AGGREGATE_IMPL_TYPE> aggregateImplType) <ID,AGGREGATE_IMPL_TYPE>
Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType)
-
Constructor Details
-
DelayedAddAndDeleteAggregateSnapshotDelegate
-
-
Method Details
-
delegateTo
public static AggregateSnapshotRepository delegateTo(AggregateSnapshotRepository delegateRepository) -
loadSnapshot
public <ID,AGGREGATE_IMPL_TYPE> Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType) - Specified by:
loadSnapshotin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregateType- the aggregate type (determining the aggregate's event stream name)aggregateId- the identifier for the aggregate instanceaggregateImplType- the concrete aggregate implementation type- Returns:
- the aggregate snapshot wrapped in an
Optionalif a snapshot was found, otherwiseOptional.empty()
-
loadSnapshot
public <ID,AGGREGATE_IMPL_TYPE> Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder withLastIncludedEventOrderLessThanOrEqualTo, Class<AGGREGATE_IMPL_TYPE> aggregateImplType) - Specified by:
loadSnapshotin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregateType- the aggregate type (determining the aggregate's event stream name)aggregateId- the identifier for the aggregate instancewithLastIncludedEventOrderLessThanOrEqualTo- the snapshot returned must haveAggregateSnapshot.eventOrderOfLastIncludedEventthat is less than or equal to this valueaggregateImplType- the concrete aggregate implementation type- Returns:
- the aggregate snapshot wrapped in an
Optionalif a snapshot was found, otherwiseOptional.empty()
-
loadAllSnapshots
public <ID,AGGREGATE_IMPL_TYPE> List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType, boolean includeSnapshotPayload) Description copied from interface:AggregateSnapshotRepositoryLoad allAggregateSnapshot's related to the given aggregate instance- Specified by:
loadAllSnapshotsin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregateType- the aggregate type (determining the aggregate's event stream name)aggregateId- the identifier for the aggregate instanceaggregateImplType- the concrete aggregate implementation typeincludeSnapshotPayload- should theAggregateSnapshot.aggregateSnapshotbe loaded?- Returns:
- list of all
AggregateSnapshot's in ascendingAggregateSnapshot.eventOrderOfLastIncludedEventorder (the oldest snapshot first) related to the given aggregate instance
-
aggregateUpdated
public <ID,AGGREGATE_IMPL_TYPE> void aggregateUpdated(AGGREGATE_IMPL_TYPE aggregate, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateEventStream<ID> persistedEvents) Description copied from interface:AggregateSnapshotRepositoryCallback from an Aggregate Repository to notify that the aggregate has been updated- Specified by:
aggregateUpdatedin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregate- the aggregate instance after the changes (in the form of events) has been marked as committed within the aggregatepersistedEvents- the aggregate changes (in the form of events) after they've been persisted
-
deleteAllSnapshots
public <AGGREGATE_IMPL_TYPE> void deleteAllSnapshots(Class<AGGREGATE_IMPL_TYPE> ofAggregateImplementationType) Description copied from interface:AggregateSnapshotRepositoryDelete all snapshots for the given aggregate implementation type- Specified by:
deleteAllSnapshotsin interfaceAggregateSnapshotRepository- Type Parameters:
AGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
ofAggregateImplementationType- the concrete aggregate implementation type that we want to delete all snapshots for
-
deleteSnapshots
public <ID,AGGREGATE_IMPL_TYPE> void deleteSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType) Description copied from interface:AggregateSnapshotRepositoryDelete all snapshots for the given aggregate instance with the given aggregate implementation type- Specified by:
deleteSnapshotsin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregateType- the aggregate type (determining the aggregate's event stream name)aggregateId- the id of the aggregate that we want to delete all snapshots forwithAggregateImplementationType- the concrete aggregate implementation type that we want to delete all snapshots for
-
deleteSnapshots
public <ID,AGGREGATE_IMPL_TYPE> void deleteSnapshots(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType, List<dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.EventOrder> snapshotEventOrdersToDelete) Description copied from interface:AggregateSnapshotRepositoryDelete all snapshots with a givenAggregateSnapshot.eventOrderOfLastIncludedEventfor the given aggregate instance, with the given aggregate implementation type- Specified by:
deleteSnapshotsin interfaceAggregateSnapshotRepository- Type Parameters:
ID- the aggregate ID typeAGGREGATE_IMPL_TYPE- the concrete aggregate implementation type- Parameters:
aggregateType- the aggregate type (determining the aggregate's event stream name)aggregateId- the id of the aggregate that we want to delete all snapshots forwithAggregateImplementationType- the concrete aggregate implementation type that we want to delete all snapshots forsnapshotEventOrdersToDelete- The list ofAggregateSnapshot.eventOrderOfLastIncludedEvent's that should be deleted
-