/**
* Copyright (c) 2001, Keith Wong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package mypackage;
import java.sql.Date;
import java.util.HashMap;
import java.util.Collection;
/**
* This class holds all the customer functions.
*
* @author Keith Wong
*/
public class CustomerDomain
{
/**
* This is a stub variable, in a real application you would retrieve
* these details from a database or some permanent data store.
*/
private static HashMap m_hmCustomers = new HashMap();
static
{
// this is for code is for the sole purpose of the example
// we are going to retrieve customers from this hash-map, not a database
m_hmCustomers.put(new Long(1),
new Customer(1,
"01",
"John",
"Jackson",
new Date(77, 5, 12),
"M",
"1 Bond St",
"2000",
"Sydney",
"New South Wales",
true,
"(02) 9765 1233",
"john_jackson@hotmail.com"));
m_hmCustomers.put(new Long(2),
new Customer(2,
"02",
"Jossie",
"Graham",
new Date(73, 2, 24),
"F",
"2 Pitt St",
"2000",
"Sydney",
"New South Wales",
true,
"(02) 9344 1255",
"jossieg@yahoo.com"));
m_hmCustomers.put(new Long(3),
new Customer(3,
"01",
"Paul",
"Peterson",
new Date(64, 10, 2),
"M",
"5 George St",
"2000",
"Sydney",
"New South Wales",
true,
"(02) 9988 1122",
"paulpeterson@mail.com"));
} // end static block
/**
* Retrieves a Customer from the database given the primary key.
* @param lCustomerId the primary key
* @return the Customer object
*/
public static final Customer retrieveCustomerDetails(long lCustomerId)
{
// stub implementation... just retrieves from the hash map!
return (Customer)m_hmCustomers.get(new Long(lCustomerId));
} // end retrieveCustomerDetails
/**
* Retrieves all the Customers from the database.
* @return a collection of Customer objects
*/
public static Collection retrieveAllCustomers()
{
// stub implementation... just retrieves from the hash map!
return m_hmCustomers.values();
} // end retrieveAllCustomers
/**
* Saves the customer details.
* @param objCustomer the new customer details
*/
public static void saveCustomerDetails(Customer objCustomer)
{
m_hmCustomers.put(objCustomer.getCustomerId(), objCustomer);
} // end saveCustomerDetails
} // end class