Class GenericSagaSqlSchema

java.lang.Object
org.axonframework.modelling.saga.repository.jdbc.GenericSagaSqlSchema
All Implemented Interfaces:
SagaSqlSchema
Direct Known Subclasses:
HsqlSagaSqlSchema, Oracle11SagaSqlSchema, PostgresSagaSqlSchema

public class GenericSagaSqlSchema extends Object implements SagaSqlSchema
Generic SagaSqlSchema implementation, for use in most databases. This implementation can be overridden to account for differences in dialect between database implementations.
Since:
2.2
Author:
Kristian Rosenvold, Allard Buijze
  • Field Details

    • sagaSchema

      protected final SagaSchema sagaSchema
  • Constructor Details

    • GenericSagaSqlSchema

      public GenericSagaSqlSchema()
      Initialize a GenericSagaSqlSchema using default settings.
    • GenericSagaSqlSchema

      public GenericSagaSqlSchema(SagaSchema sagaSchema)
      Initialize a GenericSagaSqlSchema.

      Serialized data is stored using the given sagaSchema.

      Parameters:
      sagaSchema - The configuration to use for the initialization of the schema
  • Method Details

    • sql_loadSaga

      public PreparedStatement sql_loadSaga(Connection connection, String sagaId) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that loads a single Saga, with given sagaId.
      Specified by:
      sql_loadSaga in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaId - The identifier of the Saga to return
      Returns:
      a statement, that creates a result set to be processed by SagaSqlSchema.readSerializedSaga(java.sql.ResultSet), when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_removeAssocValue

      public PreparedStatement sql_removeAssocValue(Connection connection, String key, String value, String sagaType, String sagaIdentifier) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that removes an association value for given sagaIdentifier, where the association is identified with given key and value.
      Specified by:
      sql_removeAssocValue in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      key - The key of the association to remove
      value - The value of the association to remove
      sagaType - The type of saga to remove the association for
      sagaIdentifier - The identifier of the Saga to remove the association for
      Returns:
      a statement that removes the association value, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_storeAssocValue

      public PreparedStatement sql_storeAssocValue(Connection connection, String key, String value, String sagaType, String sagaIdentifier) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that stores an association with given key and value, for a Saga of given type and identifier.
      Specified by:
      sql_storeAssocValue in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      key - The key of the association to store
      value - The value of the association to store
      sagaType - The type of saga to create the association for
      sagaIdentifier - The identifier of the Saga to create the association for
      Returns:
      a statement that inserts the association value, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_findAssocSagaIdentifiers

      public PreparedStatement sql_findAssocSagaIdentifiers(Connection connection, String key, String value, String sagaType) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that finds identifiers of Sagas of given sagaType associated with the given association key and value.
      Specified by:
      sql_findAssocSagaIdentifiers in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      key - The key of the association
      value - The value of the association
      sagaType - The type of saga to find associations for
      Returns:
      a PreparedStatement that creates a ResultSet containing only saga identifiers when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_findAssociations

      public PreparedStatement sql_findAssociations(Connection connection, String sagaIdentifier, String sagaType) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that finds the associations of a Saga of given sagaType and given sagaIdentifier.
      Specified by:
      sql_findAssociations in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaIdentifier - The identifier of the Saga
      sagaType - The type of saga to find associations for
      Returns:
      a PreparedStatement that creates a ResultSet containing association keys and their values
      Throws:
      SQLException - when an error occurs while creating the PreparedStatement
    • readToken

      public String readToken(ResultSet resultSet)
      Description copied from interface: SagaSqlSchema
      Reads a token from the given resultSet.
      Specified by:
      readToken in interface SagaSqlSchema
      Parameters:
      resultSet - The result set to read data from.
      Returns:
      the token from the resultSet
    • readAssociationValues

      public Set<AssociationValue> readAssociationValues(ResultSet resultSet) throws SQLException
      Description copied from interface: SagaSqlSchema
      Reads a Set of AssociationValues from the given resultSet, which has been returned by executing the Statement returned from SagaSqlSchema.sql_findAssociations(Connection, String, String).
      Specified by:
      readAssociationValues in interface SagaSqlSchema
      Parameters:
      resultSet - The result set to read data from.
      Returns:
      a Set of AssociationValues from the resultSet
      Throws:
      SQLException - when an exception occurs reading from the resultSet
    • sql_deleteSagaEntry

      public PreparedStatement sql_deleteSagaEntry(Connection connection, String sagaIdentifier) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that deletes a Saga with given sagaIdentifier.
      Specified by:
      sql_deleteSagaEntry in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaIdentifier - The identifier of the Saga to remove
      Returns:
      a statement that deletes the Saga, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_deleteAssociationEntries

      public PreparedStatement sql_deleteAssociationEntries(Connection connection, String sagaIdentifier) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that deletes all association entries for a Saga with given sagaIdentifier.
      Specified by:
      sql_deleteAssociationEntries in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaIdentifier - The identifier of the Saga to remove associations for
      Returns:
      a statement that deletes the associations, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_updateSaga

      public PreparedStatement sql_updateSaga(Connection connection, String sagaIdentifier, byte[] serializedSaga, String sagaType, String revision) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that updates the serialized form of an existing Saga entry, of given sagaType and with given sagaIdentifier.
      Specified by:
      sql_updateSaga in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaIdentifier - The identifier of the Saga to update
      serializedSaga - The serialized form of the saga to update
      sagaType - The serialized type of the saga
      revision - The revision identifier of the serialized form
      Returns:
      a statement that updates a Saga entry, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_storeSaga

      public PreparedStatement sql_storeSaga(Connection connection, String sagaIdentifier, String revision, String sagaType, byte[] serializedSaga) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that inserts a Saga entry, of given sagaType and with given sagaIdentifier.
      Specified by:
      sql_storeSaga in interface SagaSqlSchema
      Parameters:
      connection - The connection to create the PreparedStatement for
      sagaIdentifier - The identifier of the Saga to insert
      revision - The revision identifier of the serialized form
      sagaType - The serialized type of the saga
      serializedSaga - The serialized form of the saga to insert
      Returns:
      a statement that inserts a Saga entry, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_createTableAssocValueEntry

      public PreparedStatement sql_createTableAssocValueEntry(Connection conn) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that creates the table for storing Association Values for Sagas.
      Specified by:
      sql_createTableAssocValueEntry in interface SagaSqlSchema
      Parameters:
      conn - The connection to create the PreparedStatement for
      Returns:
      a Prepared statement that created the Association Value table, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • sql_createTableSagaEntry

      public PreparedStatement sql_createTableSagaEntry(Connection conn) throws SQLException
      Description copied from interface: SagaSqlSchema
      Creates a PreparedStatement that creates the table for storing Sagas.
      Specified by:
      sql_createTableSagaEntry in interface SagaSqlSchema
      Parameters:
      conn - The connection to create the PreparedStatement for
      Returns:
      a Prepared statement that created the Saga table, when executed
      Throws:
      SQLException - when an error occurs creating the PreparedStatement
    • readSerializedSaga

      public SerializedObject<byte[]> readSerializedSaga(ResultSet resultSet) throws SQLException
      Description copied from interface: SagaSqlSchema
      Reads a SerializedObject from the given resultSet, which has been returned by executing the Statement returned from SagaSqlSchema.sql_loadSaga(java.sql.Connection, String)

      Note: The implementation must not change the resultSet's cursor position

      Specified by:
      readSerializedSaga in interface SagaSqlSchema
      Parameters:
      resultSet - The result set to read data from.
      Returns:
      a SerializedObject, containing the serialized data from the resultSet
      Throws:
      SQLException - when an exception occurs reading from the resultSet
    • sagaSchema

      public SagaSchema sagaSchema()
      Returns the SagaSchema used to configure this sql saga schema.
      Returns:
      the saga schema