[spring] transaction이 readonly인지 확인
by 스뎅(thDeng) on현재 사용 중인 transaction이 정말 readonly로 설정되었는지 확인하고 싶을 때, TransactionSynchronizationManager#isCurrentTransactionReadOnly
를 사용해서 확인이 가능하다.
import org.springframework.transaction.support.TransactionSynchronizationManager;
@Transactional(readOnly = true)
public void testReadOnly() {
log.info("Transaction readonly flag: {}",
TransactionSynchronizationManager.isCurrentTransactionReadOnly());
// do my task
}
TransactionSynchronizationManager를 통해서 isolation level(getCurrentTransactionIsolationLevel
) 이나 transaction 이름(getCurrentTransactionName
)도 얻어올 수 있다.