Class SandboxNotificationPruneRepository

java.lang.Object
com.broadleafcommerce.sandbox.repository.nontrackable.SandboxNotificationPruneRepository

public class SandboxNotificationPruneRepository extends Object
This "repo" is responsible to delete "stale" notification states Expected to work with SandboxNotificationPruneService
  • Constructor Details

    • SandboxNotificationPruneRepository

      public SandboxNotificationPruneRepository(SandboxNotificationPruneProperties sandboxPruneNotificationProperties, org.springframework.transaction.support.TransactionTemplate transactionTemplate)
  • Method Details

    • pruneDormantNotificationStates

      public void pruneDormantNotificationStates()

      NotificationAwareDomainMapperMember eagerly creates a lot of 'dormant' NotificationStates that are only initialized for send when a transition operation is requested for their parent entities. This eager creation makes subsequent updates to initialize the NotificationState efficient, but it also means that if a particular transition is never engaged for a particular entity, the NotificationState will remain in the datastore forever and lead to buildup. For example, the state for RejectionProducer.TYPE is eagerly created but if a 'reject' is never engaged for a summary, then that NotificationState will remain 'dormant'.

      These 'dormant' states will not be pruned by StandaloneCleanupRepository.pruneRestingNotificationStates(Duration), because the dormant states have NotificationState.isStopped() set to false and NotificationState.getChangeTimestamp() set to null, and are therefore never included its standard purge criteria.

      Thus, we need this specialized prune logic that will find and remove these states, which is what this method does. The SandboxNotificationPruneProperties.getOutdatedDataAgeCutoff() should inform the cutoff. Typically, this cutoff is more aggressive than PruneRestingNotificationStatesConfigurationProperties.getOutdatedDataAgeCutoff() to minimize the buildup of bloat.

      Note that we can safely purge notification states here without worry because each of the transition flows are resilient and will create the notification state they need if it does not already exist. For example, even if we purge a RejectionProducer.TYPE notification state, a subsequent reject transition request for the parent summary would still work because the transition flow would newly create the RejectionProducer.TYPE on-demand.

    • generateUlidForPruneThresholdTimestamp

      protected String generateUlidForPruneThresholdTimestamp()
      Returns:
      a ULID whose timestamp encoding matches the prune threshold defined in SandboxNotificationPruneProperties.getOutdatedDataAgeCutoff(). This ULID can be compared against existing IDs in the datastore to serve as the boundary marker on what is/isn't pruned.
    • findDeleteBatchUpperBoundId

      @Nullable protected String findDeleteBatchUpperBoundId(@Nullable String batchLowerBoundId, String pruneThresholdUlid)
    • buildPruneableCandidateFetchingFilters

      protected jakarta.persistence.criteria.Predicate buildPruneableCandidateFetchingFilters(jakarta.persistence.criteria.CriteriaBuilder cb, jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, Map<String,Object> queryParams, String pruneThresholdUlid)
    • buildIdLessThanPruneThresholdFilter

      protected jakarta.persistence.criteria.Predicate buildIdLessThanPruneThresholdFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb, Map<String,Object> params, String pruneThresholdParameterName, String pruneThresholdUlid)
    • buildAckedFalseFilter

      protected jakarta.persistence.criteria.Predicate buildAckedFalseFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb)
    • buildStoppedFalseFilter

      protected jakarta.persistence.criteria.Predicate buildStoppedFalseFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb)
    • buildChangeTimestampNullFilter

      protected jakarta.persistence.criteria.Predicate buildChangeTimestampNullFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb)
    • buildIdGreaterThanBatchLowerBoundFilter

      protected jakarta.persistence.criteria.Predicate buildIdGreaterThanBatchLowerBoundFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb, Map<String,Object> params, String batchLowerBoundIdParameterName, String batchLowerBoundId)
    • deleteWithinBatchBounds

      protected int deleteWithinBatchBounds(@Nullable String batchLowerBoundId, String batchUpperBoundId, String pruneThresholdUlid)
    • buildIdLessThanOrEqualToBatchUpperBoundFilter

      protected jakarta.persistence.criteria.Predicate buildIdLessThanOrEqualToBatchUpperBoundFilter(jakarta.persistence.criteria.Root<com.broadleafcommerce.data.tracking.jpa.filtering.domain.JpaNotificationState> root, jakarta.persistence.criteria.CriteriaBuilder cb, Map<String,Object> params, String batchUpperBoundIdParameterName, String batchUpperBoundId)
    • pauseBetweenBatches

      protected void pauseBetweenBatches()
    • getSandboxPruneNotificationProperties

      protected SandboxNotificationPruneProperties getSandboxPruneNotificationProperties()
    • getTransactionTemplate

      protected org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()