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 Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionJdbcProgressTracker(DataSource dataSource, org.springframework.transaction.PlatformTransactionManager platformTransactionManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidRetrieves the currentProgressfor the specified event processing group and partition.booleanbooleanvoidvoidsetCheckDatabaseOnStart(boolean checkDatabaseOnStart) Configures, if the SQL database should be checked on startup, in order to be sure the tables have been created.voidsetCountAllQuery(String countAllQuery) Configures the SQL {code SELECT} statement used to check the database on start-up.voidsetFindQuery(String statement) voidsetInsertQuery(String statement) Configures the SQLINSERTstatement to insert a newProgressduringproceed(String, long, Supplier).voidsetProceedTransactionally(boolean proceedTransactionally) Configures whether the execution passed toproceed(String, long, Supplier)will be executed transactionally.voidsetTablePrefix(String tablePrefix) Configures the SQL table prefix.voidsetUpdateQuery(String statement) Configures the SQLUPDATEstatement to update an existingProgressduringproceed(String, long, Supplier).voidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, stop
-
Field Details
-
DEFAULT_TABLE_PREFIX
- See Also:
-
-
Constructor Details
-
JdbcProgressTracker
public JdbcProgressTracker(DataSource dataSource, org.springframework.transaction.PlatformTransactionManager platformTransactionManager) - Parameters:
dataSource- the data source to use for persistingProgressplatformTransactionManager- 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-falseif check shall be disabled (defaults totrue)
-
setProceedTransactionally
public void setProceedTransactionally(boolean proceedTransactionally) Configures whether the execution passed toproceed(String, long, Supplier)will be executed transactionally. If set totrueallEventHandlers orEventHandlingannotated methods executed within the event processing loop (for the same rawEvent) will be executed transactionally within the same transaction, that is used to retrieve and update the event processing progress. This guarantees atomicity and idempotency, if and only if all participating event handlers operate only on resources managed by the configuredPlatformTransactionManager, i.e. theDataSourceresource.- Parameters:
proceedTransactionally-trueif event handlers shall participate in the same transaction, defaults tofalseotherwise
-
setTablePrefix
Configures the SQL table prefix.- Parameters:
tablePrefix- the table prefix, defaults to "EVENTHANDLER_"
-
setFindQuery
Configures the SQLSELECTstatement to query the currentProgress. The statement may contain a single %s placeholder for the table prefix.- Parameters:
statement- the statement
-
setUpdateQuery
Configures the SQLUPDATEstatement to update an existingProgressduringproceed(String, long, Supplier). The statement may contain a single %s placeholder for the table prefix.- Parameters:
statement- the statement
-
setInsertQuery
Configures the SQLINSERTstatement to insert a newProgressduringproceed(String, long, Supplier). The statement may contain a single %s placeholder for the table prefix.- Parameters:
statement- the statement
-
setCountAllQuery
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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
current
Description copied from interface:ProgressTrackerRetrieves the currentProgressfor the specified event processing group and partition.- Specified by:
currentin interfaceProgressTracker- Parameters:
group- the processing group identifierpartition- the partition number- Returns:
- the current progress
-
proceed
Description copied from interface:ProgressTrackerProceeds the currentProgressby executing the givenSupplier, which in turn yields the new progress for the specified event processing group and partition.- Specified by:
proceedin interfaceProgressTracker- Parameters:
group- the processing group identifierpartition- the partition numberexecution- the supplier returning the new progress, if executed successfully
-