org.broadleafcommerce.core.catalog.dao
Class ProductDaoImpl

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

@Repository(value="blProductDao")
public class ProductDaoImpl
extends Object
implements ProductDao

Author:
Jeff Fischer, Andre Azzolini (apazzolini)

Field Summary
protected  Long currentDateResolution
           
protected  javax.persistence.EntityManager em
           
protected  EntityConfiguration entityConfiguration
           
 
Constructor Summary
ProductDaoImpl()
           
 
Method Summary
protected  void attachActiveRestriction(Date currentDate, javax.persistence.criteria.Path<? extends Product> product, javax.persistence.criteria.Path<? extends Sku> sku, List<javax.persistence.criteria.Predicate> restrictions)
           
protected  void attachOrderBy(ProductSearchCriteria searchCriteria, javax.persistence.criteria.From<?,? extends Product> product, javax.persistence.criteria.Path<? extends Sku> sku, javax.persistence.criteria.CriteriaQuery<?> criteria)
           
protected  void attachProductSearchCriteria(ProductSearchCriteria searchCriteria, javax.persistence.criteria.From<?,? extends Product> product, javax.persistence.criteria.From<?,? extends Sku> sku, List<javax.persistence.criteria.Predicate> restrictions)
           
 Product create(ProductType productType)
          Create a new Product instance.
 void delete(Product product)
          Remove the passed in product instance from the datastore
 List<Product> findProductByURI(String uri)
          Look up a product that matches the given URI
protected  javax.persistence.criteria.CriteriaQuery<Product> getCriteriaForActiveProducts(Date currentDate)
           
 Long getCurrentDateResolution()
           
protected  Date getDateFactoringInDateResolution(Date currentDate)
           
 List<Product> readActiveProductsByCategory(Long categoryId, Date currentDate)
          Find all products whose start and end dates are before and after the passed in date and who are related to the given category
 List<Product> readActiveProductsByCategory(Long categoryId, Date currentDate, int limit, int offset)
           
 List<Product> readAllActiveProducts(Date currentDate)
          Reads all products from the database that are currently active.
 List<Product> readAllActiveProducts(int page, int pageSize, Date currentDate)
          Reads all products from the database that are currently active.
 List<ProductBundle> readAutomaticProductBundles()
          Returns all active ProductBundles whose automatic property is true.
 Long readCountAllActiveProducts(Date currentDate)
          Returns the number of products that are currently active.
 List<Product> readFilteredActiveProductsByCategory(Long categoryId, Date currentDate, ProductSearchCriteria searchCriteria)
          Find all products whose start and end dates are before and after the passed in date, who are related to the given category, match the given search criteria, and are not marked as archived.
 List<Product> readFilteredActiveProductsByQuery(String query, Date currentDate, ProductSearchCriteria 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.
 Product readProductById(Long productId)
          Retrieve a Product instance by its primary key
 List<Product> readProductsByCategory(Long categoryId)
          Find all products related to the passed in category
 List<Product> readProductsByCategory(Long categoryId, int limit, int offset)
          Find all products related to the passed in category
 List<Product> readProductsByIds(List<Long> productIds)
          Retrieves a list of Product instances by their primary keys
 List<Product> readProductsByName(String searchName)
          Find all Product instances whose name starts with or is equal to the passed in search parameter
 List<Product> readProductsByName(String searchName, int limit, int offset)
          Find a subset of Product instances whose name starts with or is equal to the passed in search parameter.
 Product save(Product product)
          Persist a Product instance to the datastore
 void setCurrentDateResolution(Long currentDateResolution)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

em

protected javax.persistence.EntityManager em

entityConfiguration

protected EntityConfiguration entityConfiguration

currentDateResolution

protected Long currentDateResolution
Constructor Detail

ProductDaoImpl

public ProductDaoImpl()
Method Detail

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

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

getDateFactoringInDateResolution

protected Date getDateFactoringInDateResolution(Date currentDate)

readActiveProductsByCategory

public List<Product> readActiveProductsByCategory(Long categoryId,
                                                  Date currentDate)
Description copied from interface: ProductDao
Find all products whose start and end dates are before and after the passed in date and who are related to the given category

Specified by:
readActiveProductsByCategory in interface ProductDao
Parameters:
categoryId - the primary key of the category to whom the resulting product list should be related
currentDate - the date for which the products should be checked against to determine their active state
Returns:
the list of products qualified for the category and date

readFilteredActiveProductsByQuery

public List<Product> readFilteredActiveProductsByQuery(String query,
                                                       Date currentDate,
                                                       ProductSearchCriteria 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

readFilteredActiveProductsByCategory

public List<Product> readFilteredActiveProductsByCategory(Long categoryId,
                                                          Date currentDate,
                                                          ProductSearchCriteria searchCriteria)
Description copied from interface: ProductDao
Find all products whose start and end dates are before and after the passed in date, who 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

attachActiveRestriction

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

attachOrderBy

protected void attachOrderBy(ProductSearchCriteria searchCriteria,
                             javax.persistence.criteria.From<?,? extends Product> product,
                             javax.persistence.criteria.Path<? extends Sku> sku,
                             javax.persistence.criteria.CriteriaQuery<?> criteria)

attachProductSearchCriteria

protected void attachProductSearchCriteria(ProductSearchCriteria searchCriteria,
                                           javax.persistence.criteria.From<?,? extends Product> product,
                                           javax.persistence.criteria.From<?,? extends Sku> sku,
                                           List<javax.persistence.criteria.Predicate> restrictions)

readActiveProductsByCategory

public List<Product> readActiveProductsByCategory(Long categoryId,
                                                  Date currentDate,
                                                  int limit,
                                                  int offset)
Specified by:
readActiveProductsByCategory in interface ProductDao

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()

setCurrentDateResolution

public void setCurrentDateResolution(Long currentDateResolution)

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
Returns:
List of products that match the passed in URI.

readAllActiveProducts

public List<Product> readAllActiveProducts(int page,
                                           int pageSize,
                                           Date currentDate)
Description copied from interface: ProductDao
Reads all products from the database that are currently active. That is, reads all products that are not archived and whose start and end dates surround the currentDate. This method differs from ProductDao.readAllActiveProducts(Date) 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.

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(Date currentDate)
Description copied from interface: ProductDao
Reads all products from the database that are currently active. That is, reads all products that are not archived and whose start and end dates surround the currentDate

Specified by:
readAllActiveProducts in interface ProductDao
Returns:
a list of all active products

readCountAllActiveProducts

public Long readCountAllActiveProducts(Date currentDate)
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

getCriteriaForActiveProducts

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


Copyright © 2013. All Rights Reserved.