-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContactRepository.groovy
More file actions
35 lines (29 loc) · 1.09 KB
/
Copy pathContactRepository.groovy
File metadata and controls
35 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@Grab("h2")
import java.sql.ResultSet
class ContactRepository {
@Autowired
JdbcTemplate jdbc
List<Contact> findAll() {
jdbc.query(
"select id, firstName, lastName, phoneNumber, emailAddress " +
"from contact order by lastName",
new RowMapper<Contact>() {
Contact mapRow(ResultSet rs, int rowNum) {
new Contact(
id: rs.getLong(1),
firstName: rs.getString(2),
lastName: rs.getString(3),
phoneNumber: rs.getString(4),
emailAddress: rs.getString(5))
}
})
}
void save(Contact contact) {
jdbc.update(
"insert into contact " +
"(firstName, lastName, phoneNumber, emailAddress) " +
"values (?, ?, ?, ?)",
contact.firstName, contact.lastName,
contact.phoneNumber, contact.emailAddress)
}
}