Class JpaCustomizedUserPermissionRepository<D extends JpaUserPermission>
java.lang.Object
com.broadleafcommerce.auth.security.provider.jpa.repository.JpaCustomizedUserPermissionRepository<D>
- All Implemented Interfaces:
CustomizedUserPermissionRepository<D>,com.broadleafcommerce.common.extension.DomainTypeAware
public class JpaCustomizedUserPermissionRepository<D extends JpaUserPermission>
extends Object
implements CustomizedUserPermissionRepository<D>
Additional functionality necessary for
JpaUserPermissionRepository.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorsConstructorDescriptionJpaCustomizedUserPermissionRepository(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository) -
Method Summary
Modifier and TypeMethodDescriptionprotected javax.persistence.criteria.PredicatebuildIdFilter(String entityId, javax.persistence.criteria.Root<D> permissionEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) createOnlyIfDoesNotExist(D permission, @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 UserPermissionRepository<D>protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> replaceOnlyIfLastUpdatedBefore(@NonNull String entityId, D permission, @NonNull Instant lastUpdated) A specialized replace operation that does not invoke the "save" create-or-update behavior.voidsetRepository(UserPermissionRepository<D> repository)
-
Constructor Details
-
JpaCustomizedUserPermissionRepository
public JpaCustomizedUserPermissionRepository(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository)
-
-
Method Details
-
setRepository
-
getDomainType
- Specified by:
getDomainTypein interfacecom.broadleafcommerce.common.extension.DomainTypeAware
-
createOnlyIfDoesNotExist
@Nullable @Transactional public D createOnlyIfDoesNotExist(@NonNull D permission, @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
ResourceLockRepositoryto lock the requested ID and ensure competing concurrent invocations of this method will not overwrite each other whenEntityManager.merge(Object)is called.- Specified by:
createOnlyIfDoesNotExistin interfaceCustomizedUserPermissionRepository<D extends JpaUserPermission>- Parameters:
permission- the permission to createlastUpdated- theUserPermission.lastUpdatedto set on the permission- Returns:
- the entity if successfully created,
nullotherwise
-
replaceOnlyIfLastUpdatedBefore
@Nullable @Transactional public D replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull D permission, @NonNull @NonNull Instant lastUpdated) Description copied from interface:CustomizedUserPermissionRepositoryA 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
UserPermission.archived.Note that this method should also set the provided
UserPermission.archivedvalue, even if it istrue.- Specified by:
replaceOnlyIfLastUpdatedBeforein interfaceCustomizedUserPermissionRepository<D extends JpaUserPermission>- Parameters:
entityId- the id of the entity to replacepermission- 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 itsUserPermission.lastUpdatedset to this value.- Returns:
- the permission after replacement if successfully replaced, or
nullif 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() -
getPermissionRepository
-