public class JpaSagaStore extends Object implements SagaStore<Object>
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)SagaStore.Entry<T>| Constructor and Description |
|---|
JpaSagaStore(EntityManagerProvider entityManagerProvider)
Initializes a Saga Repository with an
XStreamSerializer and given entityManagerProvider. |
JpaSagaStore(Serializer serializer,
EntityManagerProvider entityManagerProvider)
Initializes a Saga Repository with the given
serializer and entityManagerProvider. |
| Modifier and Type | Method and Description |
|---|---|
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,
TrackingToken token,
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,
TrackingToken token,
AssociationValues associationValues)
Updates a given Saga after its state was modified.
|
public JpaSagaStore(EntityManagerProvider entityManagerProvider)
XStreamSerializer and given entityManagerProvider.entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repositorypublic JpaSagaStore(Serializer serializer, EntityManagerProvider entityManagerProvider)
serializer and entityManagerProvider.serializer - The serializer to serialize saga instances withentityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repositorypublic <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, TrackingToken token, 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 instancetoken - The tracking token of the event last handled by the Saga. May be null.associationValues - The initial association values of the Sagapublic void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, TrackingToken token, 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 instancetoken - The tracking token of the event last handled by the Saga. May be null.associationValues - 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–2017. All rights reserved.