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 Campaign Model

Campaign repository

CampaignRepository

The CampaignRepository interface provides access to Campaign entities in the database. It extends several standard Spring Data interfaces and includes support for safe entity retrieval within a transaction using SynchronousAccessRepository.

Repository Example:

public interface CampaignRepository extends 
    JpaRepository<Campaign, Long>,
    JpaSpecificationExecutor<Campaign>,
    SynchronousAccessRepository<Campaign, Long> {

    @Query("select c.id from Campaign c where c.executionType = 'AUTOMATIC' and c.automaticCampaignStatus = 'SCHEDULED' and c.active = true")
    List<Long> findAutomaticScheduledCampaigns();
}

Inherited Interfaces:

  • JpaRepository — provides basic CRUD operations

  • JpaSpecificationExecutor — enables filtering support via CampaignFilter

  • SynchronousAccessRepository — a custom interface from timveroOS that provides the getSync(id) method: This method ensures the entity is retrieved with a lock until the current transaction completes — which is crucial for concurrent access scenarios (e.g., during automatic campaign executions)

Additional Methods:

    @Query("select c.id from Campaign c where c.executionType = 'AUTOMATIC' and c.automaticCampaignStatus = 'SCHEDULED' and c.active = true")
    List<Long> findAutomaticScheduledCampaigns();

This method is used by the CampaignExecutionProducer component to retrieve all active automatic campaigns scheduled for execution.

Usage Example:

Campaign campaign = campaignRepository.getSync(campaignId);

The getSync method ensures that the retrieved Campaign entity is synchronized with the current transaction — which is critical for components operating in a distributed environment or when using Shedlock.

PreviousCampaign modelNextCampaign forms

Last updated 1 month ago

Was this helpful?