public class JpaSagaStore extends Object implements SagaStore<Object>
SagaStore. It uses an EntityManager to persist the actual
saga in a backing store in serialized form.
After each operations that modified the backing store, EntityManager.flush() is invoked to
ensure the store contains the last modifications. To override this behavior, see setUseExplicitFlush(boolean)| Modifier and Type | Class and Description |
|---|---|
static class |
JpaSagaStore.Builder
Builder class to instantiate a
JpaSagaStore. |
SagaStore.Entry<T>| Modifier | Constructor and Description |
|---|---|
protected |
JpaSagaStore(JpaSagaStore.Builder builder)
Instantiate a
JpaSagaStore based on the fields contained in the JpaSagaStore.Builder. |
| Modifier and Type | Method and Description |
|---|---|
static JpaSagaStore.Builder |
builder()
Instantiate a Builder to be able to create a
JpaSagaStore. |
protected AbstractSagaEntry<?> |
createSagaEntry(Object saga,
String sagaIdentifier,
Serializer serializer)
Intended for clients to override.
|
void |
deleteSaga(Class<?> sagaType,
String sagaIdentifier,
Set<AssociationValue> associationValues)
Deletes a Saga with given
sagaType and sagaIdentifier and all its associations. |
Set<String> |
findSagas(Class<?> sagaType,
AssociationValue associationValue)
Returns identifiers of saga instances of the given
sagaType that have been associated with the given
associationValue. |
void |
insertSaga(Class<?> sagaType,
String sagaIdentifier,
Object saga,
Set<AssociationValue> associationValues)
Adds a new Saga and its initial association values to the store.
|
protected Set<AssociationValue> |
loadAssociationValues(javax.persistence.EntityManager entityManager,
Class<?> sagaType,
String sagaIdentifier)
|
<S> SagaStore.Entry<S> |
loadSaga(Class<S> sagaType,
String sagaIdentifier)
|
protected void |
removeAssociationValue(javax.persistence.EntityManager entityManager,
Class<?> sagaType,
String sagaIdentifier,
AssociationValue associationValue)
Removes the given
associationValue of the saga with given sagaIdentifier and sagaType. |
protected String |
sagaEntryEntityName()
Intended for clients to override.
|
protected Class<? extends SimpleSerializedObject<?>> |
serializedObjectType()
Intended for clients to override.
|
void |
setUseExplicitFlush(boolean useExplicitFlush)
Sets whether or not to do an explicit
EntityManager.flush() after each data modifying
operation on the backing storage. |
protected void |
storeAssociationValue(javax.persistence.EntityManager entityManager,
Class<?> sagaType,
String sagaIdentifier,
AssociationValue associationValue)
Stores the given
associationValue of the saga with given sagaIdentifier and sagaType. |
void |
updateSaga(Class<?> sagaType,
String sagaIdentifier,
Object saga,
AssociationValues associationValues)
Updates a given Saga after its state was modified.
|
protected JpaSagaStore(JpaSagaStore.Builder builder)
JpaSagaStore based on the fields contained in the JpaSagaStore.Builder.
Will assert that the EntityManagerProvider and Serializer are not null, and will throw an
AxonConfigurationException if any of them is null.
builder - the JpaSagaStore.Builder used to instantiate a JpaSagaStore instancepublic static JpaSagaStore.Builder builder()
JpaSagaStore.
The Serializer is defaulted to an XStreamSerializer.
The EntityManagerProvider is a hard requirement and as such should be provided.
JpaSagaStorepublic <S> SagaStore.Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier)
SagaStoreSagaStore.Entry instance with given sagaType and unique sagaIdentifier.
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.
protected Set<AssociationValue> loadAssociationValues(javax.persistence.EntityManager entityManager, Class<?> sagaType, String sagaIdentifier)
entityManager - the entity manager instance to use for the querysagaType - the saga instance classsagaIdentifier - the saga identifierprotected void removeAssociationValue(javax.persistence.EntityManager entityManager,
Class<?> sagaType,
String sagaIdentifier,
AssociationValue associationValue)
associationValue of the saga with given sagaIdentifier and sagaType.entityManager - the entity manager instance to use for the querysagaType - the saga instance classsagaIdentifier - the saga identifierassociationValue - the association value to removeprotected void storeAssociationValue(javax.persistence.EntityManager entityManager,
Class<?> sagaType,
String sagaIdentifier,
AssociationValue associationValue)
associationValue of the saga with given sagaIdentifier and sagaType.entityManager - the entity manager instance to use for the querysagaType - the saga instance classsagaIdentifier - the saga identifierassociationValue - the association value to addpublic Set<String> findSagas(Class<?> sagaType, AssociationValue associationValue)
SagaStoresagaType that have been associated with the given
associationValue.public void deleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues)
SagaStoresagaType and sagaIdentifier and all its associations. For convenience
all known association values are passed along as well, which has the advantage that the saga store is not
required to keep an index of association value to saga identifier.deleteSaga in interface SagaStore<Object>sagaType - The type of saga to deletesagaIdentifier - The identifier of the saga to deleteassociationValues - The known associations of the sagapublic void updateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues)
SagaStoretoken may be null if the Saga is not tracking the
event store.updateSaga in interface SagaStore<Object>sagaType - The type of the SagasagaIdentifier - The identifier of the Sagasaga - The Saga instanceassociationValues - The initial association values of the Sagapublic void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, Set<AssociationValue> associationValues)
SagaStoretoken may be null if the Saga is not tracking the event store.insertSaga in interface SagaStore<Object>sagaType - The type of the SagasagaIdentifier - The identifier of the Sagasaga - The Saga instanceassociationValues - The initial association values of the Sagapublic void setUseExplicitFlush(boolean useExplicitFlush)
EntityManager.flush() after each data modifying
operation on the backing storage. Default to trueuseExplicitFlush - true to force flush, false otherwise.protected AbstractSagaEntry<?> createSagaEntry(Object saga, String sagaIdentifier, Serializer serializer)
SagaEntry.sagaIdentifier - The identifier of the Sagasaga - The Saga instanceserializer - The serializer to serialize to the AbstractSagaEntry.getSerializedSaga()SagaEntryprotected String sagaEntryEntityName()
protected Class<? extends SimpleSerializedObject<?>> serializedObjectType()
SerialzedSaga.classCopyright © 2010–2018. All rights reserved.