1 |
torben |
599 |
package dk.thoerup.hibertest1;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
public class Example1 {
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* @param args
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
|
|
public static void printList(List<Employee> emps) {
|
14 |
|
|
for (Employee e : emps) {
|
15 |
|
|
System.out.println(" - " + e.getId() + " : " + e.getName() + " (" + e.getDepartment().getName() + ")" );
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
public static void main(String[] args) throws Exception {
|
21 |
|
|
EmployeeDAO dao = new EmployeeDAO();
|
22 |
|
|
|
23 |
|
|
List<Employee> list = dao.getAll();
|
24 |
|
|
|
25 |
|
|
printList(list);
|
26 |
|
|
|
27 |
|
|
Employee emp = dao.getEmployeeById(3);
|
28 |
|
|
dao.updateEmployee(emp);
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
/*
|
32 |
|
|
emp = dao.getEmployeeById(6);
|
33 |
|
|
System.out.println("Employee #6 : " + emp.getName());
|
34 |
|
|
|
35 |
|
|
String search = "marC";
|
36 |
|
|
list = dao.getEmployeesByName(search);
|
37 |
|
|
System.out.println("Employee named '" + search + "' : ");
|
38 |
|
|
printList(list);
|
39 |
|
|
|
40 |
|
|
Employee emp2 = dao.getEmployeeById(11);
|
41 |
|
|
emp2.setName("Hello World");
|
42 |
|
|
dao.updateEmployee(emp2);
|
43 |
|
|
|
44 |
|
|
emp = dao.getEmployeeById(12);
|
45 |
|
|
if (emp != null)
|
46 |
|
|
dao.deleteEmployee(emp);
|
47 |
|
|
else
|
48 |
|
|
System.out.println("no emp with id=12");*/
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
} |