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 voidaddActiveDatesPredicate(Instant instant, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root) protected voidaddNotArchivedPredicate(List<jakarta.persistence.criteria.Predicate> predicates, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root) protected voidaddPriceListIdPredicate(String priceListId, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root) protected voidaddTargetTypePredicate(String targetType, List<jakarta.persistence.criteria.Predicate> predicates, Map<String, Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root) voidprotected voidapplyRsqlCriteria(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) intdecrementAvailableQuantity(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 givenPriceableTargetRefsand 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.TrackableBehaviorUtilprotected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilderprotected jakarta.persistence.EntityManagerprotected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelpergetPriceDataFromIds(List<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected PriceDataRepository<D>protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManagerprotected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer>protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitorprotected 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) AddsPredicatesbased on the incomingref'sexplicit terms.protected jakarta.persistence.criteria.PredicategetVendorRefPredicate(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef targetRef, String vendorRefFieldName, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> root, Map<String, Object> params) intincrementAvailableQuantity(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 allJpaPriceDataby the given price list id.voidsetRepository(PriceDataRepository<D> repository) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
afterPropertiesSetin 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:
findByPriceListIdAndTargetin 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:
findByPriceListIdAndTargetin 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:CustomizedPriceDataRepositoryFinds a list of price data by the givenPriceableTargetRefsand price list ids.- Specified by:
findByTargetInAndPriceListIdsInin interfaceCustomizedPriceDataRepository<D extends JpaPriceData>- Parameters:
targets- a list ofPriceableTargetRefsto 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
PriceableTargetRefsand 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) AddsPredicatesbased on the incomingref'sexplicit 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:
findByTargetAndPriceListIdin 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:CustomizedPriceDataRepositoryReads allJpaPriceDataby the given price list id.This method explicitly fetches the ids and then fetches the entities by the ids to avoid using the SQL
offsetfor the sake of performance, which is used under the hood inJpaNarrowExecutorwhen the query is a page query.- Specified by:
readAllByPriceListIdin 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:CustomizedPriceDataRepositoryIncrements 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:
incrementAvailableQuantityin 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:CustomizedPriceDataRepositoryDecrements 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:
decrementAvailableQuantityin interfaceCustomizedPriceDataRepository<D extends JpaPriceData>- Parameters:
priceDataId- thePriceData.getId()to decrementpriceListId- thePriceList.getId()that it belongs tousageDate- theInstantused 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()
-