Class JpaCustomizedPriceDataRepository<D extends JpaPriceData>
- All Implemented Interfaces:
CustomizedPriceDataRepository<D>
,org.springframework.beans.factory.InitializingBean
JpaPriceDataRepository
that includes custom JPA query methods.- Author:
- Nick Crum ncrum
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJpaCustomizedPriceDataRepository
(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addActiveDatesPredicate
(Instant instant, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root) protected void
addNotArchivedPredicate
(List<jakarta.persistence.criteria.Predicate> predicates, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root) protected void
addPriceListIdPredicate
(String priceListId, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root) protected void
addTargetTypePredicate
(String targetType, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root) void
protected void
applyRsqlCriteria
(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<?> nativeQuery, Map<String, Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates, Class<?> type) int
decrementAvailableQuantity
(String priceDataId, String priceListId, Instant usageDate, int quantityToDecrement, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Decrements thePriceData.getAvailableQuantity()
.org.springframework.data.domain.Page<D>
findByPriceListIdAndTarget
(String priceListId, String targetType, Collection<String> targetIds, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<D>
findByPriceListIdAndTarget
(String priceListId, String targetType, Collection<String> targetIds, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.findByTargetAndPriceListId
(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target, String priceListId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) findByTargetInAndPriceListIdsIn
(Collection<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> targets, Collection<String> priceListIds, boolean filterByVendor, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds a list of price data by the givenPriceableTargetRefs
and price list ids.findIdsByPriceListId
(AtomicReference<String> startingIdField, String priceListId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds a list ofJpaPriceData.get_id()
from the given starting id, pricelist id, filters, and paging details.protected com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder
protected jakarta.persistence.EntityManager
protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper
getPriceDataFromIds
(List<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected PriceDataRepository<D>
protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager
protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer>
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor
protected List<jakarta.persistence.criteria.Predicate>
getTermsPredicates
(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTargetRef ref, @NonNull jakarta.persistence.criteria.CriteriaBuilder builder, @NonNull jakarta.persistence.criteria.Root<D> topRoot, @NonNull Map<String, Object> params, Integer index) AddsPredicates
based on the incomingref's
explicit terms.protected jakarta.persistence.criteria.Predicate
getVendorRefPredicate
(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef targetRef, String vendorRefFieldName, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root, Map<String, Object> params) int
incrementAvailableQuantity
(String priceDataId, int quantityToIncrement, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Increments thePriceData.getAvailableQuantity()
, typically used as part of the rollback.readAllByPriceListId
(String priceListId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads allJpaPriceData
by the given price list id.void
setRepository
(PriceDataRepository<D> repository) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.pricing.repository.CustomizedPriceDataRepository
findByTargetInAndPriceListIdsIn
-
Field Details
-
PRICE_LIST_ID
- See Also:
-
CONTEXT_ID
- See Also:
-
TARGET_TYPE
- See Also:
-
TERM_DURATION_LENGTH
- See Also:
-
TERM_DURATION_TYPE
- See Also:
-
-
Constructor Details
-
JpaCustomizedPriceDataRepository
public JpaCustomizedPriceDataRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor)
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
findByPriceListIdAndTarget
@NonNull @Deprecated(since="1.7.2", forRemoval=true) public org.springframework.data.domain.Page<D> findByPriceListIdAndTarget(@Nullable String priceListId, @Nullable String targetType, Collection<String> targetIds, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
findByPriceListIdAndTarget
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
-
findByPriceListIdAndTarget
@NonNull public org.springframework.data.domain.Page<D> findByPriceListIdAndTarget(@Nullable String priceListId, @Nullable String targetType, Collection<String> targetIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findByPriceListIdAndTarget
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
-
findByTargetInAndPriceListIdsIn
@NonNull public List<D> findByTargetInAndPriceListIdsIn(@NonNull Collection<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> targets, @NonNull Collection<String> priceListIds, boolean filterByVendor, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedPriceDataRepository
Finds a list of price data by the givenPriceableTargetRefs
and price list ids.- Specified by:
findByTargetInAndPriceListIdsIn
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
- Parameters:
targets
- a list ofPriceableTargetRefs
to matchpriceListIds
- a list of price list ids to look forfilterByVendor
- whether to also filter the price data based on the {@link {@link PriceableTargetRef#getVendorRef()}contextInfo
- the current context- Returns:
- a list of price data by the given
PriceableTargetRefs
and price list ids
-
getTermsPredicates
protected List<jakarta.persistence.criteria.Predicate> getTermsPredicates(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.PriceableTargetRef ref, @NonNull @NonNull jakarta.persistence.criteria.CriteriaBuilder builder, @NonNull @NonNull jakarta.persistence.criteria.Root<D> topRoot, @NonNull @NonNull Map<String, Object> params, @Nullable Integer index) AddsPredicates
based on the incomingref's
explicit terms. -
getVendorRefPredicate
-
findByTargetAndPriceListId
@NonNull public Optional<D> findByTargetAndPriceListId(@NonNull com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target, @NonNull String priceListId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findByTargetAndPriceListId
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
-
readAllByPriceListId
public Stream<D> readAllByPriceListId(String priceListId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:CustomizedPriceDataRepository
Reads allJpaPriceData
by the given price list id.This method explicitly fetches the ids and then fetches the entities by the ids to avoid using the SQL
offset
for the sake of performance, which is used under the hood inJpaNarrowExecutor
when the query is a page query.- Specified by:
readAllByPriceListId
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
-
incrementAvailableQuantity
@Transactional("pricingTransactionManager") public int incrementAvailableQuantity(String priceDataId, int quantityToIncrement, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedPriceDataRepository
Increments thePriceData.getAvailableQuantity()
, typically used as part of the rollback.This method updates the quantity based on the current
PriceData.getAvailableQuantity()
to prevent causing stale data (e.g. read entity and then update the entity separately could cause the data to be stale).This method should be used to increment the
PriceData.getAvailableQuantity()
to prevent race condition and cause the quantity to be stale.- Specified by:
incrementAvailableQuantity
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
- Parameters:
priceDataId
- thePriceData.getId()
to incrementquantityToIncrement
- the quantity to incrementcontextInfo
- the context info- Returns:
- the count of records updated
-
decrementAvailableQuantity
@Transactional("pricingTransactionManager") public int decrementAvailableQuantity(String priceDataId, String priceListId, Instant usageDate, int quantityToDecrement, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedPriceDataRepository
Decrements thePriceData.getAvailableQuantity()
.This method only updates the quantity if the
PriceData.getAvailableQuantity()
is enough to cover thequantityToDecrement
.This method should be used to decrement the
PriceData.getAvailableQuantity()
to prevent race condition and decrement more quantity than actually available.- Specified by:
decrementAvailableQuantity
in interfaceCustomizedPriceDataRepository<D extends JpaPriceData>
- Parameters:
priceDataId
- thePriceData.getId()
to decrementpriceListId
- thePriceList.getId()
that it belongs tousageDate
- theInstant
used to check against the active start and end datesquantityToDecrement
- the quantity to decrementcontextInfo
- the context info- Returns:
- the count of records updated
-
findIdsByPriceListId
protected List<String> findIdsByPriceListId(AtomicReference<String> startingIdField, String priceListId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds a list ofJpaPriceData.get_id()
from the given starting id, pricelist id, filters, and paging details.The query uses the starting id condition and order by price list id and price data id for the sake of performance.
-
getPriceDataFromIds
-
applyRsqlCriteria
protected void applyRsqlCriteria(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<?> nativeQuery, Map<String, Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates, Class<?> type) -
addActiveDatesPredicate
-
addNotArchivedPredicate
protected void addNotArchivedPredicate(List<jakarta.persistence.criteria.Predicate> predicates, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root) -
addPriceListIdPredicate
-
addTargetTypePredicate
-
getManagedType
-
getJpaNarrowingHelper
protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper getJpaNarrowingHelper() -
getRepository
-
setRepository
-
getBehaviorUtil
protected com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil getBehaviorUtil() -
getCriteriaBuilder
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder getCriteriaBuilder() -
getRepositoryEntityTypeManager
protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager getRepositoryEntityTypeManager() -
getRsqlQueryTransformers
protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> getRsqlQueryTransformers() -
getRsqlVisitor
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor getRsqlVisitor() -
getEntityManager
protected jakarta.persistence.EntityManager getEntityManager()
-