X Tutup
Skip to content

Commit 3526d96

Browse files
committed
iluwatar#107 Dao example JavaDoc
1 parent a7d25e0 commit 3526d96

File tree

5 files changed

+89
-61
lines changed

5 files changed

+89
-61
lines changed
Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1-
package com.iluwatar.dao;
2-
3-
import java.util.ArrayList;
4-
import java.util.List;
5-
6-
/**
7-
*
8-
* With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly
9-
* interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete.
10-
*/
11-
public class App {
12-
13-
public static void main(String[] args) {
14-
15-
CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers());
16-
17-
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
18-
System.out.println("customerDao.getCusterById(2): " + customerDao.getCusterById(2));
19-
20-
Customer customer = new Customer(4, "Dan", "Danson");
21-
customerDao.addCustomer(customer);
22-
23-
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
24-
25-
customer.setFirstName("Daniel");
26-
customer.setLastName("Danielson");
27-
customerDao.updateCustomer(customer);
28-
29-
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
30-
31-
customerDao.deleteCustomer(customer);
32-
33-
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
34-
}
35-
36-
public static List<Customer> generateSampleCustomers() {
37-
Customer customer1 = new Customer(1, "Adam", "Adamson");
38-
Customer customer2 = new Customer(2, "Bob", "Bobson");
39-
Customer customer3 = new Customer(3, "Carl", "Carlson");
40-
41-
List<Customer> customers = new ArrayList<Customer>();
42-
customers.add(customer1);
43-
customers.add(customer2);
44-
customers.add(customer3);
45-
return customers;
46-
}
47-
}
1+
package com.iluwatar.dao;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
*
8+
* With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly
9+
* interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete.
10+
*
11+
*/
12+
public class App {
13+
14+
/**
15+
* Program entry point
16+
* @param args command line args
17+
*/
18+
public static void main(String[] args) {
19+
20+
CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers());
21+
22+
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
23+
System.out.println("customerDao.getCusterById(2): " + customerDao.getCusterById(2));
24+
25+
Customer customer = new Customer(4, "Dan", "Danson");
26+
customerDao.addCustomer(customer);
27+
28+
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
29+
30+
customer.setFirstName("Daniel");
31+
customer.setLastName("Danielson");
32+
customerDao.updateCustomer(customer);
33+
34+
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
35+
36+
customerDao.deleteCustomer(customer);
37+
38+
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
39+
}
40+
41+
/**
42+
* Generate customers
43+
* @return list of customers
44+
*/
45+
public static List<Customer> generateSampleCustomers() {
46+
Customer customer1 = new Customer(1, "Adam", "Adamson");
47+
Customer customer2 = new Customer(2, "Bob", "Bobson");
48+
Customer customer3 = new Customer(3, "Carl", "Carlson");
49+
50+
List<Customer> customers = new ArrayList<Customer>();
51+
customers.add(customer1);
52+
customers.add(customer2);
53+
customers.add(customer3);
54+
return customers;
55+
}
56+
}

dao/src/main/java/com/iluwatar/dao/Customer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package com.iluwatar.dao;
22

3+
/**
4+
*
5+
* Customer
6+
*
7+
*/
38
public class Customer {
9+
410
private int id;
511
private String firstName;
612
private String lastName;

dao/src/main/java/com/iluwatar/dao/CustomerDao.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import java.util.List;
44

5+
/**
6+
*
7+
* CustomerDao
8+
*
9+
*/
510
public interface CustomerDao {
11+
612
public List<Customer> getAllCustomers();
713
public Customer getCusterById(int id);
814
public void addCustomer(Customer customer);

dao/src/main/java/com/iluwatar/dao/CustomerDaoImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import java.util.List;
44

55
/**
6+
*
67
* The data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism.
78
* By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database.
89
* This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of
910
* domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS,
1011
* database schema, etc.
12+
*
1113
*/
1214
public class CustomerDaoImpl implements CustomerDao {
1315

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
package com.iluwatar.dao;
2-
3-
import org.junit.Test;
4-
5-
import com.iluwatar.dao.App;
6-
7-
public class AppTest {
8-
9-
@Test
10-
public void test() {
11-
String[] args = {};
12-
App.main(args);
13-
}
14-
}
1+
package com.iluwatar.dao;
2+
3+
import org.junit.Test;
4+
5+
import com.iluwatar.dao.App;
6+
7+
/**
8+
*
9+
* Application test
10+
*
11+
*/
12+
public class AppTest {
13+
14+
@Test
15+
public void test() {
16+
String[] args = {};
17+
App.main(args);
18+
}
19+
}

0 commit comments

Comments
 (0)
X Tutup