diff --git a/dao/src/main/java/com/iluwatar/dao/App.java b/dao/src/main/java/com/iluwatar/dao/App.java index dd96cf807..ac6794973 100644 --- a/dao/src/main/java/com/iluwatar/dao/App.java +++ b/dao/src/main/java/com/iluwatar/dao/App.java @@ -1,47 +1,56 @@ -package com.iluwatar.dao; - -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 generateSampleCustomers() { - Customer customer1 = new Customer(1, "Adam", "Adamson"); - Customer customer2 = new Customer(2, "Bob", "Bobson"); - Customer customer3 = new Customer(3, "Carl", "Carlson"); - - List customers = new ArrayList(); - customers.add(customer1); - customers.add(customer2); - customers.add(customer3); - return customers; - } -} +package com.iluwatar.dao; + +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 { + + /** + * Program entry point + * @param args command line args + */ + 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()); + } + + /** + * Generate customers + * @return list of customers + */ + public static List generateSampleCustomers() { + Customer customer1 = new Customer(1, "Adam", "Adamson"); + Customer customer2 = new Customer(2, "Bob", "Bobson"); + Customer customer3 = new Customer(3, "Carl", "Carlson"); + + List customers = new ArrayList(); + customers.add(customer1); + customers.add(customer2); + customers.add(customer3); + return customers; + } +} diff --git a/dao/src/main/java/com/iluwatar/dao/Customer.java b/dao/src/main/java/com/iluwatar/dao/Customer.java index 7900fee67..8cfdd8034 100644 --- a/dao/src/main/java/com/iluwatar/dao/Customer.java +++ b/dao/src/main/java/com/iluwatar/dao/Customer.java @@ -1,6 +1,12 @@ package com.iluwatar.dao; +/** + * + * Customer + * + */ public class Customer { + private int id; private String firstName; private String lastName; diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java index f201d945d..2a50d2bfb 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerDao.java @@ -2,7 +2,13 @@ package com.iluwatar.dao; import java.util.List; +/** + * + * CustomerDao + * + */ public interface CustomerDao { + public List getAllCustomers(); public Customer getCusterById(int id); public void addCustomer(Customer customer); diff --git a/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java b/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java index ff5332798..4403b57ed 100644 --- a/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java +++ b/dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java @@ -3,11 +3,13 @@ package com.iluwatar.dao; import java.util.List; /** + * * The data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism. * By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database. * This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of * domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, * database schema, etc. + * */ public class CustomerDaoImpl implements CustomerDao { diff --git a/dao/src/test/java/com/iluwatar/dao/AppTest.java b/dao/src/test/java/com/iluwatar/dao/AppTest.java index d45e0ef18..5eb1ebb11 100644 --- a/dao/src/test/java/com/iluwatar/dao/AppTest.java +++ b/dao/src/test/java/com/iluwatar/dao/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.dao; - -import org.junit.Test; - -import com.iluwatar.dao.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.dao; + +import org.junit.Test; + +import com.iluwatar.dao.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +}