Skip to content
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

Task: jv-jdbc-intro. Executor: Oleksii Bashkirov. #355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OleksiiBashkirov
Copy link

Created Book model.
Created DAO layer for Book model with save, findById, findAll, update and deleteById methods. Also created helper methods executeUpdate and executeQuery to reduce code duplication. And created two func.interfaces SqlConsumer and SqlFunction in the util package. Created a service layer with CRUD methods.
Created custom exception.
Also connected to Database(book_storage).
Created new table (books) for this task.
Created init_db.sql file in src/main/resources folder and put the scripts for creating required table. Used the @dao annotation on the BookDaoImpl class
Edited the Main class.

Created DAO layer for Book model with save, findById, findAll, update and deleteById methods. Also created helper methods executeUpdate and executeQuery to reduce code duplication.
And created two func.interfaces SqlConsumer and SqlFunction in the util package.
Created a service layer with CRUD methods.
Created custom exception.
Also connected to Database(book_storage).
Created new table (books) for this task.
Created init_db.sql file in src/main/resources folder and put the scripts for creating required table.
Used the @dao annotation on the BookDaoImpl class
Edited the Main class.
Copy link

@Vasul-Pankiv Vasul-Pankiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, cool solution!

Comment on lines +22 to +45
private static final String SAVE_SQL = """
INSERT INTO books (title, price)
VALUES(?, ?)
""";
private static final String UPDATE_SQL = """
UPDATE books
SET title = ?, price = ?
WHERE id = ?
""";
private static final String FIND_BY_ID_SQL = """
SELECT id, title, price
FROM books
WHERE id = ?
""";
private static final String FIND_ALL_SQL = """
SELECT id,
title,
price
FROM books
""";
private static final String DELETE_BY_ID_SQL = """
DELETE FROM books
WHERE id = ?
""";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such case, you can move Sqls to a separate file

Comment on lines +77 to +78
return executeQuery(FIND_ALL_SQL, ps -> {
}, rs -> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return executeQuery(FIND_ALL_SQL, ps -> {
}, rs -> {
return executeQuery(FIND_ALL_SQL, ps -> {}, rs -> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants