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

created UtilConnection; #398

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

aksoli666
Copy link

create init_ds.sql on resources folder;
created entity Book;
created Dao;
used Injector;

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`.

Choose a reason for hiding this comment

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

revert

Copy link
Author

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

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.

Choose a reason for hiding this comment

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

revert file

Copy link
Author

Choose a reason for hiding this comment

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

title doesn`t unique

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);

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

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

Comment on lines 114 to 119
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;

Choose a reason for hiding this comment

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

Suggested change
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`.

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.

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

@@ -0,0 +1,5 @@
CREATE TABLE book (

Choose a reason for hiding this comment

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

Suggested change
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();

Choose a reason for hiding this comment

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

Suggested change
Book books = new Book();
Book book = new Book();

// initialize field values using setters or constructor
bookDao.create(book);
bookDao.create(books);

Choose a reason for hiding this comment

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

Suggested change
bookDao.create(books);
bookDao.create(book);

@@ -40,10 +40,10 @@ public class Book {
```

### BookDao methods:
- Book create(Book book);
- Book create(Book books);

Choose a reason for hiding this comment

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

Suggested change
- Book create(Book books);
- Book create(Book book);

- Optional<Book> findById(Long id);
- List<Book> findAll();
- Book update(Book book);
- Book update(Book books);

Choose a reason for hiding this comment

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

Suggested change
- Book update(Book books);
- Book update(Book book);

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