org.axonframework.saga.repository
Class AbstractSagaRepository

java.lang.Object
  extended by org.axonframework.saga.repository.AbstractSagaRepository
All Implemented Interfaces:
SagaRepository
Direct Known Subclasses:
JdbcSagaRepository, JpaSagaRepository, MongoSagaRepository, MongoSagaRepository

public abstract class AbstractSagaRepository
extends Object
implements SagaRepository

Abstract implementation for saga repositories. This (partial) implementation will take care of the uniqueness of saga instances in the JVM. That means it will prevent multiple instances of the same conceptual Saga (i.e. with same identifier) to exist within the JVM.

Since:
0.7
Author:
Allard Buijze

Constructor Summary
AbstractSagaRepository()
           
 
Method Summary
 void add(Saga saga)
          Registers a newly created Saga with the Repository.
 void commit(Saga saga)
          Commits the changes made to the Saga instance.
protected abstract  void deleteSaga(Saga saga)
          Remove the given saga as well as all known association values pointing to it from the repository.
 Set<String> find(Class<? extends Saga> type, AssociationValue associationValue)
          Find saga instances of the given type that have been associated with the given associationValue.
protected abstract  Set<String> findAssociatedSagaIdentifiers(Class<? extends Saga> type, AssociationValue associationValue)
          Finds the identifiers of the sagas of given type associated with the given associationValue.
protected abstract  void removeAssociationValue(AssociationValue associationValue, String sagaType, String sagaIdentifier)
          Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.
protected abstract  void storeAssociationValue(AssociationValue associationValue, String sagaType, String sagaIdentifier)
          Store the given associationValue, which has been associated with given sagaIdentifier.
protected abstract  void storeSaga(Saga saga)
          Stores a newly created Saga instance.
protected abstract  String typeOf(Class<? extends Saga> sagaClass)
          Returns the type identifier to use for the given sagaClass.
protected abstract  void updateSaga(Saga saga)
          Update a stored Saga, by replacing it with the given saga instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axonframework.saga.SagaRepository
load
 

Constructor Detail

AbstractSagaRepository

public AbstractSagaRepository()
Method Detail

find

public Set<String> find(Class<? extends Saga> type,
                        AssociationValue associationValue)
Description copied from interface: SagaRepository
Find saga instances of the given type that have been associated with the given associationValue.

Returned Sagas must be committed after processing.

Specified by:
find in interface SagaRepository
Parameters:
type - The type of Saga to return
associationValue - The value that the returned Sagas must be associated with
Returns:
A Set containing the found Saga instances. If none are found, an empty Set is returned. Will never return null.

add

public void add(Saga saga)
Description copied from interface: SagaRepository
Registers a newly created Saga with the Repository. Once a Saga instance has been added, it can be found using its association values or its unique identifier.

Note that if the added Saga is marked inActive (Saga.isActive() returns false), it is not stored.

Specified by:
add in interface SagaRepository
Parameters:
saga - The Saga instances to add.

commit

public void commit(Saga saga)
Description copied from interface: SagaRepository
Commits the changes made to the Saga instance. At this point, the repository may release any resources kept for this saga. If the committed saga is marked inActive (Saga.isActive() returns false), the repository should delete the saga from underlying storage and remove all stored association values associated with that Saga.

Implementations *may* (temporarily) return a cached version of the Saga, which is marked inactive.

Specified by:
commit in interface SagaRepository
Parameters:
saga - The Saga instance to commit

findAssociatedSagaIdentifiers

protected abstract Set<String> findAssociatedSagaIdentifiers(Class<? extends Saga> type,
                                                             AssociationValue associationValue)
Finds the identifiers of the sagas of given type associated with the given associationValue.

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 abstract String typeOf(Class<? extends Saga> sagaClass)
Returns the type identifier to use for the given sagaClass. This information is typically provided by the Serializer, if the repository stores serialized instances.

Parameters:
sagaClass - The type of saga to get the type identifier for.
Returns:
The type identifier to use for the given sagaClass

deleteSaga

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

Parameters:
saga - The saga instance to remove from the repository

updateSaga

protected abstract void updateSaga(Saga saga)
Update a stored Saga, by replacing it with the given saga instance.

Parameters:
saga - The saga that has been modified and needs to be updated in the storage

storeSaga

protected abstract void storeSaga(Saga saga)
Stores a newly created Saga instance.

Parameters:
saga - The newly created Saga instance to store.

storeAssociationValue

protected abstract void storeAssociationValue(AssociationValue associationValue,
                                              String sagaType,
                                              String sagaIdentifier)
Store the given associationValue, which has been associated with given sagaIdentifier.

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 abstract void removeAssociationValue(AssociationValue associationValue,
                                               String sagaType,
                                               String sagaIdentifier)
Removes the association value that has been associated with Saga, identified with the given sagaIdentifier.

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


Copyright © 2010-2016. All Rights Reserved.