org.axonframework.mongo3.saga.repository
Class MongoSagaRepository

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

public class MongoSagaRepository
extends AbstractSagaRepository

Implementations of the SagaRepository that stores Sagas and their associations in a Mongo Database. Each Saga and its associations is stored as a single document.

Since:
2.0
Author:
Jettro Coenradie, Allard Buijze

Constructor Summary
MongoSagaRepository(MongoTemplate mongoTemplate)
          Initializes the Repository, using given mongoTemplate to access the collections containing the stored Saga instances.
 
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 sagaIdentifier)
          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)
          Provide the serializer to use if the default JavaSagaSerializer is not the best solution.
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

MongoSagaRepository

public MongoSagaRepository(MongoTemplate mongoTemplate)
Initializes the Repository, using given mongoTemplate to access the collections containing the stored Saga instances.

Parameters:
mongoTemplate - the template providing access to the collections
Method Detail

load

public Saga load(String sagaIdentifier)
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:
sagaIdentifier - The unique identifier of the Saga to load
Returns:
The Saga instance, or null if no such saga exists

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

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

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.

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

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

setSerializer

public void setSerializer(Serializer serializer)
Provide the serializer to use if the default JavaSagaSerializer is not the best solution.

Parameters:
serializer - SagaSerializer to use for sag serialization.

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


Copyright © 2010-2016. All Rights Reserved.