public class JpaCustomizedUserPermissionRepository<D extends JpaUserPermission> extends Object implements CustomizedUserPermissionRepository<D>
JpaUserPermissionRepository
.Constructor and Description |
---|
JpaCustomizedUserPermissionRepository(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> resourceLockRepository) |
Modifier and Type | Method and Description |
---|---|
protected javax.persistence.criteria.Predicate |
buildIdFilter(String entityId,
javax.persistence.criteria.Root<D> permissionEntity,
javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
Map<String,Object> parameterValues) |
D |
createOnlyIfDoesNotExist(D permission,
@NonNull Instant lastUpdated)
Since we have a pre-defined id we want to create the entity with, we cannot simply call
EntityManager.persist(Object) , since it will reject it as a "detached" entity. |
Class<D> |
getDomainType() |
protected UserPermissionRepository<D> |
getPermissionRepository() |
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> |
getResourceLockRepository() |
D |
replaceOnlyIfLastUpdatedBefore(@NonNull String entityId,
D permission,
@NonNull Instant lastUpdated)
A specialized replace operation that does not invoke the "save" create-or-update behavior.
|
void |
setRepository(UserPermissionRepository<D> repository) |
public JpaCustomizedUserPermissionRepository(com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> resourceLockRepository)
@Autowired public void setRepository(UserPermissionRepository<D> repository)
public Class<D> getDomainType()
getDomainType
in interface com.broadleafcommerce.common.extension.DomainTypeAware
@Nullable @Transactional public D createOnlyIfDoesNotExist(@NonNull D permission, @NonNull @NonNull Instant lastUpdated)
EntityManager.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 when
EntityManager.merge(Object)
is called.
createOnlyIfDoesNotExist
in interface CustomizedUserPermissionRepository<D extends JpaUserPermission>
permission
- the permission to createlastUpdated
- the UserPermission.lastUpdated
to set on the permissionnull
otherwise@Nullable @Transactional public D replaceOnlyIfLastUpdatedBefore(@NonNull @NonNull String entityId, @NonNull D permission, @NonNull @NonNull Instant lastUpdated)
CustomizedUserPermissionRepository
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.archived
value, even if it is true
.
replaceOnlyIfLastUpdatedBefore
in interface CustomizedUserPermissionRepository<D extends JpaUserPermission>
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 its UserPermission.lastUpdated
set to this value.null
if the
entity was not found or could not be updated due to its lastUpdated value.protected javax.persistence.criteria.Predicate buildIdFilter(String entityId, javax.persistence.criteria.Root<D> permissionEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository()
protected UserPermissionRepository<D> getPermissionRepository()
Copyright © 2021. All rights reserved.