diff --git a/src/main/java/io/pivotal/pal/tracker/JdbcTimeEntryRepository.java b/src/main/java/io/pivotal/pal/tracker/JdbcTimeEntryRepository.java index 9896da0..7e9b4c3 100644 --- a/src/main/java/io/pivotal/pal/tracker/JdbcTimeEntryRepository.java +++ b/src/main/java/io/pivotal/pal/tracker/JdbcTimeEntryRepository.java @@ -4,6 +4,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.namedparam.NamedParameterUtils; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; @@ -29,6 +30,8 @@ public JdbcTimeEntryRepository(DataSource dataSource) { public TimeEntry create(TimeEntry timeEntry) { KeyHolder generatedKeyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { PreparedStatement statement = connection.prepareStatement( "INSERT INTO time_entries (project_id, user_id, date, hours) " + diff --git a/src/main/java/io/pivotal/pal/tracker/PalTrackerApplication.java b/src/main/java/io/pivotal/pal/tracker/PalTrackerApplication.java index 4068f16..32e9ef7 100644 --- a/src/main/java/io/pivotal/pal/tracker/PalTrackerApplication.java +++ b/src/main/java/io/pivotal/pal/tracker/PalTrackerApplication.java @@ -11,6 +11,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.jdbc.core.JdbcTemplate; +import javax.sql.DataSource; import java.util.TimeZone; @SpringBootApplication @@ -21,9 +22,10 @@ public static void main(String[] args) { } + @Bean - TimeEntryRepository timeEntryRepository() { - return new InMemoryTimeEntryRepository(); + TimeEntryRepository timeEntryRepository(DataSource dataSource) { + return new JdbcTimeEntryRepository(dataSource); } @Bean