Class AnnotatedSagaRepository<T>

java.lang.Object
org.axonframework.modelling.saga.repository.LockingSagaRepository<T>
org.axonframework.modelling.saga.repository.AnnotatedSagaRepository<T>
Type Parameters:
T - generic type specifying the Saga type stored by this SagaRepository
All Implemented Interfaces:
SagaRepository<T>

public class AnnotatedSagaRepository<T> extends LockingSagaRepository<T>
SagaRepository implementation extending from the LockingSagaRepository dealing with annotated Sagas. Will take care of the uniqueness of Saga instances in the JVM. That means it will prevent multiple instances of the same conceptual Saga (i.e. with same identifier) to exist within the JVM.
Since:
0.7
Author:
Allard Buijze
  • Constructor Details

  • Method Details

    • builder

      public static <T> AnnotatedSagaRepository.Builder<T> builder()
      Instantiate a Builder to be able to create an AnnotatedSagaRepository.

      The ResourceInjector is defaulted to a NoResourceInjector. This Builder either allows directly setting a SagaModel of generic type T, or it will generate it based of the required sagaType field of type Class. Same for the MessageHandlerInterceptorMemberChain Thus, either the SagaModel or the sagaType should be provided. All Saga in this repository must be instanceOf this saga type. Additionally, the sagaType and SagaStore are hard requirements and as such should be provided.

      Type Parameters:
      T - a generic specifying the Saga type contained in this SagaRepository implementation
      Returns:
      a Builder to be able to create a AnnotatedSagaRepository
    • doLoad

      public AnnotatedSaga<T> doLoad(String sagaIdentifier)
      Description copied from class: LockingSagaRepository
      Loads a known Saga instance by its unique identifier. Due to the concurrent nature of Sagas, it is not unlikely for a Saga to have ceased to exist after it has been found based on associations. Therefore, a repository should return null in case a Saga doesn't exists, as opposed to throwing an exception.
      Specified by:
      doLoad in class LockingSagaRepository<T>
      Parameters:
      sagaIdentifier - The unique identifier of the Saga to load
      Returns:
      The Saga instance, or null if no such saga exists
    • doCreateInstance

      public AnnotatedSaga<T> doCreateInstance(String sagaIdentifier, Supplier<T> sagaFactory)
      Description copied from class: LockingSagaRepository
      Creates a new Saga instance. The returned Saga will delegate event handling to the instance supplied by the given factoryMethod.
      Specified by:
      doCreateInstance in class LockingSagaRepository<T>
      Parameters:
      sagaIdentifier - the identifier to use for the new saga instance
      sagaFactory - Used to create a new Saga delegate
      Returns:
      a new Saga instance wrapping an instance of type T
    • unsavedSagaResource

      protected Set<String> unsavedSagaResource(UnitOfWork<?> unitOfWork)
      Returns a set of identifiers of sagas that may have changed in the context of the given unitOfWork and have not been saved yet.
      Parameters:
      unitOfWork - the unit of work to inspect for unsaved sagas
      Returns:
      set of saga identifiers of unsaved sagas
    • commit

      protected void commit(AnnotatedSaga<T> saga)
      Commits the given modified saga to the underlying saga store. If the saga is not active anymore it will be deleted. Otherwise the stored saga and its associations will be updated.
      Parameters:
      saga - the saga to commit to the store
    • find

      public Set<String> find(AssociationValue associationValue)
      Description copied from interface: SagaRepository
      Find saga instances of the given type that have been associated with the given associationValue.

      Parameters:
      associationValue - The value that the returned Sagas must be associated with
      Returns:
      A Set containing the found Saga instances. If none are found, an empty Set is returned. Will never return null.
    • deleteSaga

      protected void deleteSaga(AnnotatedSaga<T> saga)
      Remove the given saga as well as all known association values pointing to it from the repository. If no such saga exists, nothing happens.
      Parameters:
      saga - The saga instance to remove from the repository
    • updateSaga

      protected void updateSaga(AnnotatedSaga<T> saga)
      Update a stored Saga, by replacing it with the given saga instance.
      Parameters:
      saga - The saga that has been modified and needs to be updated in the storage
    • storeSaga

      protected void storeSaga(AnnotatedSaga<T> saga)
      Stores a newly created Saga instance.
      Parameters:
      saga - The newly created Saga instance to store.
    • doLoadSaga

      protected AnnotatedSaga<T> doLoadSaga(String sagaIdentifier)
      Loads the saga with given sagaIdentifier from the underlying saga store and returns it as a AnnotatedSaga. Resources of the saga will be injected using the ResourceInjector configured with the repository.
      Parameters:
      sagaIdentifier - the identifier of the saga to load
      Returns:
      AnnotatedSaga instance with the loaded saga