org.axonframework.saga.repository.jdbc
Class JdbcSagaRepository

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

public class JdbcSagaRepository
extends AbstractSagaRepository

Jdbc implementation of the Saga Repository.

Since:
2.1
Author:
Allard Buijze, Kristian Rosenvold

Constructor Summary
JdbcSagaRepository(ConnectionProvider connectionProvider)
          Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, using a Generic SQL Schema.
JdbcSagaRepository(ConnectionProvider connectionProvider, SagaSqlSchema sqldef)
          Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, and given sqldef to execute SQL statements.
JdbcSagaRepository(ConnectionProvider connectionProvider, SagaSqlSchema sqldef, Serializer serializer)
          Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, and given sqldef to execute SQL statements and serializer to serialize Sagas.
JdbcSagaRepository(DataSource dataSource, SagaSqlSchema sqldef)
          Initializes a Saga Repository, using given dataSource to obtain connections to the database, and given sqldef to execute SQL statements.
 
Method Summary
 void createSchema()
          Creates the SQL Schema required to store Sagas and their associations,.
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.
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

JdbcSagaRepository

public JdbcSagaRepository(ConnectionProvider connectionProvider)
Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, using a Generic SQL Schema.

Parameters:
connectionProvider - The data source to obtain connections from

JdbcSagaRepository

public JdbcSagaRepository(DataSource dataSource,
                          SagaSqlSchema sqldef)
Initializes a Saga Repository, using given dataSource to obtain connections to the database, and given sqldef to execute SQL statements.

Parameters:
dataSource - The data source to obtain connections from
sqldef - The definition of SQL operations to execute

JdbcSagaRepository

public JdbcSagaRepository(ConnectionProvider connectionProvider,
                          SagaSqlSchema sqldef)
Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, and given sqldef to execute SQL statements.

Parameters:
connectionProvider - The provider to obtain connections from
sqldef - The definition of SQL operations to execute

JdbcSagaRepository

public JdbcSagaRepository(ConnectionProvider connectionProvider,
                          SagaSqlSchema sqldef,
                          Serializer serializer)
Initializes a Saga Repository, using given connectionProvider to obtain connections to the database, and given sqldef to execute SQL statements and serializer to serialize Sagas.

Parameters:
connectionProvider - The provider to obtain connections from
sqldef - The definition of SQL operations to execute
serializer - The serializer to serialize and deserialize Saga instances with
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

createSchema

public void createSchema()
                  throws SQLException
Creates the SQL Schema required to store Sagas and their associations,.

Throws:
SQLException - When an error occurs preparing of executing the required statements


Copyright © 2010-2016. All Rights Reserved.