Class ProductDAOImpl

java.lang.Object
org.example.customerdao.ProductDAOImpl
All Implemented Interfaces:
ProductDAO, Deleteable

public class ProductDAOImpl extends Object implements ProductDAO
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    addProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product)
    Adds a Product.
    void
    deleteEntity(org.example.websecurity.UserCredentials credentials, int id)
    Deletes a CuUstomerEntity by id.
    void
    deleteEntity(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.Product
    findProductById(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.
    boolean
    isDeleteable(org.example.websecurity.UserCredentials credentials, int id)
    This method will determine if a CustomerEntity record can be deleted.
    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.
    void
    Sets the Read Only DataSource for this DAO Implication.
    void
    Sets the Read/Write DataSource for this DAO Implication.
    void
    updateProduct(org.example.websecurity.UserCredentials credentials, org.example.customer.Product product)
    Updates a Product.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ProductDAOImpl

      public ProductDAOImpl()
  • Method Details

    • setReadOnlyDS

      public void setReadOnlyDS(DataSource readOnlyDS)
      Sets the Read Only DataSource for this DAO Implication.
      Specified by:
      setReadOnlyDS in interface ProductDAO
      Parameters:
      readOnlyDS - the readOnlyDS to set
    • setReadWriteDS

      public void setReadWriteDS(DataSource readWriteDS)
      Sets the Read/Write DataSource for this DAO Implication.
      Specified by:
      setReadWriteDS in interface ProductDAO
      Parameters:
      readWriteDS - the readWriteDS to set
    • findAllProducts

      public List<org.example.customer.Product> findAllProducts(org.example.websecurity.UserCredentials credentials)
      Finds all Products.
      Specified by:
      findAllProducts in interface ProductDAO
      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:
      findAllActiveProducts in interface ProductDAO
      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:
      findProductById in interface ProductDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      id - 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:
      findProductsBySupplier in interface ProductDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      supplier - 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:
      addProduct in interface ProductDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      product - 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:
      updateProduct in interface ProductDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      product - 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:
      isDeleteable in interface Deleteable
      Parameters:
      credentials - the UserCredentials for this Database operation
      entity - 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:
      isDeleteable in interface Deleteable
      Parameters:
      credentials - the UserCredentials for this Database operation
      id - 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:
      deleteEntity in interface Deleteable
      Parameters:
      credentials - the UserCredentials for this Database operation
      entity - 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:
      deleteEntity in interface Deleteable
      Parameters:
      credentials - the UserCredentials for this Database operation
      id - the CustomerEntity id to delete
      Throws:
      NonDeleteableRecordException - if this CustomerEntity cannot be deleted