Class CustomerDAOImpl

java.lang.Object
org.example.customerdao.CustomerDAOImpl
All Implemented Interfaces:
CustomerDAO, Deleteable

public final class CustomerDAOImpl extends Object implements CustomerDAO
This is the CustomerDAO Implementation for the Customer DAO component of the Customer Web Application. This will be the primary Customer 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
    addCustomer(org.example.websecurity.UserCredentials credentials, org.example.customer.Customer customer)
    Adds a Customer.
    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.Customer>
    findAllCustomers(org.example.websecurity.UserCredentials credentials)
    Finds all Customers.
    org.example.customer.Customer
    findCustomerById(org.example.websecurity.UserCredentials credentials, int id)
    Find Customer by Id.
    List<org.example.customer.Customer>
    findCustomersByName(org.example.websecurity.UserCredentials credentials, String firstName, String lastName)
    Find Customers by Name.
    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
    updateCustomer(org.example.websecurity.UserCredentials credentials, org.example.customer.Customer customer)
    Updates a Customer.

    Methods inherited from class java.lang.Object

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

    • CustomerDAOImpl

      public CustomerDAOImpl()
  • Method Details

    • setReadOnlyDS

      public void setReadOnlyDS(DataSource readOnlyDS)
      Sets the Read Only DataSource for this DAO Implication.
      Specified by:
      setReadOnlyDS in interface CustomerDAO
      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 CustomerDAO
      Parameters:
      readWriteDS - the readWriteOnlyDS to set
    • findAllCustomers

      public List<org.example.customer.Customer> findAllCustomers(org.example.websecurity.UserCredentials credentials)
      Finds all Customers.
      Specified by:
      findAllCustomers in interface CustomerDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      Returns:
      a list of Customers, this list may be empty
    • findCustomerById

      public org.example.customer.Customer findCustomerById(org.example.websecurity.UserCredentials credentials, int id)
      Find Customer by Id.

      This will return null if the Customer cannot be found.

      Specified by:
      findCustomerById in interface CustomerDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      id - the Customer ID to search for
      Returns:
      a Customer or null if the Customer is not found
    • findCustomersByName

      public List<org.example.customer.Customer> findCustomersByName(org.example.websecurity.UserCredentials credentials, String firstName, String lastName)
      Find Customers by Name.
      Specified by:
      findCustomersByName in interface CustomerDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      firstName - the first name to search for
      lastName - the last name to search for
      Returns:
      a list of Customers, this list may be empty
    • addCustomer

      public int addCustomer(org.example.websecurity.UserCredentials credentials, org.example.customer.Customer customer)
      Adds a Customer.

      Only a Manager is permitted to add a Customer.

      Specified by:
      addCustomer in interface CustomerDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      customer - the Customer object to add
      Returns:
      the id of the new Customer record
    • updateCustomer

      public void updateCustomer(org.example.websecurity.UserCredentials credentials, org.example.customer.Customer customer)
      Updates a Customer.

      Only a Manager is permitted to update a Customer.

      Specified by:
      updateCustomer in interface CustomerDAO
      Parameters:
      credentials - the UserCredentials for this Database operation
      customer - the Customer object to update
    • 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.

      Customers 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
    • 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.

      Customers 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
    • deleteEntity

      public void deleteEntity(org.example.websecurity.UserCredentials credentials, org.example.customer.utility.CustomerEntity entity)
      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.

      Customers 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
    • deleteEntity

      public void deleteEntity(org.example.websecurity.UserCredentials credentials, int id)
      Deletes a CuUstomerEntity by id.

      Only a Manager is permitted to delete a CustomerEntity.

      Customers 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