Package org.example.customerdao
Class ProductDAOImpl
java.lang.Object
org.example.customerdao.ProductDAOImpl
- All Implemented Interfaces:
ProductDAO,Deleteable
This is the ProductDAO Implementation for the Customer DAO component of the
Customer Web Application. This will be the primary Product database exposure
for the Customer Web Layer.
- Since:
- 1.0
- Author:
- Jonathan Earl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product) Adds a Product.voiddeleteEntity(org.example.websecurity.UserCredentials credentials, int id) Deletes a CuUstomerEntity by id.voiddeleteEntity(org.example.websecurity.UserCredentials credentials, org.example.customer.utility.CustomerEntity entity) Deletes an CustomerEntity.List<org.example.customer.Product> findAllActiveProducts(org.example.websecurity.UserCredentials credentials) Finds all non discontinued Products.List<org.example.customer.Product> findAllProducts(org.example.websecurity.UserCredentials credentials) Finds all Products.org.example.customer.ProductfindProductById(org.example.websecurity.UserCredentials credentials, int id) Find Product by Id.List<org.example.customer.Product> findProductsBySupplier(org.example.websecurity.UserCredentials credentials, org.example.customer.Supplier supplier) Find Products by Supplier.booleanisDeleteable(org.example.websecurity.UserCredentials credentials, int id) This method will determine if a CustomerEntity record can be deleted.booleanisDeleteable(org.example.websecurity.UserCredentials credentials, org.example.customer.utility.CustomerEntity entity) Checks to see if a Product has Orders, if not the Product is deleteable.voidsetReadOnlyDS(DataSource readOnlyDS) Sets the Read Only DataSource for this DAO Implication.voidsetReadWriteDS(DataSource readWriteDS) Sets the Read/Write DataSource for this DAO Implication.voidupdateProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product) Updates a Product.
-
Constructor Details
-
ProductDAOImpl
public ProductDAOImpl()
-
-
Method Details
-
setReadOnlyDS
Sets the Read Only DataSource for this DAO Implication.- Specified by:
setReadOnlyDSin interfaceProductDAO- Parameters:
readOnlyDS- the readOnlyDS to set
-
setReadWriteDS
Sets the Read/Write DataSource for this DAO Implication.- Specified by:
setReadWriteDSin interfaceProductDAO- Parameters:
readWriteDS- the readWriteDS to set
-
findAllProducts
public List<org.example.customer.Product> findAllProducts(org.example.websecurity.UserCredentials credentials) Finds all Products.- Specified by:
findAllProductsin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operation- Returns:
- a list of Products, this list may be empty
-
findAllActiveProducts
public List<org.example.customer.Product> findAllActiveProducts(org.example.websecurity.UserCredentials credentials) Finds all non discontinued Products.- Specified by:
findAllActiveProductsin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operation- Returns:
- a list of active Products, this list may be empty
-
findProductById
public org.example.customer.Product findProductById(org.example.websecurity.UserCredentials credentials, int id) Find Product by Id.This will return null if the Product cannot be found.
- Specified by:
findProductByIdin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operationid- the Product ID to search for- Returns:
- a Product or null if the Product is not found
-
findProductsBySupplier
public List<org.example.customer.Product> findProductsBySupplier(org.example.websecurity.UserCredentials credentials, org.example.customer.Supplier supplier) Find Products by Supplier.- Specified by:
findProductsBySupplierin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operationsupplier- the Supplier to search for- Returns:
- a list of Products, this list may be empty
-
addProduct
public int addProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product) Adds a Product.Only a Manager is permitted to add a Product.
- Specified by:
addProductin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operationproduct- the Product object to add- Returns:
- the id of the new Product record
-
updateProduct
public void updateProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product) Updates a Product.Only a Manager is permitted to update a Product.
- Specified by:
updateProductin interfaceProductDAO- Parameters:
credentials- the UserCredentials for this Database operationproduct- the Product object to update
-
isDeleteable
public boolean isDeleteable(org.example.websecurity.UserCredentials credentials, org.example.customer.utility.CustomerEntity entity) Checks to see if a Product has Orders, if not the Product is deleteable.Only Managers can delete CustomerEntity records.
Products with Orders are not deleteable.
- Specified by:
isDeleteablein interfaceDeleteable- Parameters:
credentials- the UserCredentials for this Database operationentity- the CustomerEntity object to check- Returns:
- true if the CustomerEntity is deleteable
-
isDeleteable
public boolean isDeleteable(org.example.websecurity.UserCredentials credentials, int id) This method will determine if a CustomerEntity record can be deleted.Only Managers can delete CustomerEntity records.
Products with Orders are not deleteable.
- Specified by:
isDeleteablein interfaceDeleteable- Parameters:
credentials- the UserCredentials for this Database operationid- the if of the object to delete- Returns:
- true if the object is deleteable
-
deleteEntity
public void deleteEntity(org.example.websecurity.UserCredentials credentials, org.example.customer.utility.CustomerEntity entity) throws NonDeleteableRecordException Deletes an CustomerEntity.Only a Manager is permitted to delete a CustomerEntity.
If this CustomerEntity fails to meet the criteria for deletion, the delete will fail.
Products with Orders are not deleteable.
- Specified by:
deleteEntityin interfaceDeleteable- Parameters:
credentials- the UserCredentials for this Database operationentity- the CustomerEntity object to delete- Throws:
NonDeleteableRecordException- if this CustomerEntity cannot be deleted
-
deleteEntity
public void deleteEntity(org.example.websecurity.UserCredentials credentials, int id) throws NonDeleteableRecordException Deletes a CuUstomerEntity by id.Only a Manager is permitted to delete a CustomerEntity.
Products with Orders are not deleteable.
- Specified by:
deleteEntityin interfaceDeleteable- Parameters:
credentials- the UserCredentials for this Database operationid- the CustomerEntity id to delete- Throws:
NonDeleteableRecordException- if this CustomerEntity cannot be deleted
-