Skip to content
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
10393c8
empty branch init
NotableDeveloper Nov 12, 2023
669ab96
Create README.md
NotableDeveloper Nov 12, 2023
3855223
init SpringBase
NotableDeveloper Nov 12, 2023
255559f
style : 디렉터리 생성
NotableDeveloper Nov 14, 2023
f5985d1
feat : Book 클래스 작성
NotableDeveloper Nov 14, 2023
7ccbd72
feat : BookRepository interface 작성
NotableDeveloper Nov 14, 2023
37d9be5
feat : MemoryBookRepository 구현
NotableDeveloper Nov 14, 2023
2088ede
feat : BookService 구현
NotableDeveloper Nov 14, 2023
450b9b4
feat : BookController 구현
NotableDeveloper Nov 14, 2023
8f4c39d
도서 검색 긴ê¸ê°긴ê기능 구현
NotableDeveloper Nov 17, 2023
3b8d39d
feat : RegisterBookDTO 추가
NotableDeveloper Nov 19, 2023
70767e8
feat : BaseResponse 구현
NotableDeveloper Nov 19, 2023
a9ee984
feat : 예외 처리
NotableDeveloper Nov 21, 2023
ba63810
feat : BorrowBookDTO 생성
NotableDeveloper Nov 22, 2023
259572a
feat : 책 대출 기능 구현
NotableDeveloper Nov 22, 2023
7cefc4b
feat : 책 반납 기능 구현
NotableDeveloper Nov 22, 2023
ed97f88
feat : 책의 이름으로 검색하는 기능 추가
NotableDeveloper Nov 22, 2023
4f1b409
feat : StatementBookRepository 구현
NotableDeveloper Nov 29, 2023
982bfb7
refact : JdbcBookRepository로 수정
NotableDeveloper Dec 1, 2023
4fcfc13
Merge pull request #13 from ACS-Spring-Study/SpringBase-sj
NotableDeveloper Dec 1, 2023
eedeacf
fix : MariaDB 연동
NotableDeveloper Dec 1, 2023
86fc5fa
feat : DB 커넥션 연결 확인 출력문 추가
sw801733 Dec 4, 2023
efe032e
feat : findAll 기능을 위한 Statement 추가
sw801733 Dec 4, 2023
f06f468
feat : save 기능을 위한 PreparedStatement 추가
sw801733 Dec 5, 2023
10c7734
feat : findByIsbn 기능을 위한 PreparedStatement 추가
sw801733 Dec 5, 2023
0ece409
feat : existsByIsbn 기능을 위한 PreparedStatement 추가
sw801733 Dec 5, 2023
c53aaf1
refact : Response 를 위한 Book 을 set 하는 메서드 추가
sw801733 Dec 6, 2023
278c4f9
fix : sout 대신 logback 을 통한 로그 사용으로 변경
sw801733 Dec 13, 2023
a0c8825
refact : finally 에서 close 수행하도록 수정
sw801733 Dec 14, 2023
0c34ffb
refact: save 메서드의 insert SQL 문 수정
sw801733 Dec 16, 2023
4fccf07
Merge remote-tracking branch 'origin/SpringBase-sw' into SpringBase-sw
sw801733 Dec 16, 2023
e2c6274
refact : setBook 의 메서드 인자 안 단순화
sw801733 Dec 16, 2023
782e1e6
refact : return null 대신 예외 발생
sw801733 Dec 16, 2023
9a186b8
refact : existsByIsbn 메서드의 SQL 문 성능 개선
sw801733 Dec 16, 2023
bd3f91a
chore : JPA 의존성 추가
sw801733 Dec 17, 2023
fa8f0ef
feat : JPA 적용을 위한 JpaBookRepository 생성 및 적용
sw801733 Dec 17, 2023
caaa8c2
chore : JPA 와 MariaDB 데이터베이스 연동을 위한 환경 변수 설정
sw801733 Dec 17, 2023
45f9a15
feat : Book 클래스에 엔티티 매핑을 위한 어노테이션 추가
sw801733 Dec 18, 2023
ef028cb
feat : JpaBookRepository isbn 검색을 위한 메서드 추가
sw801733 Dec 18, 2023
bd962c3
fix : Book 클래스의 isbn 의 이름에 맞게 메서드 명 수정
sw801733 Dec 18, 2023
807d328
feat : JpaBookRepository title 검색을 위한 메서드 추가
sw801733 Dec 18, 2023
4adc69e
fix : JPA 구현에 맞게 findAllContainsTitle 로직 변경
sw801733 Dec 18, 2023
4cdf4c9
feat : JpaBookRepository author 검색을 위한 메서드 추가
sw801733 Dec 18, 2023
77bbc75
fix : JPA 구현에 맞게 findAllContainsAuthor 로직 변경
sw801733 Dec 18, 2023
0b6c23d
fix : Book 엔티티 ID 에 Auto increment 적용
sw801733 Dec 18, 2023
a7a14fa
fix : JPA 요청을 통한 테이블 생성 옵션 none 으로 설정
sw801733 Dec 18, 2023
fe8832f
fix : ENUM 타입 저장을 위해 @Enumerated 추가
sw801733 Dec 18, 2023
e88b640
feat : JpaBookRepository category 검색을 위한 메서드 추가
sw801733 Dec 18, 2023
398462c
fix : JPA 구현에 맞게 findAllByCategory 로직 변경
sw801733 Dec 18, 2023
3ee673b
fix : 책 대여와 반납의 상태 변화에 맞게 DB 업데이트 수행
sw801733 Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/main/java/com/example/demo/repository/JdbcBookRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public class JdbcBookRepository implements BookRepository {
private static Statement statement;
private static PreparedStatement preparedStatement;

private Book setBook(ResultSet resultSet) throws SQLException {
Book book = new Book();

book.setTitle(resultSet.getString("title"));
book.setIsbn(resultSet.getString("isbn"));
book.setAuthor(resultSet.getString("author"));
book.setCategory(BookCategory.valueOf(resultSet.getString("book_category")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

book의 setter 메서드에 값을 입력할 때 내부적으로 valueOf와 getter 호출이 일어나고 있습니다. 이는 앞에서 간단한 변수로 빼두어 사용하면 간결할 것 같습니다.

book.setStatus(BookStatus.valueOf(resultSet.getString("book_status")));

return book;
}

public JdbcBookRepository(){
try {
connection = DriverManager.getConnection(DATABASE_URL);
Expand Down Expand Up @@ -54,13 +66,13 @@ public Book save(Book book) {

} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

메서드가 null을 반환하는 경우는 없어야 합니다. 이 사항은 모든 메서드에 일괄 적용해주시기 바랍니다.


}

@Override
public Book findByISBN(String isbn) {
Book book = new Book();

String sql = "SELECT * from Book where isbn = ?";

Expand All @@ -72,23 +84,23 @@ public Book findByISBN(String isbn) {
ResultSet resultSet = preparedStatement.executeQuery();

if (resultSet.next()) {
book.setTitle(resultSet.getString("title"));
book.setIsbn(resultSet.getString("isbn"));
book.setAuthor(resultSet.getString("author"));
book.setCategory(BookCategory.valueOf(resultSet.getString("book_category")));
book.setStatus(BookStatus.valueOf(resultSet.getString("book_status")));

Book book = setBook(resultSet);

System.out.println(book.getTitle() + " 책 조회 성공");

return book;

} else {
System.out.println("책을 찾을 수 없습니다.");
}

return book;

} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
return null;

}

@Override
Expand Down Expand Up @@ -125,12 +137,7 @@ public List<Book> findAll() {
ResultSet resultset = statement.executeQuery(sql);

while (resultset.next()) {
Book book = new Book();
book.setTitle(resultset.getString("title"));
book.setIsbn(resultset.getString("isbn"));
book.setAuthor(resultset.getString("author"));
book.setCategory(BookCategory.valueOf(resultset.getString("book_category")));
book.setStatus(BookStatus.valueOf(resultset.getString("book_status")));
Book book = setBook(resultset);

System.out.println("모든 책 조회 성공");

Expand All @@ -139,9 +146,12 @@ public List<Book> findAll() {

resultset.close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

close 메서드는 try-catch의 finally 문에서 호출하는 것이 좋아보입니다. (예외가 발생하는 경우에도 close 할 수 있어야 함.)

또, static이 붙은 경우에는 그 특성을 잘 고려하여 close를 호출 할 것인지를 잘 생각해야 합니다.

statement.close();
} catch (SQLException e){

return books;

} catch (SQLException e) {
System.out.println(e.getMessage());
}
return books;
return null;
}
}