-
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
created UtilConnection; #398
base: main
Are you sure you want to change the base?
Conversation
create init_ds.sql on resources folder; created entity Book; created Dao; used Injector;
README.md
Outdated
@@ -25,7 +25,7 @@ public class Main { | |||
} | |||
``` | |||
**WARNING!!!** Path to your project must contain only english letters. Also, it mustn't contain spaces. In other case `Injector` won't work correctly. | |||
- Your table should be named `books` and contain these columns: `id`, `title`, `price`. | |||
- Your table should be named `book` and contain these columns: `id`, `title`, `price`. |
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.
revert
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.
but i have table dook with columns: id, title and price
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.
according to the naming convention, table in DB should be plural
checklist.md
Outdated
@@ -3,7 +3,7 @@ | |||
* Try to avoid code duplication. Especially, when you are working with ResultSet. | |||
Move retrieving data from ResultSet into Entity object to a separate private method. | |||
|
|||
* Don't make `books.title` UNIQUE. This is not required in this task. |
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.
revert file
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.
title doesn`t unique
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.
Please, revert changes in checklist file. If you have some questions please ask in chat
statement.setObject(1, id, Types.BIGINT); | ||
ResultSet resultSet = statement.executeQuery(); | ||
if (resultSet.next()) { | ||
String title = resultSet.getObject("title", String.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.
replace logic of mapping resultSet to book into separate method
List<Book> books = new ArrayList<>(); | ||
ResultSet resultSet = statement.executeQuery(); | ||
while (resultSet.next()) { | ||
Book book = new Book(); |
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.
use separate method from comment above
int affectedRows = statement.executeUpdate(); | ||
if (affectedRows < 1) { | ||
throw new DataProcessingException("At least one row was expected to be affected, " | ||
+ "but 0 rows were affected"); | ||
} | ||
return true; |
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.
int affectedRows = statement.executeUpdate(); | |
if (affectedRows < 1) { | |
throw new DataProcessingException("At least one row was expected to be affected, " | |
+ "but 0 rows were affected"); | |
} | |
return true; | |
return statement.executeUpdate() > 0; |
README.md
Outdated
@@ -25,7 +25,7 @@ public class Main { | |||
} | |||
``` | |||
**WARNING!!!** Path to your project must contain only english letters. Also, it mustn't contain spaces. In other case `Injector` won't work correctly. | |||
- Your table should be named `books` and contain these columns: `id`, `title`, `price`. | |||
- Your table should be named `book` and contain these columns: `id`, `title`, `price`. |
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.
according to the naming convention, table in DB should be plural
checklist.md
Outdated
@@ -3,7 +3,7 @@ | |||
* Try to avoid code duplication. Especially, when you are working with ResultSet. | |||
Move retrieving data from ResultSet into Entity object to a separate private method. | |||
|
|||
* Don't make `books.title` UNIQUE. This is not required in this task. |
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.
Please, revert changes in checklist file. If you have some questions please ask in chat
src/main/resources/init_db.sql
Outdated
@@ -0,0 +1,5 @@ | |||
CREATE TABLE book ( |
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.
CREATE TABLE book ( | |
CREATE TABLE books ( |
renamed table in db(now books, was book);
@@ -17,9 +17,9 @@ public class Main { | |||
|
|||
public static void main(String[] args) { | |||
BookDao bookDao = (BookDao) injector.getInstance(BookDao.class); | |||
Book book = new Book(); | |||
Book books = new Book(); |
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.
Book books = new Book(); | |
Book book = new Book(); |
// initialize field values using setters or constructor | ||
bookDao.create(book); | ||
bookDao.create(books); |
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.
bookDao.create(books); | |
bookDao.create(book); |
@@ -40,10 +40,10 @@ public class Book { | |||
``` | |||
|
|||
### BookDao methods: | |||
- Book create(Book book); | |||
- Book create(Book books); |
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.
- Book create(Book books); | |
- Book create(Book book); |
- Optional<Book> findById(Long id); | ||
- List<Book> findAll(); | ||
- Book update(Book book); | ||
- Book update(Book books); |
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.
- Book update(Book books); | |
- Book update(Book book); |
create init_ds.sql on resources folder;
created entity Book;
created Dao;
used Injector;