-
Notifications
You must be signed in to change notification settings - Fork 438
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
base: main
Are you sure you want to change the base?
Conversation
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.
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.
Wow, cool solution!
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 = ? | ||
"""; |
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.
In such case, you can move Sqls to a separate file
return executeQuery(FIND_ALL_SQL, ps -> { | ||
}, rs -> { |
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.
return executeQuery(FIND_ALL_SQL, ps -> { | |
}, rs -> { | |
return executeQuery(FIND_ALL_SQL, ps -> {}, rs -> { |
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.