Class JpaCustomizedPriceDataRepository<D extends JpaPriceData>

java.lang.Object
com.broadleafcommerce.pricing.provider.jpa.repository.JpaCustomizedPriceDataRepository<D>
All Implemented Interfaces:
CustomizedPriceDataRepository<D>, org.springframework.beans.factory.InitializingBean

public class JpaCustomizedPriceDataRepository<D extends JpaPriceData> extends Object implements CustomizedPriceDataRepository<D>, org.springframework.beans.factory.InitializingBean
Repository fragment for JpaPriceDataRepository that includes custom JPA query methods.
Author:
Nick Crum ncrum
See Also:
  • Field Details

  • 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 interface org.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 interface CustomizedPriceDataRepository<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 interface CustomizedPriceDataRepository<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 given PriceableTargetRefs and price list ids.
      Specified by:
      findByTargetInAndPriceListIdsIn in interface CustomizedPriceDataRepository<D extends JpaPriceData>
      Parameters:
      targets - a list of PriceableTargetRefs to match
      priceListIds - a list of price list ids to look for
      filterByVendor - 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)
      Adds Predicates based on the incoming ref's explicit terms.
    • getVendorRefPredicate

      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)
    • 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 interface CustomizedPriceDataRepository<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 all JpaPriceData 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 in JpaNarrowExecutor when the query is a page query.

      Specified by:
      readAllByPriceListId in interface CustomizedPriceDataRepository<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 the PriceData.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 interface CustomizedPriceDataRepository<D extends JpaPriceData>
      Parameters:
      priceDataId - the PriceData.getId() to increment
      quantityToIncrement - the quantity to increment
      contextInfo - 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 the PriceData.getAvailableQuantity().

      This method only updates the quantity if the PriceData.getAvailableQuantity() is enough to cover the quantityToDecrement.

      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 interface CustomizedPriceDataRepository<D extends JpaPriceData>
      Parameters:
      priceDataId - the PriceData.getId() to decrement
      priceListId - the PriceList.getId() that it belongs to
      usageDate - the Instant used to check against the active start and end dates
      quantityToDecrement - the quantity to decrement
      contextInfo - 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 of JpaPriceData.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

      protected List<D> getPriceDataFromIds(List<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • 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

      protected void addActiveDatesPredicate(Instant instant, List<jakarta.persistence.criteria.Predicate> predicates, Map<String,Object> params, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root)
    • addNotArchivedPredicate

      protected void addNotArchivedPredicate(List<jakarta.persistence.criteria.Predicate> predicates, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<?> root)
    • addPriceListIdPredicate

      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)
    • addTargetTypePredicate

      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)
    • getManagedType

      protected Class<D> getManagedType()
    • getJpaNarrowingHelper

      protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper getJpaNarrowingHelper()
    • getRepository

      protected PriceDataRepository<D> getRepository()
    • setRepository

      @Autowired @Lazy public void setRepository(PriceDataRepository<D> repository)
    • 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()