Class ProductDaoImpl

java.lang.Object
org.broadleafcommerce.core.catalog.dao.ProductDaoImpl
All Implemented Interfaces:
ProductDao

@Repository("blProductDao") public class ProductDaoImpl extends Object implements ProductDao
Author:
Jeff Fischer, Andre Azzolini (apazzolini)
  • Field Details

    • em

      protected jakarta.persistence.EntityManager em
    • entityConfiguration

      protected org.broadleafcommerce.common.persistence.EntityConfiguration entityConfiguration
    • sandBoxHelper

      protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper
    • extensionManager

      protected ProductDaoExtensionManager extensionManager
    • currentDateResolution

      @Value("${query.dateResolution.product:10000}") protected Long currentDateResolution
    • productTypeSiteMapExtensionManager

      protected SiteMapExtensionManager productTypeSiteMapExtensionManager
    • cachedDate

      protected Date cachedDate
  • Constructor Details

    • ProductDaoImpl

      public ProductDaoImpl()
  • Method Details

    • save

      public Product save(Product product)
      Description copied from interface: ProductDao
      Persist a Product instance to the datastore
      Specified by:
      save in interface ProductDao
      Parameters:
      product - the product instance
      Returns:
      the updated state of the product instance after being persisted
    • readProductById

      public Product readProductById(Long productId)
      Description copied from interface: ProductDao
      Retrieve a Product instance by its primary key
      Specified by:
      readProductById in interface ProductDao
      Parameters:
      productId - the primary key of the product
      Returns:
      the product instance at the specified primary key
    • readProductByExternalId

      public Product readProductByExternalId(String externalId)
      Specified by:
      readProductByExternalId in interface ProductDao
    • readProductsByIds

      public List<Product> readProductsByIds(List<Long> productIds)
      Description copied from interface: ProductDao
      Retrieves a list of Product instances by their primary keys
      Specified by:
      readProductsByIds in interface ProductDao
      Parameters:
      productIds - the list of primary keys for products
      Returns:
      the list of products specified by the primary keys
    • readProductsByName

      public List<Product> readProductsByName(String searchName)
      Description copied from interface: ProductDao
      Find all Product instances whose name starts with or is equal to the passed in search parameter
      Specified by:
      readProductsByName in interface ProductDao
      Parameters:
      searchName - the partial or whole name to match
      Returns:
      the list of product instances that were search hits
    • readProductsByName

      public List<Product> readProductsByName(@Nonnull String searchName, @Nonnull int limit, @Nonnull int offset)
      Description copied from interface: ProductDao
      Find a subset of Product instances whose name starts with or is equal to the passed in search parameter. Res
      Specified by:
      readProductsByName in interface ProductDao
      limit - the maximum number of results
      offset - the starting point in the record set
      Returns:
      the list of product instances that fit the search criteria
    • readActiveProductsByCategory

      public List<Product> readActiveProductsByCategory(Long categoryId)
      Description copied from interface: ProductDao
      Find all products whose in the passed in category.
      Specified by:
      readActiveProductsByCategory in interface ProductDao
      Parameters:
      categoryId - the primary key of the category to whom the resulting product list should be related
      Returns:
      the list of products qualified for the category and date
    • readActiveProductsByCategoryInternal

      protected List<Product> readActiveProductsByCategoryInternal(Long categoryId, Date currentDate)
    • readFilteredActiveProductsByQuery

      public List<Product> readFilteredActiveProductsByQuery(String query, SearchCriteria searchCriteria)
      Description copied from interface: ProductDao
      Find all products whose start and end dates are before and after the passed in date, who match the search string, match the given search criteria, and are not marked as archived.
      Specified by:
      readFilteredActiveProductsByQuery in interface ProductDao
      Returns:
      the matching products
    • readFilteredActiveProductsByQuery

      @Deprecated(forRemoval=true) public List<Product> readFilteredActiveProductsByQuery(String query, Date currentDate, SearchCriteria searchCriteria)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      readFilteredActiveProductsByQuery in interface ProductDao
      Returns:
      the matching products
    • readFilteredActiveProductsByQueryInternal

      protected List<Product> readFilteredActiveProductsByQueryInternal(String query, Date currentDate, SearchCriteria searchCriteria)
    • readFilteredActiveProductsByCategory

      public List<Product> readFilteredActiveProductsByCategory(Long categoryId, SearchCriteria searchCriteria)
      Description copied from interface: ProductDao
      Find all active products that are related to the given category, match the given search criteria, and are not marked as archived.
      Specified by:
      readFilteredActiveProductsByCategory in interface ProductDao
      Returns:
      the matching products
    • readFilteredActiveProductsByCategory

      @Deprecated(forRemoval=true) public List<Product> readFilteredActiveProductsByCategory(Long categoryId, Date currentDate, SearchCriteria searchCriteria)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      readFilteredActiveProductsByCategory in interface ProductDao
      Returns:
      the matching products
    • readFilteredActiveProductsByCategoryInternal

      protected List<Product> readFilteredActiveProductsByCategoryInternal(Long categoryId, Date currentDate, SearchCriteria searchCriteria)
    • attachActiveRestriction

      protected void attachActiveRestriction(Date currentDate, jakarta.persistence.criteria.Path<? extends Product> product, jakarta.persistence.criteria.Path<? extends Sku> sku, List<jakarta.persistence.criteria.Predicate> restrictions)
    • attachOrderBy

      protected void attachOrderBy(SearchCriteria searchCriteria, jakarta.persistence.criteria.From<?,? extends Product> product, jakarta.persistence.criteria.Path<? extends Sku> sku, jakarta.persistence.criteria.CriteriaQuery<?> criteria)
    • attachSearchCriteria

      protected void attachSearchCriteria(SearchCriteria searchCriteria, jakarta.persistence.criteria.From<?,? extends Product> product, jakarta.persistence.criteria.From<?,? extends Sku> sku, List<jakarta.persistence.criteria.Predicate> restrictions)
    • readActiveProductsByCategory

      public List<Product> readActiveProductsByCategory(Long categoryId, int limit, int offset)
      Description copied from interface: ProductDao
      Read a page of products for a category.
      Specified by:
      readActiveProductsByCategory in interface ProductDao
      Returns:
    • readActiveProductsByCategory

      @Deprecated(forRemoval=true) public List<Product> readActiveProductsByCategory(Long categoryId, Date currentDate, int limit, int offset)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      readActiveProductsByCategory in interface ProductDao
    • readActiveProductsByCategoryInternal

      public List<Product> readActiveProductsByCategoryInternal(Long categoryId, Date currentDate, int limit, int offset)
    • readProductsByCategory

      public List<Product> readProductsByCategory(Long categoryId)
      Description copied from interface: ProductDao
      Find all products related to the passed in category
      Specified by:
      readProductsByCategory in interface ProductDao
      Parameters:
      categoryId - the primary key of the category to whom the resulting product list should be related
      Returns:
      the list of products qualified for the category
    • readProductsByCategory

      public List<Product> readProductsByCategory(Long categoryId, int limit, int offset)
      Description copied from interface: ProductDao
      Find all products related to the passed in category
      Specified by:
      readProductsByCategory in interface ProductDao
      Parameters:
      categoryId - the primary key of the category to whom the resulting product list should be related
      limit - the maximum number of results to return
      offset - the starting point in the record set
      Returns:
      the list of products qualified for the category
    • delete

      public void delete(Product product)
      Description copied from interface: ProductDao
      Remove the passed in product instance from the datastore
      Specified by:
      delete in interface ProductDao
      Parameters:
      product - the product instance to remove
    • create

      public Product create(ProductType productType)
      Description copied from interface: ProductDao
      Create a new Product instance. The system will use the configuration in /BroadleafCommerce/core/BroadleafCommerceFramework/src/main/resources/bl-framework-applicationContext-entity.xml to determine which polymorphic version of Product to instantiate. To make Broadleaf instantiate your extension of Product by default, include an entity configuration bean in your application context xml similar to:

      <bean id="blEntityConfiguration" class="org.broadleafcommerce.common.persistence.EntityConfiguration"> <property name="entityContexts"> <list> <value>classpath:myCompany-applicationContext-entity.xml</value> </list> </property> </bean>

      Declare the same key for your desired entity in your entity xml that is used in the Broadleaf entity xml, but change the value to the fully qualified classname of your entity extension.
      Specified by:
      create in interface ProductDao
      Parameters:
      productType - the type of product you would like to create (presumably a Product or ProductSku instance). The getType method of ProductType provides the key for the entity configuration.
      Returns:
      a Product instance based on the Broadleaf entity configuration.
    • readAutomaticProductBundles

      public List<ProductBundle> readAutomaticProductBundles()
      Description copied from interface: ProductDao
      Returns all active ProductBundles whose automatic property is true.
      Specified by:
      readAutomaticProductBundles in interface ProductDao
      Returns:
    • getCurrentDateResolution

      public Long getCurrentDateResolution()
      Description copied from interface: ProductDao
      Returns the number of milliseconds that the current date/time will be cached for queries before refreshing. This aids in query caching, otherwise every query that utilized current date would be different and caching would be ineffective.
      Specified by:
      getCurrentDateResolution in interface ProductDao
      Returns:
      the milliseconds to cache the current date/time
    • setCurrentDateResolution

      public void setCurrentDateResolution(Long currentDateResolution)
      Description copied from interface: ProductDao
      Sets the number of milliseconds that the current date/time will be cached for queries before refreshing. This aids in query caching, otherwise every query that utilized current date would be different and caching would be ineffective.
      Specified by:
      setCurrentDateResolution in interface ProductDao
      Parameters:
      currentDateResolution - the milliseconds to cache the current date/time
    • findProductByURI

      public List<Product> findProductByURI(String uri)
      Description copied from interface: ProductDao
      Look up a product that matches the given URI
      Specified by:
      findProductByURI in interface ProductDao
      Parameters:
      uri - - the relative URL to look up the Product by
      Returns:
      List of products that match the passed in URI.
    • readAllActiveProducts

      public List<Product> readAllActiveProducts(int page, int pageSize)
      Description copied from interface: ProductDao
      Reads all products from the database that are currently active. This method differs from ProductDao.readAllActiveProducts() in that this one will utilize database paging.

      It will fetch results in pages. For example, if page = 3 and pageSize = 25, this method would return rows 75-99 from the database.

      When possible, it is suggested to use ProductDao.readAllActiveProducts(Integer, Long) instead for performance.

      Specified by:
      readAllActiveProducts in interface ProductDao
      Parameters:
      page - - the number of the page to get (0 indexed)
      pageSize - - the number of results per page
      Returns:
      a list of active products for the given page
    • readAllActiveProducts

      public List<Product> readAllActiveProducts(Integer pageSize, Long lastId)
      Description copied from interface: ProductDao
      Reads all products from the database that are currently active. This method utilizes efficient paging to retrieve a subset of records. This approach does not use an offset technique (like ProductDao.readAllActiveProducts(int, int), but rather limits the retrieved records to those greater than the given id and returns a max results of pageSize. This is more efficient that using an offset, since the database will not have to retrieve all the records from the beginning of the table and trim the offset.
      Specified by:
      readAllActiveProducts in interface ProductDao
      Parameters:
      pageSize - the number of results per page
      lastId - the last id from the previous page - can be null if this is the first page request
      Returns:
      a list of active products for the given page
    • readAllActiveProducts

      @Deprecated public List<Product> readAllActiveProducts(int page, int pageSize, Date currentDate)
      Deprecated.
      Specified by:
      readAllActiveProducts in interface ProductDao
      Parameters:
      page - - the number of the page to get (0 indexed)
      pageSize - - the number of results per page
      Returns:
      a list of active products for the given page
    • readAllActiveProductsForSiteMap

      public List<Product> readAllActiveProductsForSiteMap(int page, int pageSize)
      Specified by:
      readAllActiveProductsForSiteMap in interface ProductDao
    • getCriteriaForActiveProductsForSiteMap

      protected jakarta.persistence.criteria.CriteriaQuery<Product> getCriteriaForActiveProductsForSiteMap(Date currentDate)
    • readAllActiveProductIds

      public List<Long> readAllActiveProductIds(Long lastId, int pageSize)
      Description copied from interface: ProductDao
      Reads a paginated list of active product IDs, in ascending order, starting immediately after the lastId. If the lastId is null, then this returns the first page.
      Specified by:
      readAllActiveProductIds in interface ProductDao
      Returns:
    • readAllActiveProductsInternal

      protected List<Product> readAllActiveProductsInternal(int page, int pageSize, Date currentDate)
    • readAllActiveProductsInternal

      protected List<Product> readAllActiveProductsInternal(Integer pageSize, Date currentDate, Long lastId)
    • readAllActiveProducts

      public List<Product> readAllActiveProducts()
      Description copied from interface: ProductDao
      Reads all products from the database that are currently active.
      Specified by:
      readAllActiveProducts in interface ProductDao
      Returns:
      a list of all active products
    • readAllActiveProducts

      @Deprecated public List<Product> readAllActiveProducts(Date currentDate)
      Deprecated.
      Specified by:
      readAllActiveProducts in interface ProductDao
      Returns:
      a list of all active products
    • readAllActiveProductsInternal

      protected List<Product> readAllActiveProductsInternal(Date currentDate)
    • readCountAllActiveProducts

      public Long readCountAllActiveProducts()
      Description copied from interface: ProductDao
      Returns the number of products that are currently active.
      Specified by:
      readCountAllActiveProducts in interface ProductDao
      Returns:
      the number of currently active products
    • readCountAllActiveProducts

      @Deprecated public Long readCountAllActiveProducts(Date currentDate)
      Deprecated.
      Specified by:
      readCountAllActiveProducts in interface ProductDao
      Returns:
      the number of currently active products
    • readCountAllActiveProductsInternal

      protected Long readCountAllActiveProductsInternal(Date currentDate)
    • getCriteriaForActiveProducts

      protected jakarta.persistence.criteria.CriteriaQuery<Product> getCriteriaForActiveProducts(Date currentDate)
    • getCriteriaForActiveProducts

      protected jakarta.persistence.criteria.CriteriaQuery<Product> getCriteriaForActiveProducts(Date currentDate, Long lastId, boolean forSiteMap)