-
Notifications
You must be signed in to change notification settings - Fork 0
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 #55 from WooHyeopHa/kyukyu/post
[Refactoring] 모집글 CRUD 리팩토링
- Loading branch information
Showing
32 changed files
with
399 additions
and
336 deletions.
There are no files selected for viewing
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
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
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
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
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
40 changes: 40 additions & 0 deletions
40
...se-API/src/main/java/com/whh/findmuseapi/common/annotation/OptimisticLockRetryAspect.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,40 @@ | ||
package com.whh.findmuseapi.common.annotation; | ||
|
||
import jakarta.persistence.OptimisticLockException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.hibernate.StaleObjectStateException; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.orm.ObjectOptimisticLockingFailureException; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Aspect | ||
@Order(2147483646) | ||
@Slf4j | ||
public class OptimisticLockRetryAspect { | ||
private static final int MAX_RETRIES = 1000; | ||
private static final int RETRY_DELAY_MS = 100; | ||
|
||
@Pointcut("@annotation(Retry)") | ||
public void retry() { | ||
} | ||
|
||
@Around("retry()") | ||
public Object retryOptimisticLock(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Exception exceptionHolder = null; | ||
for (int attempt = 0; attempt < MAX_RETRIES; attempt++) { | ||
try { | ||
return joinPoint.proceed(); | ||
} catch (OptimisticLockException | ObjectOptimisticLockingFailureException | StaleObjectStateException e) { | ||
log.info("Post 버전이 일치하지 않습니다. 재시도합니다."); | ||
exceptionHolder = e; | ||
Thread.sleep(RETRY_DELAY_MS); | ||
} | ||
} | ||
throw exceptionHolder; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
findMuse-API/src/main/java/com/whh/findmuseapi/common/annotation/Retry.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,11 @@ | ||
package com.whh.findmuseapi.common.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Retry { | ||
} |
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
Oops, something went wrong.