LogoLogo
timvero.comMaven Repository
  • timveroOS SDK guide
  • timveroOS how-to
  • timveroOS admin-side setup
  • Campaigns in timveroOS
    • 7.11
      • Business Context
      • Introduction
      • Core Concept
        • Entity Diagram
        • Lifecycle Diagram
        • Expression
      • Design and Development of the Campaign Model
        • Campaign model
        • Campaign repository
        • Campaign forms
        • Campaign сontroller
        • UI elements
        • Campaign actions
      • Design and Development of the CampaignExecution Model
        • CampaignExecution model
        • CampaignExecution repository
        • CampaignExecution controller
        • UI elements
      • Expression
      • Services
        • CampaignService
        • CampaignExecutionService
      • Campaign Processing
        • Producer
        • Consumer
      • Post-processing
        • Checker
Powered by GitBook
On this page

Was this helpful?

  1. Campaigns in timveroOS
  2. 7.11
  3. Design and Development of the CampaignExecution Model

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 methods

  • JpaSpecificationExecutor — filtering support via Spring Specifications

  • SynchronousAccessRepository — provides getSync(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 with CampaignExecutionConsumer.


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);
            }
        });
    });
PreviousCampaignExecution modelNextCampaignExecution controller

Last updated 18 days ago

Was this helpful?