Class PostgresqlAggregateSnapshotRepository
java.lang.Object
dk.cloudcreate.essentials.components.eventsourced.aggregates.snapshot.PostgresqlAggregateSnapshotRepository
- All Implemented Interfaces:
AggregateSnapshotRepository
public class PostgresqlAggregateSnapshotRepository
extends Object
implements AggregateSnapshotRepository
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, JSONEventSerializer jsonSerializer) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepositorythat will persistAggregateSnapshot's into theDEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAMEtable
Adding newAggregateSnapshot's when it's behind by 10 events AND Deleting All HistoricAggregateSnapshot'sPostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepositorythat will persistAggregateSnapshot's into theDEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAMEtablePostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, JSONEventSerializer jsonSerializer) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepository
Adding newAggregateSnapshot's when it's behind by 10 events AND Deleting All HistoricAggregateSnapshot'sPostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepositoryPostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, Optional<String> snapshotTableName, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepository -
Method Summary
Modifier and TypeMethodDescription<ID,AGGREGATE_IMPL_TYPE>
voidaggregateUpdated(AGGREGATE_IMPL_TYPE aggregate, AggregateEventStream<ID> persistedEvents) Callback from an Aggregate Repository to notify that the aggregate has been updated<AGGREGATE_IMPL_TYPE>
voiddeleteAllSnapshots(Class<AGGREGATE_IMPL_TYPE> ofAggregateImplementationType) Delete all snapshots for the given aggregate implementation type<ID,AGGREGATE_IMPL_TYPE>
voiddeleteSnapshots(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(AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType, List<EventOrder> snapshotEventOrdersToDelete) Delete all snapshots with a givenAggregateSnapshot.eventOrderOfLastIncludedEventfor the given aggregate instance, with the given aggregate implementation typeprotected Optional<EventOrder>findMostRecentLastIncludedEventOrderFor(String serializedAggregateId, String aggregateImplType, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork uow) <ID,AGGREGATE_IMPL_TYPE>
List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType, boolean includeSnapshotPayload) Load allAggregateSnapshot's related to the given aggregate instanceprotected <ID,AGGREGATE_IMPL_TYPE>
List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(String serializedAggregateId, String aggregateImplType, boolean includeSnapshotPayload, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork uow) <ID,AGGREGATE_IMPL_TYPE>
Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(AggregateType aggregateType, ID aggregateId, EventOrder withLastIncludedEventOrderLessThanOrEqualTo, Class<AGGREGATE_IMPL_TYPE> aggregateImplType) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dk.cloudcreate.essentials.components.eventsourced.aggregates.snapshot.AggregateSnapshotRepository
loadSnapshot
-
Field Details
-
DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME
- See Also:
-
-
Constructor Details
-
PostgresqlAggregateSnapshotRepository
public PostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, JSONEventSerializer jsonSerializer) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepositorythat will persistAggregateSnapshot's into theDEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAMEtable
Adding newAggregateSnapshot's when it's behind by 10 events AND Deleting All HistoricAggregateSnapshot's- Parameters:
eventStore- the event store responsible for persisting aggregate event streamunitOfWorkFactory- unit of work factory for controlling transactionsjsonSerializer- JSON serializer that will be used to serialize Aggregate instances
-
PostgresqlAggregateSnapshotRepository
public PostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, JSONEventSerializer jsonSerializer) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepository
Adding newAggregateSnapshot's when it's behind by 10 events AND Deleting All HistoricAggregateSnapshot's- Parameters:
eventStore- the event store responsible for persisting aggregate event streamunitOfWorkFactory- unit of work factory for controlling transactionssnapshotTableName- the name of the table whereAggregateSnapshot's will be storedjsonSerializer- JSON serializer that will be used to serialize Aggregate instances
-
PostgresqlAggregateSnapshotRepository
public PostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepository- Parameters:
eventStore- the event store responsible for persisting aggregate event streamunitOfWorkFactory- unit of work factory for controlling transactionssnapshotTableName- the name of the table whereAggregateSnapshot's will be storedjsonSerializer- JSON serializer that will be used to serialize Aggregate instancesaddNewSnapshotStrategy- the strategy determining when a newAggregateSnapshotwill be storedsnapshotDeletionStrategy- the strategy determining when an existingAggregateSnapshotwill be deleted
-
PostgresqlAggregateSnapshotRepository
public PostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepositorythat will persistAggregateSnapshot's into theDEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAMEtable- Parameters:
eventStore- the event store responsible for persisting aggregate event streamunitOfWorkFactory- unit of work factory for controlling transactionsjsonSerializer- JSON serializer that will be used to serialize Aggregate instancesaddNewSnapshotStrategy- the strategy determining when a newAggregateSnapshotwill be storedsnapshotDeletionStrategy- the strategy determining when an existingAggregateSnapshotwill be deleted
-
PostgresqlAggregateSnapshotRepository
public PostgresqlAggregateSnapshotRepository(ConfigurableEventStore<? extends AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, Optional<String> snapshotTableName, JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy) Create a new durable Postgresql version of thePostgresqlAggregateSnapshotRepository- Parameters:
eventStore- the event store responsible for persisting aggregate event streamunitOfWorkFactory- unit of work factory for controlling transactionssnapshotTableName- Optional name of the table whereAggregateSnapshot's will be stored - ifOptional.empty()thenAggregateSnapshot's will persisted into theDEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAMEtablejsonSerializer- JSON serializer that will be used to serialize Aggregate instancesaddNewSnapshotStrategy- the strategy determining when a newAggregateSnapshotwill be storedsnapshotDeletionStrategy- the strategy determining when an existingAggregateSnapshotwill be deleted
-
-
Method Details
-
loadSnapshot
public <ID,AGGREGATE_IMPL_TYPE> Optional<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadSnapshot(AggregateType aggregateType, ID aggregateId, 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()
-
aggregateUpdated
public <ID,AGGREGATE_IMPL_TYPE> void aggregateUpdated(AGGREGATE_IMPL_TYPE aggregate, 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
-
findMostRecentLastIncludedEventOrderFor
protected Optional<EventOrder> findMostRecentLastIncludedEventOrderFor(String serializedAggregateId, String aggregateImplType, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork uow) -
loadAllSnapshots
public <ID,AGGREGATE_IMPL_TYPE> List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(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
-
loadAllSnapshots
protected <ID,AGGREGATE_IMPL_TYPE> List<AggregateSnapshot<ID,AGGREGATE_IMPL_TYPE>> loadAllSnapshots(String serializedAggregateId, String aggregateImplType, boolean includeSnapshotPayload, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork uow) -
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(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(AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> withAggregateImplementationType, List<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
-