Merge branch '4-db' into 'master'
Resolve "Добавить БД в проект" Closes #4 See merge request romanov73/git-extractor!2merge-requests/4/head
commit
23bcb5e1b7
@ -0,0 +1,42 @@
|
|||||||
|
package ru.ulstu.extractor.db;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import ru.ulstu.extractor.Commit;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class CommitRepository {
|
||||||
|
private final static String SQL_SELECT_COMMITS = "SELECT * FROM commit";
|
||||||
|
private final static String SQL_INSERT_COMMITS = "INSERT INTO commit (hash, date, author, message) " +
|
||||||
|
"VALUES (?, ?, ?, ?)";
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public CommitRepository(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CommitRowMapper implements RowMapper<Commit> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Commit mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
|
return new Commit(rs.getString("message"),
|
||||||
|
rs.getString("author"),
|
||||||
|
rs.getDate("date"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Commit> getCommits() {
|
||||||
|
return jdbcTemplate.query(SQL_SELECT_COMMITS, new CommitRowMapper());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveCommit(Commit commit) {
|
||||||
|
jdbcTemplate.update(SQL_INSERT_COMMITS, "", commit.getDate(),
|
||||||
|
commit.getAuthor(),
|
||||||
|
commit.getMessage());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue