-
Notifications
You must be signed in to change notification settings - Fork 2
Spring base sw #15
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
Open
sw801733
wants to merge
50
commits into
JavaBase
Choose a base branch
from
SpringBase-sw
base: JavaBase
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Spring base sw #15
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
10393c8
empty branch init
NotableDeveloper 669ab96
Create README.md
NotableDeveloper 3855223
init SpringBase
NotableDeveloper 255559f
style : 디렉터리 생성
NotableDeveloper f5985d1
feat : Book 클래스 작성
NotableDeveloper 7ccbd72
feat : BookRepository interface 작성
NotableDeveloper 37d9be5
feat : MemoryBookRepository 구현
NotableDeveloper 2088ede
feat : BookService 구현
NotableDeveloper 450b9b4
feat : BookController 구현
NotableDeveloper 8f4c39d
도서 검색 긴ê¸ê°긴ê기능 구현
NotableDeveloper 3b8d39d
feat : RegisterBookDTO 추가
NotableDeveloper 70767e8
feat : BaseResponse 구현
NotableDeveloper a9ee984
feat : 예외 처리
NotableDeveloper ba63810
feat : BorrowBookDTO 생성
NotableDeveloper 259572a
feat : 책 대출 기능 구현
NotableDeveloper 7cefc4b
feat : 책 반납 기능 구현
NotableDeveloper ed97f88
feat : 책의 이름으로 검색하는 기능 추가
NotableDeveloper 4f1b409
feat : StatementBookRepository 구현
NotableDeveloper 982bfb7
refact : JdbcBookRepository로 수정
NotableDeveloper 4fcfc13
Merge pull request #13 from ACS-Spring-Study/SpringBase-sj
NotableDeveloper eedeacf
fix : MariaDB 연동
NotableDeveloper 86fc5fa
feat : DB 커넥션 연결 확인 출력문 추가
sw801733 efe032e
feat : findAll 기능을 위한 Statement 추가
sw801733 f06f468
feat : save 기능을 위한 PreparedStatement 추가
sw801733 10c7734
feat : findByIsbn 기능을 위한 PreparedStatement 추가
sw801733 0ece409
feat : existsByIsbn 기능을 위한 PreparedStatement 추가
sw801733 c53aaf1
refact : Response 를 위한 Book 을 set 하는 메서드 추가
sw801733 278c4f9
fix : sout 대신 logback 을 통한 로그 사용으로 변경
sw801733 a0c8825
refact : finally 에서 close 수행하도록 수정
sw801733 0c34ffb
refact: save 메서드의 insert SQL 문 수정
sw801733 4fccf07
Merge remote-tracking branch 'origin/SpringBase-sw' into SpringBase-sw
sw801733 e2c6274
refact : setBook 의 메서드 인자 안 단순화
sw801733 782e1e6
refact : return null 대신 예외 발생
sw801733 9a186b8
refact : existsByIsbn 메서드의 SQL 문 성능 개선
sw801733 bd3f91a
chore : JPA 의존성 추가
sw801733 fa8f0ef
feat : JPA 적용을 위한 JpaBookRepository 생성 및 적용
sw801733 caaa8c2
chore : JPA 와 MariaDB 데이터베이스 연동을 위한 환경 변수 설정
sw801733 45f9a15
feat : Book 클래스에 엔티티 매핑을 위한 어노테이션 추가
sw801733 ef028cb
feat : JpaBookRepository isbn 검색을 위한 메서드 추가
sw801733 bd962c3
fix : Book 클래스의 isbn 의 이름에 맞게 메서드 명 수정
sw801733 807d328
feat : JpaBookRepository title 검색을 위한 메서드 추가
sw801733 4adc69e
fix : JPA 구현에 맞게 findAllContainsTitle 로직 변경
sw801733 4cdf4c9
feat : JpaBookRepository author 검색을 위한 메서드 추가
sw801733 77bbc75
fix : JPA 구현에 맞게 findAllContainsAuthor 로직 변경
sw801733 0b6c23d
fix : Book 엔티티 ID 에 Auto increment 적용
sw801733 a7a14fa
fix : JPA 요청을 통한 테이블 생성 옵션 none 으로 설정
sw801733 fe8832f
fix : ENUM 타입 저장을 위해 @Enumerated 추가
sw801733 e88b640
feat : JpaBookRepository category 검색을 위한 메서드 추가
sw801733 398462c
fix : JPA 구현에 맞게 findAllByCategory 로직 변경
sw801733 3ee673b
fix : 책 대여와 반납의 상태 변화에 맞게 DB 업데이트 수행
sw801733 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,27 @@ public Book findByISBN(String isbn) { | |
|
|
||
| @Override | ||
| public boolean existsByIsbn(String isbn) { | ||
| return false; | ||
| String sql = "SELECT * from Book where isbn = ?"; | ||
|
|
||
| try { | ||
| preparedStatement = connection.prepareStatement(sql); | ||
|
|
||
| preparedStatement.setString(1, isbn); | ||
|
|
||
| ResultSet resultSet = preparedStatement.executeQuery(); | ||
|
|
||
| if (resultSet.next()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앞서 작성한 쿼리를 개선하면서 이 부분도 보다 더 간단하게 개선할 수 있을 것으로 보입니다. |
||
| System.out.println(isbn + " 은 이미 있는 책입니다."); | ||
| return true; | ||
| } else { | ||
| System.out.println(isbn + "에 해당하는 책을 찾을 수 없습니다."); | ||
| return false; | ||
| } | ||
|
|
||
| } catch (SQLException e) { | ||
| System.out.println(e.getMessage()); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이 쿼리는 아래와 같이 개선할 수 있습니다.
SELECT isbn EXISTS (SELECT isbn FROM book WHERE isbn = ?)
위와 같이 exists와 서브쿼리를 사용하면 입력으로 주어진 isbn과 일치하는 레코드를 찾은 시점에 검색을 종료합니다.
그에 반하여 지금 작성한 쿼리는 입력으로 주어진 isbn과 일치하는 레코드를 찾아도 테이블의 모든 내용을 찾아가며 추가적으로 일치하는 레코드를 찾게 됩니다.
또, 지금처럼 단순 조회(= 값이 있는 지 혹은 없는 지와 같은 조회)의 경우, select 쿼리가 반환하려는 컬럼을 아래와 같은 와일드 카드(*)로 주게 되면, 가져오는 컬럼이 많아지게 되므로 비효율적입니다.
SELECT * from Book where isbn = ?
따라서, 아래처럼 하나의 컬럼만을 가져오는 것이 더 효율적일 것입니다.
SELECT isbn from Book where isbn = ?