Class ProductDaoImpl
java.lang.Object
org.broadleafcommerce.core.catalog.dao.ProductDaoImpl
- All Implemented Interfaces:
ProductDao
- Author:
- Jeff Fischer, Andre Azzolini (apazzolini)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Dateprotected Longprotected jakarta.persistence.EntityManagerprotected org.broadleafcommerce.common.persistence.EntityConfigurationprotected ProductDaoExtensionManagerprotected SiteMapExtensionManagerprotected org.broadleafcommerce.common.sandbox.SandBoxHelper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidattachActiveRestriction(Date currentDate, jakarta.persistence.criteria.Path<? extends Product> product, jakarta.persistence.criteria.Path<? extends Sku> sku, List<jakarta.persistence.criteria.Predicate> restrictions) protected voidattachOrderBy(SearchCriteria searchCriteria, jakarta.persistence.criteria.From<?, ? extends Product> product, jakarta.persistence.criteria.Path<? extends Sku> sku, jakarta.persistence.criteria.CriteriaQuery<?> criteria) protected voidattachSearchCriteria(SearchCriteria searchCriteria, jakarta.persistence.criteria.From<?, ? extends Product> product, jakarta.persistence.criteria.From<?, ? extends Sku> sku, List<jakarta.persistence.criteria.Predicate> restrictions) create(ProductType productType) Create a newProductinstance.voidRemove the passed in product instance from the datastorefindProductByURI(String uri) Look up a product that matches the given URIprotected jakarta.persistence.criteria.CriteriaQuery<Product>getCriteriaForActiveProducts(Date currentDate) protected jakarta.persistence.criteria.CriteriaQuery<Product>getCriteriaForActiveProducts(Date currentDate, Long lastId, boolean forSiteMap) protected jakarta.persistence.criteria.CriteriaQuery<Product>getCriteriaForActiveProductsForSiteMap(Date currentDate) Returns the number of milliseconds that the current date/time will be cached for queries before refreshing.readActiveProductsByCategory(Long categoryId) Find all products whose in the passed in category.readActiveProductsByCategory(Long categoryId, int limit, int offset) Read a page of products for a category.readActiveProductsByCategory(Long categoryId, Date currentDate, int limit, int offset) Deprecated, for removal: This API element is subject to removal in a future version.readActiveProductsByCategoryInternal(Long categoryId, Date currentDate) readActiveProductsByCategoryInternal(Long categoryId, Date currentDate, int limit, int offset) readAllActiveProductIds(Long lastId, int pageSize) Reads a paginated list of active product IDs, in ascending order, starting immediately after the lastId.Reads all products from the database that are currently active.readAllActiveProducts(int page, int pageSize) Reads all products from the database that are currently active.readAllActiveProducts(int page, int pageSize, Date currentDate) Deprecated.readAllActiveProducts(Integer pageSize, Long lastId) Reads all products from the database that are currently active.readAllActiveProducts(Date currentDate) Deprecated.readAllActiveProductsForSiteMap(int page, int pageSize) readAllActiveProductsInternal(int page, int pageSize, Date currentDate) readAllActiveProductsInternal(Integer pageSize, Date currentDate, Long lastId) readAllActiveProductsInternal(Date currentDate) Returns all active ProductBundles whose automatic property is true.Returns the number of products that are currently active.readCountAllActiveProducts(Date currentDate) Deprecated.protected LongreadCountAllActiveProductsInternal(Date currentDate) readFilteredActiveProductsByCategory(Long categoryId, Date currentDate, SearchCriteria searchCriteria) Deprecated, for removal: This API element is subject to removal in a future version.readFilteredActiveProductsByCategory(Long categoryId, SearchCriteria searchCriteria) Find all active products that are related to the given category, match the given search criteria, and are not marked as archived.readFilteredActiveProductsByCategoryInternal(Long categoryId, Date currentDate, SearchCriteria searchCriteria) readFilteredActiveProductsByQuery(String query, Date currentDate, SearchCriteria searchCriteria) Deprecated, for removal: This API element is subject to removal in a future version.readFilteredActiveProductsByQuery(String query, SearchCriteria searchCriteria) 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.readFilteredActiveProductsByQueryInternal(String query, Date currentDate, SearchCriteria searchCriteria) readProductByExternalId(String externalId) readProductById(Long productId) Retrieve aProductinstance by its primary keyreadProductsByCategory(Long categoryId) Find all products related to the passed in categoryreadProductsByCategory(Long categoryId, int limit, int offset) Find all products related to the passed in categoryreadProductsByIds(List<Long> productIds) Retrieves a list of Product instances by their primary keysreadProductsByName(String searchName) Find allProductinstances whose name starts with or is equal to the passed in search parameterreadProductsByName(String searchName, int limit, int offset) Find a subset ofProductinstances whose name starts with or is equal to the passed in search parameter.Persist aProductinstance to the datastorevoidsetCurrentDateResolution(Long currentDateResolution) Sets the number of milliseconds that the current date/time will be cached for queries before refreshing.
-
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
-
currentDateResolution
-
productTypeSiteMapExtensionManager
-
cachedDate
-
-
Constructor Details
-
ProductDaoImpl
public ProductDaoImpl()
-
-
Method Details
-
save
Description copied from interface:ProductDaoPersist aProductinstance to the datastore- Specified by:
savein interfaceProductDao- Parameters:
product- the product instance- Returns:
- the updated state of the product instance after being persisted
-
readProductById
Description copied from interface:ProductDaoRetrieve aProductinstance by its primary key- Specified by:
readProductByIdin interfaceProductDao- Parameters:
productId- the primary key of the product- Returns:
- the product instance at the specified primary key
-
readProductByExternalId
- Specified by:
readProductByExternalIdin interfaceProductDao
-
readProductsByIds
Description copied from interface:ProductDaoRetrieves a list of Product instances by their primary keys- Specified by:
readProductsByIdsin interfaceProductDao- Parameters:
productIds- the list of primary keys for products- Returns:
- the list of products specified by the primary keys
-
readProductsByName
Description copied from interface:ProductDaoFind allProductinstances whose name starts with or is equal to the passed in search parameter- Specified by:
readProductsByNamein interfaceProductDao- 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:ProductDaoFind a subset ofProductinstances whose name starts with or is equal to the passed in search parameter. Res- Specified by:
readProductsByNamein interfaceProductDaolimit- the maximum number of resultsoffset- the starting point in the record set- Returns:
- the list of product instances that fit the search criteria
-
readActiveProductsByCategory
Description copied from interface:ProductDaoFind all products whose in the passed in category.- Specified by:
readActiveProductsByCategoryin interfaceProductDao- 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
-
readFilteredActiveProductsByQuery
Description copied from interface:ProductDaoFind 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:
readFilteredActiveProductsByQueryin interfaceProductDao- 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:
readFilteredActiveProductsByQueryin interfaceProductDao- 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:ProductDaoFind all active products that are related to the given category, match the given search criteria, and are not marked as archived.- Specified by:
readFilteredActiveProductsByCategoryin interfaceProductDao- 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:
readFilteredActiveProductsByCategoryin interfaceProductDao- Returns:
- the matching products
-
readFilteredActiveProductsByCategoryInternal
protected List<Product> readFilteredActiveProductsByCategoryInternal(Long categoryId, Date currentDate, SearchCriteria searchCriteria) -
attachActiveRestriction
-
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
Description copied from interface:ProductDaoRead a page of products for a category.- Specified by:
readActiveProductsByCategoryin interfaceProductDao- 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:
readActiveProductsByCategoryin interfaceProductDao
-
readActiveProductsByCategoryInternal
-
readProductsByCategory
Description copied from interface:ProductDaoFind all products related to the passed in category- Specified by:
readProductsByCategoryin interfaceProductDao- 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
Description copied from interface:ProductDaoFind all products related to the passed in category- Specified by:
readProductsByCategoryin interfaceProductDao- Parameters:
categoryId- the primary key of the category to whom the resulting product list should be relatedlimit- the maximum number of results to returnoffset- the starting point in the record set- Returns:
- the list of products qualified for the category
-
delete
Description copied from interface:ProductDaoRemove the passed in product instance from the datastore- Specified by:
deletein interfaceProductDao- Parameters:
product- the product instance to remove
-
create
Description copied from interface:ProductDaoCreate a newProductinstance. The system will use the configuration in/BroadleafCommerce/core/BroadleafCommerceFramework/src/main/resources/bl-framework-applicationContext-entity.xmlto determine which polymorphic version ofProductto instantiate. To make Broadleaf instantiate your extension ofProductby default, include an entity configuration bean in your application context xml similar to:
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.<bean id="blEntityConfiguration" class="org.broadleafcommerce.common.persistence.EntityConfiguration"> <property name="entityContexts"> <list> <value>classpath:myCompany-applicationContext-entity.xml</value> </list> </property> </bean>- Specified by:
createin interfaceProductDao- Parameters:
productType- the type of product you would like to create (presumably a Product or ProductSku instance). The getType method ofProductTypeprovides the key for the entity configuration.- Returns:
- a
Productinstance based on the Broadleaf entity configuration.
-
readAutomaticProductBundles
Description copied from interface:ProductDaoReturns all active ProductBundles whose automatic property is true.- Specified by:
readAutomaticProductBundlesin interfaceProductDao- Returns:
-
getCurrentDateResolution
Description copied from interface:ProductDaoReturns 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:
getCurrentDateResolutionin interfaceProductDao- Returns:
- the milliseconds to cache the current date/time
-
setCurrentDateResolution
Description copied from interface:ProductDaoSets 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:
setCurrentDateResolutionin interfaceProductDao- Parameters:
currentDateResolution- the milliseconds to cache the current date/time
-
findProductByURI
Description copied from interface:ProductDaoLook up a product that matches the given URI- Specified by:
findProductByURIin interfaceProductDao- Parameters:
uri- - the relative URL to look up the Product by- Returns:
- List of products that match the passed in URI.
-
readAllActiveProducts
Description copied from interface:ProductDaoReads all products from the database that are currently active. This method differs fromProductDao.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:
readAllActiveProductsin interfaceProductDao- 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
Description copied from interface:ProductDaoReads 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 (likeProductDao.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:
readAllActiveProductsin interfaceProductDao- Parameters:
pageSize- the number of results per pagelastId- 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.- Specified by:
readAllActiveProductsin interfaceProductDao- 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
- Specified by:
readAllActiveProductsForSiteMapin interfaceProductDao
-
getCriteriaForActiveProductsForSiteMap
-
readAllActiveProductIds
Description copied from interface:ProductDaoReads 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:
readAllActiveProductIdsin interfaceProductDao- Returns:
-
readAllActiveProductsInternal
-
readAllActiveProductsInternal
-
readAllActiveProducts
Description copied from interface:ProductDaoReads all products from the database that are currently active.- Specified by:
readAllActiveProductsin interfaceProductDao- Returns:
- a list of all active products
-
readAllActiveProducts
Deprecated.- Specified by:
readAllActiveProductsin interfaceProductDao- Returns:
- a list of all active products
-
readAllActiveProductsInternal
-
readCountAllActiveProducts
Description copied from interface:ProductDaoReturns the number of products that are currently active.- Specified by:
readCountAllActiveProductsin interfaceProductDao- Returns:
- the number of currently active products
-
readCountAllActiveProducts
Deprecated.- Specified by:
readCountAllActiveProductsin interfaceProductDao- Returns:
- the number of currently active products
-
readCountAllActiveProductsInternal
-
getCriteriaForActiveProducts
-
getCriteriaForActiveProducts
-