mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-23 02:25:26 +00:00
8055b9a414
Issue: #53 Signed-off-by: Magesh Khanna Vadivelu <mvadivelu@turn.com>
48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package com.iluwatar;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
*
|
|
* With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly
|
|
* interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete.
|
|
*/
|
|
public class App {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers());
|
|
|
|
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
|
|
System.out.println("customerDao.getCusterById(2): " + customerDao.getCusterById(2));
|
|
|
|
Customer customer = new Customer(4, "Dan", "Danson");
|
|
customerDao.addCustomer(customer);
|
|
|
|
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
|
|
|
|
customer.setFirstName("Daniel");
|
|
customer.setLastName("Danielson");
|
|
customerDao.updateCustomer(customer);
|
|
|
|
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
|
|
|
|
customerDao.deleteCustomer(customer);
|
|
|
|
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
|
|
}
|
|
|
|
public static List<Customer> generateSampleCustomers() {
|
|
Customer customer1 = new Customer(1, "Adam", "Adamson");
|
|
Customer customer2 = new Customer(2, "Bob", "Bobson");
|
|
Customer customer3 = new Customer(3, "Carl", "Carlson");
|
|
|
|
List<Customer> customers = new ArrayList<Customer>();
|
|
customers.add(customer1);
|
|
customers.add(customer2);
|
|
customers.add(customer3);
|
|
return customers;
|
|
}
|
|
}
|