Class JpaCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
java.lang.Object
com.broadleafcommerce.subscription.provider.jpa.nontrackable.repository.JpaCustomizedSubscriptionLockRepository<D>
- Type Parameters:
D- The possibly extendedJpaSubscriptionLocktype
- All Implemented Interfaces:
CustomizedSubscriptionLockRepository<D>
public class JpaCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>
extends Object
implements CustomizedSubscriptionLockRepository<D>
-
Constructor Summary
ConstructorsConstructorDescriptionJpaCustomizedSubscriptionLockRepository(com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.transaction.support.TransactionTemplate template, SubscriptionLockProperties properties, org.springframework.context.ApplicationEventPublisher publisher) -
Method Summary
Modifier and TypeMethodDescriptionbooleanClear the lock.protected DconstructChildLock(String id, String childIdentifier) Construct a child lockprotected DconstructLock(String id, Duration expiryDuration) Construct a parent lockcreateChildLock(String id, String childIdentifier) Attempt to create a child lock on the subscription.createLock(String id, Integer reservationCount, List<String> reservationList, Duration expiryDuration) Attempt to create a top-level lock on the subscription.findSampleForPurge(String startingId) Find a sample of locks that are ready to be purged (max size is 100).getChildLocks(String id) Get all child locks for a parent lockprotected jakarta.persistence.EntityManagerprotected org.springframework.transaction.support.TransactionTemplateprotected com.broadleafcommerce.common.extension.TypeFactoryprotected voidRemove any child locks for the parent lockintunlockChild(String token, boolean propagate) Attempt to clear the child lock.
-
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
Description copied from interface:CustomizedSubscriptionLockRepositoryFind 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:
findSampleForPurgein interfaceCustomizedSubscriptionLockRepository<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
Description copied from interface:CustomizedSubscriptionLockRepositoryClear the lock. This is used to remove the lock from the system (including any child locks).- Specified by:
clearLockin interfaceCustomizedSubscriptionLockRepository<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:CustomizedSubscriptionLockRepositoryAttempt to create a top-level lock on the subscription.- Specified by:
createLockin interfaceCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>- Parameters:
id- The subscription idreservationCount- 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 useSubscriptionLockProperties.getSubscriptionLockExpiration().- Returns:
- The persisted lock entity, and any optional child locks reserved.
-
createChildLock
Description copied from interface:CustomizedSubscriptionLockRepositoryAttempt to create a child lock on the subscription.- Specified by:
createChildLockin interfaceCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>- Parameters:
id- The subscription idchildIdentifier- The identifier for the child lock. Optional. Will generate an identifier if null.- Returns:
- The persisted lock entity
-
unlockChild
Description copied from interface:CustomizedSubscriptionLockRepositoryAttempt to clear the child lock.- Specified by:
unlockChildin interfaceCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>- Parameters:
token- The token associated with the child lockpropagate- Whether to propagate the token unlock to the parent lock- Returns:
- The number of child locks remaining
-
getChildLocks
Description copied from interface:CustomizedSubscriptionLockRepositoryGet all child locks for a parent lock- Specified by:
getChildLocksin interfaceCustomizedSubscriptionLockRepository<D extends JpaSubscriptionLock>- Parameters:
id- The parent lock ID- Returns:
- The list of child locks
-
constructLock
Construct a parent lock- Parameters:
id- The primary key valueexpiryDuration- The duration of the lock. Optional.- Returns:
- The constructed lock
-
constructChildLock
Construct a child lock- Parameters:
id- The parent lock IDchildIdentifier- The identifier for the child lock. Optional. Will generate an identifier if null.- Returns:
- The constructed child lock
-
removeChildLocks
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()
-