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 interface
Performs an update operation on an entity within an optimistic lock aware transaction.static interface
Checks 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> T
doTransactionalOptimisticUpdate
(String name, OptimisticLockUtils.UpdateOperation<T> operation, Class<? extends T> entityClass, Object identifier, org.springframework.transaction.PlatformTransactionManager transactionManager, jakarta.persistence.EntityManager entityManager) 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) 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
OptimisticLockException
then the operation will be retried untilmaxRetryCount
is reached.If a
OptimisticLockUtils.ValidatedUpdateOperation
is passed as theoperation
parameter, 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
Version
annotation.- Throws:
OptimisticLockMaxRetryException
- if anOptimisticLockException
occursmaxRetryCount
times.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)
-