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 TypeMethodDescriptionvoid
Retrieves the currentProgress
for the specified event processing group and partition.boolean
boolean
void
void
setCheckDatabaseOnStart
(boolean checkDatabaseOnStart) Configures, if the SQL database should be checked on startup, in order to be sure the tables have been created.void
setCountAllQuery
(String countAllQuery) Configures the SQL {code SELECT} statement used to check the database on start-up.void
setFindQuery
(String statement) void
setInsertQuery
(String statement) Configures the SQLINSERT
statement to insert a newProgress
duringproceed(String, long, Supplier)
.void
setProceedTransactionally
(boolean proceedTransactionally) Configures whether the execution passed toproceed(String, long, Supplier)
will be executed within the same transaction asthis
.void
setTablePrefix
(String tablePrefix) Configures the SQL table prefix.void
setUpdateQuery
(String statement) Configures the SQLUPDATE
statement to update an existingProgress
duringproceed(String, long, Supplier)
.void
start()
void
stop()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 persistingProgress
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 totrue
)
-
setProceedTransactionally
public void setProceedTransactionally(boolean proceedTransactionally) Configures whether the execution passed toproceed(String, long, Supplier)
will be executed within the same transaction asthis
. If set totrue
allEventHandler
s orEventHandling
annotated methods executed during the event processing loop (for the same rawEvent
) will automatically participate in the same transaction, that is used to persist the newProgress
. This assures atomicity, if and only if the participating event handlers operate only on resources managed by the configuredPlatformTransactionManager
, i.e. theDataSource
resource.- Parameters:
proceedTransactionally
-true
(default) if event handlers shall participate in the same transaction
-
setTablePrefix
Configures the SQL table prefix.- Parameters:
tablePrefix
- the table prefix, defaults to "EVENTHANDLER_"
-
setFindQuery
Configures the SQLSELECT
statement to query the currentProgress
. The statement may contain a single %s placeholder for the table prefix.- Parameters:
statement
- the statement
-
setUpdateQuery
Configures the SQLUPDATE
statement to update an existingProgress
duringproceed(String, long, Supplier)
. The statement may contain a single %s placeholder for the table prefix.- Parameters:
statement
- the statement
-
setInsertQuery
Configures the SQLINSERT
statement to insert a newProgress
duringproceed(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:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
current
Description copied from interface:ProgressTracker
Retrieves the currentProgress
for the specified event processing group and partition.- Specified by:
current
in interfaceProgressTracker
- Parameters:
group
- the processing group identifierpartition
- the partition number- Returns:
- the current progress
-
proceed
Description copied from interface:ProgressTracker
Proceeds the currentProgress
by executing the givenSupplier
, which in turn yields the new progress for the specified event processing group and partition.- Specified by:
proceed
in interfaceProgressTracker
- Parameters:
group
- the processing group identifierpartition
- the partition numberexecution
- the supplier returning the new progress, if executed successfully
-