Class JdbcProgressTracker

java.lang.Object
com.opencqrs.framework.eventhandler.progress.JdbcProgressTracker
All Implemented Interfaces:
ProgressTracker, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class JdbcProgressTracker extends Object implements ProgressTracker, org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle
ProgressTracker implementation using Spring JdbcOperations and TransactionOperations to persist Progress.
  • Field Details

  • Constructor Details

    • JdbcProgressTracker

      public JdbcProgressTracker(DataSource dataSource, org.springframework.transaction.PlatformTransactionManager platformTransactionManager)
      Initializes this progress tracker given a DataSource and a compliant PlatformTransactionManager.
      Parameters:
      dataSource - the data source to use for persisting Progress
      platformTransactionManager - the transaction manager used to persist and for proceed execution
  • Method Details

    • setCheckDatabaseOnStart

      public void setCheckDatabaseOnStart(boolean checkDatabaseOnStart)
      Configures, if the SQL database should be checked on startup, in order to be sure the tables have been created.
      Parameters:
      checkDatabaseOnStart - false if check shall be disabled (defaults to true)
    • setProceedTransactionally

      public void setProceedTransactionally(boolean proceedTransactionally)
      Configures whether the execution passed to proceed(String, long, Supplier) will be executed within the same transaction as this. If set to true all EventHandlers or EventHandling annotated methods executed during the event processing loop (for the same raw Event) will automatically participate in the same transaction, that is used to persist the new Progress. This assures atomicity, if and only if the participating event handlers operate only on resources managed by the configured PlatformTransactionManager, i.e. the DataSource resource.
      Parameters:
      proceedTransactionally - true (default) if event handlers shall participate in the same transaction
    • setTablePrefix

      public void setTablePrefix(String tablePrefix)
      Configures the SQL table prefix.
      Parameters:
      tablePrefix - the table prefix, defaults to "EVENTHANDLER_"
    • setFindQuery

      public void setFindQuery(String statement)
      Configures the SQL SELECT statement to query the current Progress. The statement may contain a single %s placeholder for the table prefix.
      Parameters:
      statement - the statement
    • setUpdateQuery

      public void setUpdateQuery(String statement)
      Configures the SQL UPDATE statement to update an existing Progress during proceed(String, long, Supplier). The statement may contain a single %s placeholder for the table prefix.
      Parameters:
      statement - the statement
    • setInsertQuery

      public void setInsertQuery(String statement)
      Configures the SQL INSERT statement to insert a new Progress during proceed(String, long, Supplier). The statement may contain a single %s placeholder for the table prefix.
      Parameters:
      statement - the statement
    • setCountAllQuery

      public void setCountAllQuery(String countAllQuery)
      Configures the SQL {code SELECT} statement used to check the database on start-up. The statement may contain a single %s placeholder for the table prefix.
      Parameters:
      countAllQuery - the statement
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • current

      public Progress current(String group, long partition)
      Description copied from interface: ProgressTracker
      Retrieves the current Progress for the specified event processing group and partition.
      Specified by:
      current in interface ProgressTracker
      Parameters:
      group - the processing group identifier
      partition - the partition number
      Returns:
      the current progress
    • proceed

      public void proceed(String group, long partition, Supplier<Progress> execution)
      Description copied from interface: ProgressTracker
      Proceeds the current Progress by executing the given Supplier, which in turn yields the new progress for the specified event processing group and partition.
      Specified by:
      proceed in interface ProgressTracker
      Parameters:
      group - the processing group identifier
      partition - the partition number
      execution - the supplier returning the new progress, if executed successfully