-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from marinesnow34/test
�Feat: 주문 번호 중복 문제 시퀀스 테이블 사용
- Loading branch information
Showing
4 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/readyvery/readyverydemo/domain/OrderNumberSequence.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.readyvery.readyverydemo.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Entity | ||
public class OrderNumberSequence { | ||
@Id | ||
private Long id; | ||
|
||
@Column(name = "order_number") | ||
private Long orderNumber; | ||
|
||
@OneToOne | ||
@MapsId | ||
@JoinColumn(name = "id") // Order 테이블과 조인하는 컬럼 지정 | ||
private Store store; | ||
|
||
public void increaseOrderNumber() { | ||
this.orderNumber++; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ain/java/com/readyvery/readyverydemo/domain/repository/OrderNumberSequenceRepository.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.readyvery.readyverydemo.domain.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Lock; | ||
|
||
import com.readyvery.readyverydemo.domain.OrderNumberSequence; | ||
|
||
import jakarta.persistence.LockModeType; | ||
|
||
public interface OrderNumberSequenceRepository extends JpaRepository<OrderNumberSequence, Long> { | ||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
Optional<OrderNumberSequence> findOrderNumberByStoreId(Long storeId); | ||
} |
This file contains 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
This file contains 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