|
1 | 1 | package com.iluwatar.layers; |
2 | 2 |
|
3 | | -import java.util.List; |
4 | | - |
5 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; |
6 | 4 |
|
7 | 5 | public class App { |
8 | 6 |
|
9 | 7 | public static void main(String[] args) { |
10 | 8 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( |
11 | 9 | "applicationContext.xml"); |
12 | | - PersonDao dao = context.getBean(PersonDao.class); |
13 | | - |
14 | | - Person peter = new Person("Peter", "Sagan"); |
15 | | - Person nasta = new Person("Nasta", "Kuzminova"); |
16 | | - |
17 | | - // Add new Person records |
18 | | - dao.save(peter); |
19 | | - dao.save(nasta); |
20 | | - |
21 | | - // Count Person records |
22 | | - System.out.println("Count Person records: " + dao.count()); |
23 | | - |
24 | | - // Print all records |
25 | | - List<Person> persons = (List<Person>) dao.findAll(); |
26 | | - for (Person person : persons) { |
27 | | - System.out.println(person); |
28 | | - } |
29 | | - |
30 | | - // Find Person by surname |
31 | | - System.out.println("Find by surname 'Sagan': " + dao.findBySurname("Sagan")); |
32 | | - |
33 | | - // Update Person |
34 | | - nasta.setName("Barbora"); |
35 | | - nasta.setSurname("Spotakova"); |
36 | | - dao.save(nasta); |
37 | | - |
38 | | - System.out.println("Find by id 2: " + dao.findOne(2L)); |
39 | | - |
40 | | - // Remove record from Person |
41 | | - dao.delete(2L); |
42 | | - |
43 | | - // And finally count records |
44 | | - System.out.println("Count Person records: " + dao.count()); |
| 10 | + |
| 11 | + CakeLayerDao cakeLayerDao = context.getBean(CakeLayerDao.class); |
| 12 | + cakeLayerDao.save(new CakeLayer("strawberry", 1200)); |
| 13 | + System.out.println("Count CakeLayer records: " + cakeLayerDao.count()); |
| 14 | + |
| 15 | +// PersonDao dao = context.getBean(PersonDao.class); |
| 16 | +// |
| 17 | +// Person peter = new Person("Peter", "Sagan"); |
| 18 | +// Person nasta = new Person("Nasta", "Kuzminova"); |
| 19 | +// |
| 20 | +// // Add new Person records |
| 21 | +// dao.save(peter); |
| 22 | +// dao.save(nasta); |
| 23 | +// |
| 24 | +// // Count Person records |
| 25 | +// System.out.println("Count Person records: " + dao.count()); |
| 26 | +// |
| 27 | +// // Print all records |
| 28 | +// List<Person> persons = (List<Person>) dao.findAll(); |
| 29 | +// for (Person person : persons) { |
| 30 | +// System.out.println(person); |
| 31 | +// } |
| 32 | +// |
| 33 | +// // Find Person by surname |
| 34 | +// System.out.println("Find by surname 'Sagan': " + dao.findBySurname("Sagan")); |
| 35 | +// |
| 36 | +// // Update Person |
| 37 | +// nasta.setName("Barbora"); |
| 38 | +// nasta.setSurname("Spotakova"); |
| 39 | +// dao.save(nasta); |
| 40 | +// |
| 41 | +// System.out.println("Find by id 2: " + dao.findOne(2L)); |
| 42 | +// |
| 43 | +// // Remove record from Person |
| 44 | +// dao.delete(2L); |
| 45 | +// |
| 46 | +// // And finally count records |
| 47 | +// System.out.println("Count Person records: " + dao.count()); |
45 | 48 |
|
46 | 49 | context.close(); |
47 | 50 | } |
|
0 commit comments