generated from pricelees/issue-pr-template
[#48] Tosspay mocking 서버 구현을 위한 멀티모듈 전환 #49
@ -1,29 +1,19 @@
|
||||
package com.sangdol.common.persistence
|
||||
|
||||
import com.sangdol.common.types.exception.CommonErrorCode
|
||||
import com.sangdol.common.types.exception.RoomescapeException
|
||||
import io.github.oshai.kotlinlogging.KLogger
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
|
||||
private val log: KLogger = KotlinLogging.logger {}
|
||||
|
||||
class TransactionExecutionUtil(
|
||||
private val transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
|
||||
fun <T> withNewTransaction(isReadOnly: Boolean, action: () -> T): T {
|
||||
fun <T> withNewTransaction(isReadOnly: Boolean, action: () -> T?): T? {
|
||||
val transactionTemplate = TransactionTemplate(transactionManager).apply {
|
||||
this.isReadOnly = isReadOnly
|
||||
this.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
}
|
||||
|
||||
return transactionTemplate.execute { action() }
|
||||
?: run {
|
||||
log.error { "[TransactionExecutionUtil.withNewTransaction] 트랜잭션 작업 중 예상치 못한 null 반환 " }
|
||||
throw RoomescapeException(CommonErrorCode.UNEXPECTED_SERVER_ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user