Class AnnotatedSagaRepository<T>
- Type Parameters:
T- generic type specifying the Saga type stored by thisSagaRepository
- All Implemented Interfaces:
SagaRepository<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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aAnnotatedSagaRepository. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAnnotatedSagaRepositorybased on the fields contained in theAnnotatedSagaRepository.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AnnotatedSagaRepository.Builder<T> builder()Instantiate a Builder to be able to create anAnnotatedSagaRepository.protected voidcommit(AnnotatedSaga<T> saga) Commits the given modifiedsagato the underlying saga store.protected voiddeleteSaga(AnnotatedSaga<T> saga) Remove the given saga as well as all known association values pointing to it from the repository.doCreateInstance(String sagaIdentifier, Supplier<T> sagaFactory) Creates a new Saga instance.Loads a known Saga instance by its unique identifier.protected AnnotatedSaga<T> doLoadSaga(String sagaIdentifier) Loads the saga with givensagaIdentifierfrom the underlying saga store and returns it as aAnnotatedSaga.find(AssociationValue associationValue) Find saga instances of the giventypethat have been associated with the givenassociationValue.protected voidstoreSaga(AnnotatedSaga<T> saga) Stores a newly created Saga instance.unsavedSagaResource(UnitOfWork<?> unitOfWork) Returns a set of identifiers of sagas that may have changed in the context of the givenunitOfWorkand have not been saved yet.protected voidupdateSaga(AnnotatedSaga<T> saga) Update a stored Saga, by replacing it with the givensagainstance.Methods inherited from class org.axonframework.modelling.saga.repository.LockingSagaRepository
createInstance, load
-
Constructor Details
-
AnnotatedSagaRepository
Instantiate aAnnotatedSagaRepositorybased on the fields contained in theAnnotatedSagaRepository.Builder.Will assert that the
sagaType,SagaStoreandResourceInjectorare notnull, and will throw anAxonConfigurationExceptionif any of them isnull. Additionally, the provided builder's goal is to either build aSagaModelspecifying genericTas the Saga type to be stored or derive it based on the givensagaType. The same argument applies to theMessageHandlerInterceptorMemberChain. All Sagas in this repository must beinstanceOfthis saga type.- Parameters:
builder- theAnnotatedSagaRepository.Builderused to instantiate aAnnotatedSagaRepositoryinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create anAnnotatedSagaRepository.The
ResourceInjectoris defaulted to aNoResourceInjector. This Builder either allows directly setting aSagaModelof generic typeT, or it will generate it based of the requiredsagaTypefield of typeClass. Same for theMessageHandlerInterceptorMemberChainThus, either the SagaModel or thesagaTypeshould be provided. All Saga in this repository must beinstanceOfthis saga type. Additionally, thesagaTypeandSagaStoreare hard requirements and as such should be provided.- Type Parameters:
T- a generic specifying the Saga type contained in thisSagaRepositoryimplementation- Returns:
- a Builder to be able to create a
AnnotatedSagaRepository
-
doLoad
Description copied from class:LockingSagaRepositoryLoads 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 returnnullin case a Saga doesn't exists, as opposed to throwing an exception.- Specified by:
doLoadin classLockingSagaRepository<T>- Parameters:
sagaIdentifier- The unique identifier of the Saga to load- Returns:
- The Saga instance, or
nullif no such saga exists
-
doCreateInstance
Description copied from class:LockingSagaRepositoryCreates a new Saga instance. The returned Saga will delegate event handling to the instance supplied by the givenfactoryMethod.- Specified by:
doCreateInstancein classLockingSagaRepository<T>- Parameters:
sagaIdentifier- the identifier to use for the new saga instancesagaFactory- Used to create a new Saga delegate- Returns:
- a new Saga instance wrapping an instance of type
T
-
unsavedSagaResource
Returns a set of identifiers of sagas that may have changed in the context of the givenunitOfWorkand 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
Commits the given modifiedsagato 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
Description copied from interface:SagaRepositoryFind saga instances of the giventypethat have been associated with the givenassociationValue.- 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
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
Update a stored Saga, by replacing it with the givensagainstance.- Parameters:
saga- The saga that has been modified and needs to be updated in the storage
-
storeSaga
Stores a newly created Saga instance.- Parameters:
saga- The newly created Saga instance to store.
-
doLoadSaga
Loads the saga with givensagaIdentifierfrom the underlying saga store and returns it as aAnnotatedSaga. Resources of the saga will be injected using theResourceInjectorconfigured with the repository.- Parameters:
sagaIdentifier- the identifier of the saga to load- Returns:
- AnnotatedSaga instance with the loaded saga
-