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

[39] 주문 전 재고 체크 및 재고 감소 #42

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

ohsuha
Copy link
Collaborator

@ohsuha ohsuha commented Oct 16, 2024

No description provided.

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT p FROM Product p WHERE p.id IN :productIds")
List<Product> findByIdIn(List<Long> productIds);

Choose a reason for hiding this comment

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

Lock을 잡는 쿼리와 아닌 쿼리는 메소드 레벨에서 구분하는게 좋습니다. 의도치 않게 lock을 잡는 실수를 방지할 수 있습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

findByIdInWithLock 으로 메소드 이름을 변경했습니다..!

.map(OrderRequestDto.CreateDetail::getProductId)
.toList();

List<Product> products = productRepository.findByIdIn(productIds);

Choose a reason for hiding this comment

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

여기서 잡은 lock은 언제까지 유효할까요?

Copy link
Collaborator Author

@ohsuha ohsuha Oct 18, 2024

Choose a reason for hiding this comment

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

트랜잭션어노테이션으로 지정한 부분이 종료 될때까지 유효한걸로 알고 있습니다!

@ohsuha ohsuha merged commit 2729cb6 into feature/33-add-role-check Oct 18, 2024
1 check passed
@ohsuha ohsuha deleted the feature/user/39-quantity-check branch October 19, 2024 04:16
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