Class JpaCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>

java.lang.Object
com.broadleafcommerce.subscription.provider.jpa.nontrackable.repository.JpaCustomizedSubscriptionLockRepository<D>
Type Parameters:
D - The possibly extended JpaSubscriptionLock type
All Implemented Interfaces:
CustomizedSubscriptionLockRepository<D>

public class JpaCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock> extends Object implements CustomizedSubscriptionLockRepository<D>
  • Constructor Details

    • JpaCustomizedSubscriptionLockRepository

      public JpaCustomizedSubscriptionLockRepository(com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.transaction.support.TransactionTemplate template, SubscriptionLockProperties properties, org.springframework.context.ApplicationEventPublisher publisher)
  • Method Details

    • findSampleForPurge

      public List<D> findSampleForPurge(@Nullable String startingId)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Find a sample of locks that are ready to be purged (max size is 100). Purging is used to remove orphaned locks that were not properly deleted as part of the normal lock lifecycle.
      Specified by:
      findSampleForPurge in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      startingId - The starting id to use for the query. If null, the query will start with the earliest id.
      Returns:
      The list of candidate locks to purge.
    • clearLock

      public boolean clearLock(D lock, boolean force, boolean isRevert)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Clear the lock. This is used to remove the lock from the system (including any child locks).
      Specified by:
      clearLock in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      lock - The top-level lock to clear.
      force - Whether to force the lock to be cleared, even if it is not expired.
      isRevert - Whether the lock is being cleared as part of a revert operation.
      Returns:
      true if the lock was successfully cleared, false otherwise.
    • createLock

      public List<D> createLock(String id, @Nullable Integer reservationCount, @Nullable List<String> reservationList, @Nullable Duration expiryDuration)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Attempt to create a top-level lock on the subscription.
      Specified by:
      createLock in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      id - The subscription id
      reservationCount - The number of child locks to reserve. Optional.
      reservationList - The list of child lock identifiers to reserve. Optional. If provided, will be favored over reservationCount.
      expiryDuration - The duration of the lock. Optional. Default is to use SubscriptionLockProperties.getSubscriptionLockExpiration().
      Returns:
      The persisted lock entity, and any optional child locks reserved.
    • createChildLock

      public D createChildLock(String id, @Nullable String childIdentifier)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Attempt to create a child lock on the subscription.
      Specified by:
      createChildLock in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      id - The subscription id
      childIdentifier - The identifier for the child lock. Optional. Will generate an identifier if null.
      Returns:
      The persisted lock entity
    • unlockChild

      public int unlockChild(String token, boolean propagate)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Attempt to clear the child lock.
      Specified by:
      unlockChild in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      token - The token associated with the child lock
      propagate - Whether to propagate the token unlock to the parent lock
      Returns:
      The number of child locks remaining
    • getChildLocks

      public List<D> getChildLocks(String id)
      Description copied from interface: CustomizedSubscriptionLockRepository
      Get all child locks for a parent lock
      Specified by:
      getChildLocks in interface CustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
      Parameters:
      id - The parent lock ID
      Returns:
      The list of child locks
    • constructLock

      protected D constructLock(String id, @Nullable Duration expiryDuration)
      Construct a parent lock
      Parameters:
      id - The primary key value
      expiryDuration - The duration of the lock. Optional.
      Returns:
      The constructed lock
    • constructChildLock

      protected D constructChildLock(String id, @Nullable String childIdentifier)
      Construct a child lock
      Parameters:
      id - The parent lock ID
      childIdentifier - The identifier for the child lock. Optional. Will generate an identifier if null.
      Returns:
      The constructed child lock
    • removeChildLocks

      protected void removeChildLocks(String id)
      Remove any child locks for the parent lock
      Parameters:
      id - The parent lock ID
    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getTemplate

      protected org.springframework.transaction.support.TransactionTemplate getTemplate()