|
@@ -1,15 +1,12 @@
|
1
|
1
|
package io.zipcoder.persistenceapp.service;
|
2
|
2
|
|
|
3
|
+import io.zipcoder.persistenceapp.controller.mappers.HomeRowMapper;
|
|
4
|
+import io.zipcoder.persistenceapp.controller.mappers.PersonRowMapper;
|
3
|
5
|
import io.zipcoder.persistenceapp.model.Home;
|
4
|
6
|
import io.zipcoder.persistenceapp.model.Person;
|
5
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
|
-import org.springframework.context.annotation.Bean;
|
7
|
8
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
8
|
9
|
import org.springframework.jdbc.core.JdbcTemplate;
|
9
|
|
-import org.springframework.jdbc.core.RowMapper;
|
10
|
|
-
|
11
|
|
-import java.sql.ResultSet;
|
12
|
|
-import java.sql.SQLException;
|
13
|
10
|
import java.util.List;
|
14
|
11
|
|
15
|
12
|
public class HomeService {
|
|
@@ -23,17 +20,6 @@ public class HomeService {
|
23
|
20
|
public HomeService() {
|
24
|
21
|
}
|
25
|
22
|
|
26
|
|
- class HomeRowMapper implements RowMapper<Home> {
|
27
|
|
- @Override
|
28
|
|
- public Home mapRow(ResultSet rs, int rowNum) throws SQLException {
|
29
|
|
- Home home = new Home();
|
30
|
|
- home.setAddress(rs.getString("ADDRESS"));
|
31
|
|
- home.setHomeNumber(rs.getString("HOMENUMBER"));
|
32
|
|
- home.setId(rs.getInt("id"));
|
33
|
|
- return home;
|
34
|
|
- }
|
35
|
|
- }
|
36
|
|
-
|
37
|
23
|
public void addHome(Home home) {
|
38
|
24
|
jdbcTemplate.update(
|
39
|
25
|
"INSERT INTO home(address, homenumber)" +
|
|
@@ -70,7 +56,7 @@ public class HomeService {
|
70
|
56
|
public Home findHomeById(Integer id) {
|
71
|
57
|
return jdbcTemplate.queryForObject(
|
72
|
58
|
"SELECT * FROM home WHERE ID = ?",
|
73
|
|
- new Object[] {id}, new BeanPropertyRowMapper<>(Home.class));
|
|
59
|
+ new Object[]{id}, new BeanPropertyRowMapper<>(Home.class));
|
74
|
60
|
}
|
75
|
61
|
|
76
|
62
|
public Home findHomeByHomeNumber(String homeNumber) {
|
|
@@ -94,5 +80,6 @@ public class HomeService {
|
94
|
80
|
public List<Person> generatePeopleInHome(Integer id) {
|
95
|
81
|
return jdbcTemplate.query(
|
96
|
82
|
"SELECT * FROM person INNER JOIN home on person.home_id = home.id WHERE home.id = ?",
|
97
|
|
- new Object[]{id}, new PersonService.PersonRowMapper());
|
|
83
|
+ new Object[]{id}, new PersonRowMapper());
|
|
84
|
+ }
|
98
|
85
|
}
|