T
- generic type specifying the Saga type stored by this
SagaRepository
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.Modifier and Type | Class and Description |
---|---|
static class |
AnnotatedSagaRepository.Builder<T>
Builder class to instantiate a
AnnotatedSagaRepository . |
Modifier | Constructor and Description |
---|---|
protected |
AnnotatedSagaRepository(AnnotatedSagaRepository.Builder<T> builder)
Instantiate a
AnnotatedSagaRepository based on the fields contained in the AnnotatedSagaRepository.Builder . |
Modifier and Type | Method and Description |
---|---|
static <T> AnnotatedSagaRepository.Builder<T> |
builder()
Instantiate a Builder to be able to create an
AnnotatedSagaRepository . |
protected void |
commit(AnnotatedSaga<T> saga)
Commits the given modified
saga to the underlying saga store. |
protected void |
deleteSaga(AnnotatedSaga<T> saga)
Remove the given saga as well as all known association values pointing to it from the repository.
|
AnnotatedSaga<T> |
doCreateInstance(String sagaIdentifier,
Supplier<T> sagaFactory)
Creates a new Saga instance.
|
AnnotatedSaga<T> |
doLoad(String sagaIdentifier)
Loads a known Saga instance by its unique identifier.
|
protected AnnotatedSaga<T> |
doLoadSaga(String sagaIdentifier)
Loads the saga with given
sagaIdentifier from the underlying saga store and returns it as a AnnotatedSaga . |
Set<String> |
find(AssociationValue associationValue)
Find saga instances of the given
type that have been associated with the given
associationValue . |
protected void |
storeSaga(AnnotatedSaga<T> saga)
Stores a newly created Saga instance.
|
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. |
protected void |
updateSaga(AnnotatedSaga<T> saga)
Update a stored Saga, by replacing it with the given
saga instance. |
createInstance, load
protected AnnotatedSagaRepository(AnnotatedSagaRepository.Builder<T> builder)
AnnotatedSagaRepository
based on the fields contained in the AnnotatedSagaRepository.Builder
.
Will assert that the sagaType
, SagaStore
and ResourceInjector
are not null
, and
will throw an AxonConfigurationException
if any of them is null
.
Additionally, the provided Builder's goal is to either build a SagaModel
specifying generic T
as
the Saga type to be stored or derive it based on the given sagaType
.
All Sagas in this repository must be instanceOf
this saga type.
builder
- the AnnotatedSagaRepository.Builder
used to instantiate a AnnotatedSagaRepository
instancepublic static <T> AnnotatedSagaRepository.Builder<T> builder()
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
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.
T
- a generic specifying the Saga type contained in this
SagaRepository
implementationAnnotatedSagaRepository
public AnnotatedSaga<T> doLoad(String sagaIdentifier)
LockingSagaRepository
null
in case a Saga doesn't
exists, as opposed to throwing an exception.doLoad
in class LockingSagaRepository<T>
sagaIdentifier
- The unique identifier of the Saga to loadnull
if no such saga existspublic AnnotatedSaga<T> doCreateInstance(String sagaIdentifier, Supplier<T> sagaFactory)
LockingSagaRepository
factoryMethod
.doCreateInstance
in class LockingSagaRepository<T>
sagaIdentifier
- the identifier to use for the new saga instancesagaFactory
- Used to create a new Saga delegateT
protected Set<String> unsavedSagaResource(UnitOfWork<?> unitOfWork)
unitOfWork
and
have not been saved yet.unitOfWork
- the unit of work to inspect for unsaved sagasprotected void commit(AnnotatedSaga<T> saga)
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.saga
- the saga to commit to the storepublic Set<String> find(AssociationValue associationValue)
SagaRepository
type
that have been associated with the given
associationValue
.
associationValue
- The value that the returned Sagas must be associated withnull
.protected void deleteSaga(AnnotatedSaga<T> saga)
saga
- The saga instance to remove from the repositoryprotected void updateSaga(AnnotatedSaga<T> saga)
saga
instance.saga
- The saga that has been modified and needs to be updated in the storageprotected void storeSaga(AnnotatedSaga<T> saga)
saga
- The newly created Saga instance to store.protected AnnotatedSaga<T> doLoadSaga(String sagaIdentifier)
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.sagaIdentifier
- the identifier of the saga to loadCopyright © 2010–2019. All rights reserved.