-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
homework-5 (with bonus) #5
Conversation
Code Coverage
|
public final class TimeConstants { | ||
|
||
public final static OffsetDateTime MIN_DATE_TIME = | ||
OffsetDateTime.parse("0001-01-01T00:00:00Z"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OffsetDateTime.now()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Подправил на OffsetDateTime.now()
public class BranchDao { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Transactional | ||
public boolean exists(Branch branch) { | ||
String countSql = """ | ||
SELECT COUNT(*) AS row_count\s | ||
FROM "Branch"\s | ||
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ? | ||
"""; | ||
var rowCount = jdbcTemplate.queryForObject( | ||
countSql, | ||
Integer.class, | ||
branch.getRepositoryOwner(), | ||
branch.getRepositoryName(), | ||
branch.getBranchName() | ||
); | ||
return rowCount != null && rowCount == 1; | ||
} | ||
|
||
@Transactional | ||
public void add(Branch branch) { | ||
String sql = """ | ||
INSERT INTO "Branch" (repository_owner, repository_name, branch_name, last_commit_time)\s | ||
VALUES (?, ?, ?, ?) | ||
"""; | ||
jdbcTemplate.update( | ||
sql, | ||
branch.getRepositoryOwner(), | ||
branch.getRepositoryName(), | ||
branch.getBranchName(), | ||
branch.getLastCommitTime() | ||
); | ||
} | ||
|
||
@Transactional | ||
public void delete(Branch branch) { | ||
if (!exists(branch)) { | ||
throw new InvalidDataAccessResourceUsageException("Branch not found!"); | ||
} | ||
|
||
String sql = """ | ||
DELETE FROM "Branch"\s | ||
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ? | ||
"""; | ||
jdbcTemplate.update( | ||
sql, | ||
branch.getRepositoryOwner(), | ||
branch.getRepositoryName(), | ||
branch.getBranchName() | ||
); | ||
} | ||
|
||
@Transactional | ||
public List<Branch> findAll() { | ||
String sql = "SELECT * FROM \"Branch\""; | ||
return jdbcTemplate.query(sql, (rs, rowNum) -> | ||
new Branch( | ||
rs.getLong("id"), | ||
rs.getString("repository_owner"), | ||
rs.getString("repository_name"), | ||
rs.getString("branch_name"), | ||
rs.getObject("last_commit_time", OffsetDateTime.class) | ||
) | ||
); | ||
} | ||
|
||
@Transactional | ||
public List<Branch> findAllByOwnerAndName(String owner, String name) { | ||
String sql = "SELECT * FROM \"Branch\" WHERE repository_owner = ? AND repository_name = ?"; | ||
return jdbcTemplate.query(sql, (rs, rowNum) -> | ||
new Branch( | ||
rs.getLong("id"), | ||
rs.getString("repository_owner"), | ||
rs.getString("repository_name"), | ||
rs.getString("branch_name"), | ||
rs.getObject("last_commit_time", OffsetDateTime.class) | ||
), owner, name | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BranchDao?
В задании 5-ом хотели реализовать через интерфейс, BranchDao, JdbcBranchDao, JooqBranchDao и т.д..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обговорили в телеграме
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jooq, Предлагаю создать отдельный модуль где будет лежать вся модель. ? Почему, потому что ее часто приходится перегенирировать. И будет аккуратнее выглядеть
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделано!
@Transactional | ||
public boolean exists(Branch branch) { | ||
String countSql = """ | ||
SELECT COUNT(*) AS row_count\s | ||
FROM "Branch"\s | ||
WHERE repository_owner = ? AND repository_name = ? AND branch_name = ? | ||
"""; | ||
var rowCount = jdbcTemplate.queryForObject( | ||
countSql, | ||
Integer.class, | ||
branch.getRepositoryOwner(), | ||
branch.getRepositoryName(), | ||
branch.getBranchName() | ||
); | ||
return rowCount != null && rowCount == 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У всех какая-то общая проблема. Создают транзакцию избыточно.
На селекте то она зачем?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Подправил
); | ||
} | ||
|
||
@Transactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В одной бизнес-логике используется несколько транзакций, точно он так нужно? Может мы должны удалить в одном месте и в другом сразу?
Транзакция выглядит избыточной.
Обычно ее вставляют когда в бизнес-логике идет работа с БД (а тут с несколькими таблицами сразу)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено!
Здравствуйте! Если что, отписал в телеграм по поводу правок |
… homework-5-with-bonus
…ges from homework-5-with-bonus
…into environment variables
Бот отслеживает следующие сценарии:
Github:
Stackoverflow: