Class OptimisticLockUtils
java.lang.Object
org.broadleafcommerce.common.util.OptimisticLockUtils
Utility class for operations on entities that support optimistic locking.
- Author:
- Philip Baggett (pbaggett)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePerforms an update operation on an entity within an optimistic lock aware transaction.static interfaceChecks if the state of the entity is valid then performs an update operation on an entity within an optimistic lock aware transaction. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static <T> TdoTransactionalOptimisticUpdate(String name, OptimisticLockUtils.UpdateOperation<T> operation, Class<? extends T> entityClass, Object identifier, org.springframework.transaction.PlatformTransactionManager transactionManager, jakarta.persistence.EntityManager entityManager) static <T> TperformOptimisticLockUpdate(String name, OptimisticLockUtils.UpdateOperation<T> operation, Class<? extends T> entityClass, Object identifier, int maxRetryCount, org.springframework.transaction.PlatformTransactionManager transactionManager, jakarta.persistence.EntityManager entityManager) Perform an update on a entity that supports optimistic locking.
-
Constructor Details
-
OptimisticLockUtils
public OptimisticLockUtils()
-
-
Method Details
-
performOptimisticLockUpdate
public static <T> T performOptimisticLockUpdate(String name, OptimisticLockUtils.UpdateOperation<T> operation, Class<? extends T> entityClass, Object identifier, int maxRetryCount, org.springframework.transaction.PlatformTransactionManager transactionManager, jakarta.persistence.EntityManager entityManager) throws OptimisticLockMaxRetryException, OptimisticLockInvalidStateException Perform an update on a entity that supports optimistic locking.This method will read the entity from the database, perform the update operation provided, and attempt to commit the transaction. If the transaction cannot be committed due to an
OptimisticLockExceptionthen the operation will be retried untilmaxRetryCountis reached.If a
OptimisticLockUtils.ValidatedUpdateOperationis passed as theoperationparameter, then theOptimisticLockUtils.ValidatedUpdateOperation.isValid(Object)method will be called after the read but before the update. If this call returns false, then the update will abort with aOptimisticLockInvalidStateException.Optimistic locking can be enabled on an entity by adding a variable with the
Versionannotation.- Throws:
OptimisticLockMaxRetryException- if anOptimisticLockExceptionoccursmaxRetryCounttimes.OptimisticLockInvalidStateException- if the entity state is found to be invalid due toOptimisticLockUtils.ValidatedUpdateOperation.isValid(Object)returning false.
-
doTransactionalOptimisticUpdate
protected static <T> T doTransactionalOptimisticUpdate(String name, OptimisticLockUtils.UpdateOperation<T> operation, Class<? extends T> entityClass, Object identifier, org.springframework.transaction.PlatformTransactionManager transactionManager, jakarta.persistence.EntityManager entityManager)
-