Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added JdbcTemplate + simple scaffolding
- Loading branch information
Showing
10 changed files
with
126 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ie.cit.cad.data.dao; | ||
|
||
import ie.cit.cad.Todo; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
public class JdbcTodoRepository implements TodoRepository { | ||
|
||
private JdbcTemplate jdbcTemplate; | ||
|
||
public JdbcTodoRepository(DataSource dataSource) { | ||
jdbcTemplate = new JdbcTemplate(dataSource); | ||
} | ||
|
||
public List<Todo> getAll() { | ||
return jdbcTemplate.query("SELECT * FROM TODO", new TodoRowMapper()); | ||
} | ||
|
||
public Todo findById(String id) { | ||
return null; | ||
} | ||
|
||
public void add(Todo todo) { | ||
|
||
} | ||
|
||
public void delete(String id) { | ||
|
||
} | ||
|
||
public void update(Todo todo) { | ||
|
||
} | ||
} | ||
|
||
class TodoRowMapper implements RowMapper<Todo> { | ||
|
||
public Todo mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
Todo todo = new Todo(); | ||
todo.setId(rs.getString("ID")); | ||
todo.setText(rs.getString("TEXT")); | ||
todo.setDone(rs.getBoolean("DONE")); | ||
return todo; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ie.cit.cad.data.dao; | ||
|
||
import ie.cit.cad.Todo; | ||
|
||
import java.util.List; | ||
|
||
public interface TodoRepository { | ||
List<Todo> getAll(); | ||
|
||
Todo findById(String id); | ||
|
||
void add(Todo todo); | ||
|
||
void delete(String id); | ||
|
||
void update(Todo todo); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE TABLE TODO(ID VARCHAR, TEXT VARCHAR, DONE BOOLEAN, PRIMARY KEY(ID)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" | ||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | ||
|
||
<bean id="todoRepository" class="ie.cit.cad.TodoRepository" /> | ||
|
||
<bean class="ie.cit.cad.data.dao.JdbcTodoRepository"> | ||
<constructor-arg ref="dataSource" /> | ||
</bean> | ||
|
||
<jdbc:embedded-database id="dataSource" type="H2"> | ||
<jdbc:script location="classpath:db-schema.sql" /> | ||
</jdbc:embedded-database> | ||
|
||
<bean class="org.h2.tools.Server" factory-method="createWebServer" | ||
init-method="start" lazy-init="false"> | ||
<constructor-arg value="-web,-webPort,8082" /> | ||
</bean> | ||
</beans> |