Resolve "Добавить БД в проект" #31

Merged
romanov73 merged 2 commits from 4-db into master 2021-03-17 09:17:02 +04:00
3 changed files with 50 additions and 1 deletions

View File

@ -50,6 +50,8 @@ dependencies {
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
compile group: 'org.postgresql', name: 'postgresql', version: '9.4.1212'
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'

View File

@ -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());
}
}

View File

@ -5,4 +5,9 @@ logging.level.ru.ulstu=DEBUG
extractor.custom-projects-dir=
# Thymeleaf Settings
spring.thymeleaf.cache=false
messages.basename.path=messages_en.properties
messages.basename.path=messages_en.properties
# JPA Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/repo
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driverclassName=org.postgresql.Driver