Class JpaCustomizedRoleRepository<D extends JpaUserRole>
java.lang.Object
com.broadleafcommerce.auth.security.provider.jpa.repository.JpaCustomizedRoleRepository<D>
- All Implemented Interfaces:
CustomizedRoleRepository<D>
,com.broadleafcommerce.common.extension.DomainTypeAware
public class JpaCustomizedRoleRepository<D extends JpaUserRole>
extends Object
implements CustomizedRoleRepository<D>
Additional functionality necessary for
JpaRoleRepository
.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorDescriptionJpaCustomizedRoleRepository
(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository) -
Method Summary
Modifier and TypeMethodDescriptionprotected jakarta.persistence.criteria.Predicate
buildIdFilter
(String entityId, jakarta.persistence.criteria.Root<D> roleEntity, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) createOnlyIfDoesNotExist
(D role, @NonNull Instant lastUpdated) Since we have a pre-defined id we want to create the entity with, we cannot simply callEntityManager.persist(Object)
, since it will reject it as a "detached" entity.protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,
?> protected RoleRepository<D>
replaceOnlyIfLastUpdatedBefore
(@NonNull String entityId, D role, @NonNull Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.void
setRepository
(RoleRepository<D> repository)
-
Constructor Details
-
JpaCustomizedRoleRepository
public JpaCustomizedRoleRepository(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository)
-
-
Method Details
-
setRepository
-
getDomainType
- Specified by:
getDomainType
in interfacecom.broadleafcommerce.common.extension.DomainTypeAware
-
createOnlyIfDoesNotExist
@Nullable @Transactional public D createOnlyIfDoesNotExist(@NonNull D role, @NonNull @NonNull Instant lastUpdated) Since we have a pre-defined id we want to create the entity with, we cannot simply callEntityManager.persist(Object)
, since it will reject it as a "detached" entity.Thus, we will rely on
ResourceLockRepository
to lock the requested ID and ensure competing concurrent invocations of this method will not overwrite each other whenEntityManager.merge(Object)
is called.- Specified by:
createOnlyIfDoesNotExist
in interfaceCustomizedRoleRepository<D extends JpaUserRole>
- Parameters:
role
- the role to createlastUpdated
- theUserRole.lastUpdated
to set on the role- Returns:
- the entity if successfully created,
null
otherwise
-
replaceOnlyIfLastUpdatedBefore
@Nullable @Transactional public D replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull D role, @NonNull @NonNull Instant lastUpdated) Description copied from interface:CustomizedRoleRepository
A specialized replace operation that does not invoke the "save" create-or-update behavior. This operation should directly attempt an atomic update that the data store will reject if the entity is not found or has a lastUpdated ahead of the current change.This is intended to be used in concurrent scenarios where only one operation should succeed.
Note that this update should succeed even if the existing record is
UserRole.archived
.Note that this method should also set the provided
UserRole.archived
value, even if it istrue
.- Specified by:
replaceOnlyIfLastUpdatedBefore
in interfaceCustomizedRoleRepository<D extends JpaUserRole>
- Parameters:
entityId
- the id of the entity to replacerole
- the replacement entitylastUpdated
- the timestamp of the current change. This will be compared to the lastUpdated on the existing entity for determination of whether the replacement should occur. Furthermore, the replacement will have itsUserRole.lastUpdated
set to this value.- Returns:
- the role after replacement if successfully replaced, or
null
if the entity was not found or could not be updated due to its lastUpdated value.
-
buildIdFilter
-
getResourceLockRepository
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository() -
getRoleRepository
-