CampaignExecution repository
CampaignExecutionRepository
Purpose
CampaignExecutionRepository
is a JPA repository designed for accessing CampaignExecution
entities. It provides standard CRUD operations, specification-based filtering, and synchronous access in transactional scenarios.
Code Example
public interface CampaignExecutionRepository extends
JpaRepository<CampaignExecution, Long>,
JpaSpecificationExecutor<CampaignExecution>,
SynchronousAccessRepository<CampaignExecution, Long> {
@Query("select e.id from CampaignExecution e where e.status = 'NEW' order by e.id desc limit 1")
Optional<Long> findNewExecutionId();
}
Inherited Interfaces
JpaRepository
— standard CRUD methodsJpaSpecificationExecutor
— filtering support via Spring SpecificationsSynchronousAccessRepository
— providesgetSync(id)
method, which blocks reading until the end of the current transaction
SynchronousAccessRepository
is a timveroOS interface that guarantees consistent data access in multithreaded environments — especially important for use withCampaignExecutionConsumer
.
Key Method
@Query("select e.id from CampaignExecution e where e.status = 'NEW' order by e.id desc limit 1")
Optional<Long> findNewExecutionId();
This method is used by CampaignExecutionConsumer
to select the latest NEW
execution ready to be launched.
Usage Example
executionRepository.findNewExecutionId()
.ifPresent(id -> {
ttb.requiresNew().executeWithoutResult(s -> {
CampaignExecution execution = executionRepository.getSync(id);
if (execution.getStatus() == CampaignExecutionStatus.NEW) {
executionService.runExecution(execution);
}
});
});
Last updated
Was this helpful?