org.axonframework.saga.repository.jpa
Class JpaSagaRepository

java.lang.Object
  extended by org.axonframework.saga.repository.AbstractSagaRepository
      extended by org.axonframework.saga.repository.jpa.JpaSagaRepository
All Implemented Interfaces:
SagaRepository

public class JpaSagaRepository
extends AbstractSagaRepository

JPA implementation of the Saga Repository. It uses an EntityManager to persist the actual saga in a backing store.

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

Since:
0.7
Author:
Allard Buijze

Constructor Summary
JpaSagaRepository(EntityManagerProvider entityManagerProvider)
          Initializes a Saga Repository with a JavaSerializer.
 
Method Summary
protected  void deleteSaga(Saga saga)
          Remove the given saga as well as all known association values pointing to it from the repository.
protected  Set<String> findAssociatedSagaIdentifiers(Class<? extends Saga> type, AssociationValue associationValue)
          Finds the identifiers of the sagas of given type associated with the given associationValue.
 Saga load(String sagaId)
          Loads a known Saga instance by its unique identifier.
protected  void removeAssociationValue(AssociationValue associationValue, String sagaType, String sagaIdentifier)
          Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.
 void setResourceInjector(ResourceInjector resourceInjector)
          Sets the ResourceInjector to use to inject Saga instances with any (temporary) resources they might need.
 void setSerializer(Serializer serializer)
          Sets the Serializer instance to serialize Sagas with.
 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(AssociationValue associationValue, String sagaType, String sagaIdentifier)
          Store the given associationValue, which has been associated with given sagaIdentifier.
protected  void storeSaga(Saga saga)
          Stores a newly created Saga instance.
protected  String typeOf(Class<? extends Saga> sagaClass)
          Returns the type identifier to use for the given sagaClass.
protected  void updateSaga(Saga saga)
          Update a stored Saga, by replacing it with the given saga instance.
 
Methods inherited from class org.axonframework.saga.repository.AbstractSagaRepository
add, commit, find
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaSagaRepository

public JpaSagaRepository(EntityManagerProvider entityManagerProvider)
Initializes a Saga Repository with a JavaSerializer.

Parameters:
entityManagerProvider - The EntityManagerProvider providing the EntityManager instance for this repository
Method Detail

load

public Saga load(String sagaId)
Description copied from interface: SagaRepository
Loads a known Saga instance by its unique identifier. Returned Sagas must be committed after processing. 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.

Parameters:
sagaId - The unique identifier of the Saga to load
Returns:
The Saga instance, or null if no such saga exists

removeAssociationValue

protected void removeAssociationValue(AssociationValue associationValue,
                                      String sagaType,
                                      String sagaIdentifier)
Description copied from class: AbstractSagaRepository
Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.

Specified by:
removeAssociationValue in class AbstractSagaRepository
Parameters:
associationValue - The value to remove as association value for the given saga
sagaType - The type of the Saga to remove the association from
sagaIdentifier - The identifier of the Saga to remove the association from

typeOf

protected String typeOf(Class<? extends Saga> sagaClass)
Description copied from class: AbstractSagaRepository
Returns the type identifier to use for the given sagaClass. This information is typically provided by the Serializer, if the repository stores serialized instances.

Specified by:
typeOf in class AbstractSagaRepository
Parameters:
sagaClass - The type of saga to get the type identifier for.
Returns:
The type identifier to use for the given sagaClass

storeAssociationValue

protected void storeAssociationValue(AssociationValue associationValue,
                                     String sagaType,
                                     String sagaIdentifier)
Description copied from class: AbstractSagaRepository
Store the given associationValue, which has been associated with given sagaIdentifier.

Specified by:
storeAssociationValue in class AbstractSagaRepository
Parameters:
associationValue - The association value to store
sagaType - Type type of saga the association value belongs to
sagaIdentifier - The saga related to the association value

findAssociatedSagaIdentifiers

protected Set<String> findAssociatedSagaIdentifiers(Class<? extends Saga> type,
                                                    AssociationValue associationValue)
Description copied from class: AbstractSagaRepository
Finds the identifiers of the sagas of given type associated with the given associationValue.

Specified by:
findAssociatedSagaIdentifiers in class AbstractSagaRepository
Parameters:
type - The type of saga to find identifiers for
associationValue - The value the saga must be associated with
Returns:
The identifiers of sagas associated with the given associationValue

deleteSaga

protected void deleteSaga(Saga saga)
Description copied from class: AbstractSagaRepository
Remove the given saga as well as all known association values pointing to it from the repository. If no such saga exists, nothing happens.

Specified by:
deleteSaga in class AbstractSagaRepository
Parameters:
saga - The saga instance to remove from the repository

updateSaga

protected void updateSaga(Saga saga)
Description copied from class: AbstractSagaRepository
Update a stored Saga, by replacing it with the given saga instance.

Specified by:
updateSaga in class AbstractSagaRepository
Parameters:
saga - The saga that has been modified and needs to be updated in the storage

storeSaga

protected void storeSaga(Saga saga)
Description copied from class: AbstractSagaRepository
Stores a newly created Saga instance.

Specified by:
storeSaga in class AbstractSagaRepository
Parameters:
saga - The newly created Saga instance to store.

setResourceInjector

public void setResourceInjector(ResourceInjector resourceInjector)
Sets the ResourceInjector to use to inject Saga instances with any (temporary) resources they might need. These are typically the resources that could not be persisted with the Saga.

Parameters:
resourceInjector - The resource injector

setSerializer

public void setSerializer(Serializer serializer)
Sets the Serializer instance to serialize Sagas with. Defaults to the XStream Serializer.

Parameters:
serializer - the Serializer instance to serialize Sagas with

setUseExplicitFlush

public void setUseExplicitFlush(boolean useExplicitFlush)
Sets whether or not to do an explicit EntityManager.flush() after each data modifying operation on the backing storage. Default to true

Parameters:
useExplicitFlush - true to force flush, false otherwise.


Copyright © 2010-2016. All Rights Reserved.