Class JdbcSagaStore
SagaStore implementation that uses JDBC to store and find Saga instances.
Before using this store make sure the database contains an association value- and saga entry table. These can be
constructed with SagaSqlSchema.sql_createTableAssocValueEntry(Connection) and SagaSqlSchema.sql_createTableSagaEntry(Connection) respectively. For convenience, these tables can be constructed
through the createSchema() operation.
- Since:
- 2.1
- Author:
- Allard Buijze, Kristian Rosenvold
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.axonframework.modelling.saga.repository.SagaStore
SagaStore.Entry<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJdbcSagaStore(JdbcSagaStore.Builder builder) Instantiate aJdbcSagaStorebased on the fields contained in theJdbcSagaStore.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic JdbcSagaStore.Builderbuilder()Instantiate a Builder to be able to create aJdbcSagaStore.voidCreates the SQL Schema required to store Sagas and their associations.voiddeleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Deletes a Saga with givensagaTypeandsagaIdentifierand all its associations.findSagas(Class<?> sagaType, AssociationValue associationValue) Returns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue.voidinsertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, Set<AssociationValue> associationValues) Adds a new Saga and its initial association values to the store.<S> SagaStore.Entry<S> voidsetSerializer(Serializer serializer) Sets the Serializer instance to serialize Sagas with.voidupdateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues) Updates a given Saga after its state was modified.
-
Constructor Details
-
JdbcSagaStore
Instantiate aJdbcSagaStorebased on the fields contained in theJdbcSagaStore.Builder.Will assert that the
ConnectionProvider,SagaSqlSchemaandSerializerare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theJdbcSagaStore.Builderused to instantiate aJdbcSagaStoreinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aJdbcSagaStore.The
SagaSqlSchemais defaulted to anGenericSagaSqlSchema.The
ConnectionProviderandSerializerare hard requirements and as such should be provided.You can choose to provide a
DataSourceinstead of a ConnectionProvider, but in that case the used ConnectionProvider will be aDataSourceConnectionProviderwrapped by aUnitOfWorkAwareConnectionProviderWrapper.- Returns:
- a Builder to be able to create a
JdbcSagaStore
-
loadSaga
Description copied from interface:SagaStoreLoads a known sagaSagaStore.Entryinstance with givensagaTypeand uniquesagaIdentifier.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
nullin case a Saga doesn't exists, as opposed to throwing an exception. -
findSagas
Description copied from interface:SagaStoreReturns identifiers of saga instances of the givensagaTypethat have been associated with the givenassociationValue. -
deleteSaga
public void deleteSaga(Class<?> sagaType, String sagaIdentifier, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreDeletes a Saga with givensagaTypeandsagaIdentifierand all its associations. For convenience all known association values are passed along as well, which has the advantage that the saga store is not required to keep an index of association value to saga identifier.- Specified by:
deleteSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of saga to deletesagaIdentifier- The identifier of the saga to deleteassociationValues- The known associations of the saga
-
updateSaga
public void updateSaga(Class<?> sagaType, String sagaIdentifier, Object saga, AssociationValues associationValues) Description copied from interface:SagaStoreUpdates a given Saga after its state was modified. The tracking token of the event last handled by the Saga is also passed as a parameter. Note that the giventokenmay benullif the Saga is not tracking the event store.- Specified by:
updateSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The initial association values of the Saga
-
insertSaga
public void insertSaga(Class<?> sagaType, String sagaIdentifier, Object saga, Set<AssociationValue> associationValues) Description copied from interface:SagaStoreAdds a new Saga and its initial association values to the store. The tracking token of the event last handled by the Saga (usually the event that started the Saga) is also passed as a parameter. Note that the giventokenmay benullif the Saga is not tracking the event store.- Specified by:
insertSagain interfaceSagaStore<Object>- Parameters:
sagaType- The type of the SagasagaIdentifier- The identifier of the Sagasaga- The Saga instanceassociationValues- The initial association values of the Saga
-
setSerializer
Sets the Serializer instance to serialize Sagas with. Defaults to the XStream Serializer.- Parameters:
serializer- the Serializer instance to serialize Sagas with
-
createSchema
Creates the SQL Schema required to store Sagas and their associations.- Throws:
SQLException- when an error occurs preparing of executing the required statements
-