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()
          Initializes a Saga Repository with a JavaSagaSerializer.
 
Method Summary
 void initialize()
          Initializes the repository by loading all AssociationValues in memory.
protected
<T extends Saga>
T
loadSaga(Class<T> type, String sagaId)
          Loads a known Saga instance by its unique identifier.
protected  void removeAssociationValue(AssociationValue associationValue, String sagaIdentifier)
          Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.
 void setEntityManager(javax.persistence.EntityManager entityManager)
          Sets the EntityManager that takes care of the actual storage of the Saga entries.
 void setResourceInjector(ResourceInjector resourceInjector)
          Sets the ResourceInjector to use to inject Saga instances with any (temporary) resources they might need.
 void setSerializer(SagaSerializer serializer)
          Sets the SagaSerializer 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 sagaIdentifier)
          Store the given associationValue, which has been associated with given sagaIdentifier.
protected  void storeSaga(Saga saga)
          Stores a newly created Saga instance.
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, getAssociationValueMap, getSagaCache, load, purgeCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaSagaRepository

public JpaSagaRepository()
Initializes a Saga Repository with a JavaSagaSerializer.

Method Detail

removeAssociationValue

protected void removeAssociationValue(AssociationValue associationValue,
                                      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
sagaIdentifier - The identifier of the Saga to remove the association from

storeAssociationValue

protected void storeAssociationValue(AssociationValue associationValue,
                                     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
sagaIdentifier - The saga related to the association value

loadSaga

protected <T extends Saga> T loadSaga(Class<T> type,
                                      String sagaId)
Description copied from class: AbstractSagaRepository
Loads a known Saga instance by its unique identifier. Implementations are encouraged, but not required to return the same instance when two Sagas with equal identifiers are loaded.

Specified by:
loadSaga in class AbstractSagaRepository
Type Parameters:
T - The expected type of Saga
Parameters:
type - The expected type of Saga
sagaId - The unique identifier of the Saga to load
Returns:
The Saga instance

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.

initialize

@PostConstruct
public void initialize()
Initializes the repository by loading all AssociationValues in memory. Failure to initialize properly might result in Saga instance not being found based on their AssociationValues.


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

setEntityManager

public void setEntityManager(javax.persistence.EntityManager entityManager)
Sets the EntityManager that takes care of the actual storage of the Saga entries.

Parameters:
entityManager - the EntityManager that takes care of the actual storage of the Saga entries

setSerializer

public void setSerializer(SagaSerializer serializer)
Sets the SagaSerializer instance to serialize Sagas with. Defaults to the JavaSagaSerializer.

Parameters:
serializer - the SagaSerializer 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 © 2011. All Rights Reserved.