Class PostgresqlAggregateSnapshotRepository

    • Constructor Summary

      Constructors 
      Constructor Description
      PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer)
      Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository that will persist AggregateSnapshot's into the DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME table
      Adding new AggregateSnapshot's when it's behind by 10 events AND Deleting All Historic AggregateSnapshot's
      PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
      Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository that will persist AggregateSnapshot's into the DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME table
      PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer)
      Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
      Adding new AggregateSnapshot's when it's behind by 10 events AND Deleting All Historic AggregateSnapshot's
      PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, String snapshotTableName, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
      Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
      PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore, dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory, Optional<String> snapshotTableName, dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer, AddNewAggregateSnapshotStrategy addNewSnapshotStrategy, AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
      Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <ID,​AGGREGATE_IMPL_TYPE>
      void
      aggregateUpdated​(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 updated
      <AGGREGATE_IMPL_TYPE>
      void
      deleteAllSnapshots​(Class<AGGREGATE_IMPL_TYPE> ofAggregateImplementationType)
      Delete all snapshots for the given aggregate implementation type
      <ID,​AGGREGATE_IMPL_TYPE>
      void
      deleteSnapshots​(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>
      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)
      Delete all snapshots with a given AggregateSnapshot.eventOrderOfLastIncludedEvent for the given aggregate instance, with the given aggregate implementation type
      protected Optional<dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.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​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType, ID aggregateId, Class<AGGREGATE_IMPL_TYPE> aggregateImplType, boolean includeSnapshotPayload)
      Load all AggregateSnapshot's related to the given aggregate instance
      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)  
      <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)  
    • Field Detail

      • DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME

        public static final String DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME
        See Also:
        Constant Field Values
    • Constructor Detail

      • PostgresqlAggregateSnapshotRepository

        public PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore,
                                                     dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory,
                                                     dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer)
        Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository that will persist AggregateSnapshot's into the DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME table
        Adding new AggregateSnapshot's when it's behind by 10 events AND Deleting All Historic AggregateSnapshot's
        Parameters:
        eventStore - the event store responsible for persisting aggregate event stream
        unitOfWorkFactory - unit of work factory for controlling transactions
        jsonSerializer - JSON serializer that will be used to serialize Aggregate instances
      • PostgresqlAggregateSnapshotRepository

        public PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore,
                                                     dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory,
                                                     String snapshotTableName,
                                                     dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer)
        Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
        Adding new AggregateSnapshot's when it's behind by 10 events AND Deleting All Historic AggregateSnapshot's
        Parameters:
        eventStore - the event store responsible for persisting aggregate event stream
        unitOfWorkFactory - unit of work factory for controlling transactions
        snapshotTableName - the name of the table where AggregateSnapshot's will be stored
        jsonSerializer - JSON serializer that will be used to serialize Aggregate instances
      • PostgresqlAggregateSnapshotRepository

        public PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore,
                                                     dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory,
                                                     String snapshotTableName,
                                                     dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer,
                                                     AddNewAggregateSnapshotStrategy addNewSnapshotStrategy,
                                                     AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
        Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
        Parameters:
        eventStore - the event store responsible for persisting aggregate event stream
        unitOfWorkFactory - unit of work factory for controlling transactions
        snapshotTableName - the name of the table where AggregateSnapshot's will be stored
        jsonSerializer - JSON serializer that will be used to serialize Aggregate instances
        addNewSnapshotStrategy - the strategy determining when a new AggregateSnapshot will be stored
        snapshotDeletionStrategy - the strategy determining when an existing AggregateSnapshot will be deleted
      • PostgresqlAggregateSnapshotRepository

        public PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore,
                                                     dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory,
                                                     dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer,
                                                     AddNewAggregateSnapshotStrategy addNewSnapshotStrategy,
                                                     AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
        Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository that will persist AggregateSnapshot's into the DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME table
        Parameters:
        eventStore - the event store responsible for persisting aggregate event stream
        unitOfWorkFactory - unit of work factory for controlling transactions
        jsonSerializer - JSON serializer that will be used to serialize Aggregate instances
        addNewSnapshotStrategy - the strategy determining when a new AggregateSnapshot will be stored
        snapshotDeletionStrategy - the strategy determining when an existing AggregateSnapshot will be deleted
      • PostgresqlAggregateSnapshotRepository

        public PostgresqlAggregateSnapshotRepository​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.ConfigurableEventStore<? extends dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.persistence.AggregateEventStreamConfiguration> eventStore,
                                                     dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWorkFactory<? extends dk.cloudcreate.essentials.components.foundation.transaction.jdbi.HandleAwareUnitOfWork> unitOfWorkFactory,
                                                     Optional<String> snapshotTableName,
                                                     dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.serializer.json.JSONEventSerializer jsonSerializer,
                                                     AddNewAggregateSnapshotStrategy addNewSnapshotStrategy,
                                                     AggregateSnapshotDeletionStrategy snapshotDeletionStrategy)
        Create a new durable Postgresql version of the PostgresqlAggregateSnapshotRepository
        Parameters:
        eventStore - the event store responsible for persisting aggregate event stream
        unitOfWorkFactory - unit of work factory for controlling transactions
        snapshotTableName - Optional name of the table where AggregateSnapshot's will be stored - if Optional.empty() then AggregateSnapshot's will persisted into the DEFAULT_AGGREGATE_SNAPSHOTS_TABLE_NAME table
        jsonSerializer - JSON serializer that will be used to serialize Aggregate instances
        addNewSnapshotStrategy - the strategy determining when a new AggregateSnapshot will be stored
        snapshotDeletionStrategy - the strategy determining when an existing AggregateSnapshot will be deleted
    • Method Detail

      • 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:
        loadSnapshot in interface AggregateSnapshotRepository
        Type Parameters:
        ID - the aggregate ID type
        AGGREGATE_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 instance
        withLastIncludedEventOrderLessThanOrEqualTo - the snapshot returned must have AggregateSnapshot.eventOrderOfLastIncludedEvent that is less than or equal to this value
        aggregateImplType - the concrete aggregate implementation type
        Returns:
        the aggregate snapshot wrapped in an Optional if a snapshot was found, otherwise Optional.empty()
      • 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: AggregateSnapshotRepository
        Callback from an Aggregate Repository to notify that the aggregate has been updated
        Specified by:
        aggregateUpdated in interface AggregateSnapshotRepository
        Type Parameters:
        ID - the aggregate ID type
        AGGREGATE_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 aggregate
        persistedEvents - the aggregate changes (in the form of events) after they've been persisted
      • findMostRecentLastIncludedEventOrderFor

        protected Optional<dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.types.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​(dk.cloudcreate.essentials.components.eventsourced.eventstore.postgresql.eventstream.AggregateType aggregateType,
                                                                                                                     ID aggregateId,
                                                                                                                     Class<AGGREGATE_IMPL_TYPE> aggregateImplType,
                                                                                                                     boolean includeSnapshotPayload)
        Description copied from interface: AggregateSnapshotRepository
        Load all AggregateSnapshot's related to the given aggregate instance
        Specified by:
        loadAllSnapshots in interface AggregateSnapshotRepository
        Type Parameters:
        ID - the aggregate ID type
        AGGREGATE_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 instance
        aggregateImplType - the concrete aggregate implementation type
        includeSnapshotPayload - should the AggregateSnapshot.aggregateSnapshot be loaded?
        Returns:
        list of all AggregateSnapshot's in ascending AggregateSnapshot.eventOrderOfLastIncludedEvent order (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: AggregateSnapshotRepository
        Delete all snapshots for the given aggregate implementation type
        Specified by:
        deleteAllSnapshots in interface AggregateSnapshotRepository
        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: AggregateSnapshotRepository
        Delete all snapshots for the given aggregate instance with the given aggregate implementation type
        Specified by:
        deleteSnapshots in interface AggregateSnapshotRepository
        Type Parameters:
        ID - the aggregate ID type
        AGGREGATE_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 for
        withAggregateImplementationType - 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: AggregateSnapshotRepository
        Delete all snapshots with a given AggregateSnapshot.eventOrderOfLastIncludedEvent for the given aggregate instance, with the given aggregate implementation type
        Specified by:
        deleteSnapshots in interface AggregateSnapshotRepository
        Type Parameters:
        ID - the aggregate ID type
        AGGREGATE_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 for
        withAggregateImplementationType - the concrete aggregate implementation type that we want to delete all snapshots for
        snapshotEventOrdersToDelete - The list of AggregateSnapshot.eventOrderOfLastIncludedEvent 's that should be deleted