refactor: TransactionExecutionUtil 반환타입 Nullable 수정

This commit is contained in:
이상진 2025-09-29 15:43:35 +09:00
parent 9b6bb91095
commit 83a5919e9c

View File

@ -1,29 +1,19 @@
package com.sangdol.common.persistence 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.PlatformTransactionManager
import org.springframework.transaction.TransactionDefinition import org.springframework.transaction.TransactionDefinition
import org.springframework.transaction.support.TransactionTemplate import org.springframework.transaction.support.TransactionTemplate
private val log: KLogger = KotlinLogging.logger {}
class TransactionExecutionUtil( class TransactionExecutionUtil(
private val transactionManager: PlatformTransactionManager 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 { val transactionTemplate = TransactionTemplate(transactionManager).apply {
this.isReadOnly = isReadOnly this.isReadOnly = isReadOnly
this.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW this.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
} }
return transactionTemplate.execute { action() } return transactionTemplate.execute { action() }
?: run {
log.error { "[TransactionExecutionUtil.withNewTransaction] 트랜잭션 작업 중 예상치 못한 null 반환 " }
throw RoomescapeException(CommonErrorCode.UNEXPECTED_SERVER_ERROR)
}
} }
} }