-
Notifications
You must be signed in to change notification settings - Fork 781
feat: EXPOSED-818 Add Spring reactive transaction manager module #2685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fd81e29
6daee8b
5de74ac
9c358bc
e8e7a8e
80f3f4f
605aec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ interface R2dbcExposedConnection<OriginalConnection : Any> { | |
| /** The underlying database connection object contained by this wrapper. */ | ||
| val connection: OriginalConnection | ||
|
|
||
| /** Retrieves the current underlying database connection object in use. */ | ||
| suspend fun activeConnection(): OriginalConnection = connection | ||
|
|
||
|
Comment on lines
+14
to
+16
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't particularly want to implement this, but it solves the issue of the exact active connection being passed to Spring With JDBC, the transaction simply holds a single I wanted to achieve the same functionality for R2DBC using its native |
||
| /** Retrieves the name of the connection's catalog. */ | ||
| suspend fun getCatalog(): String | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| public final class org/jetbrains/exposed/v1/spring7/reactive/transaction/ExposedSpringReactiveTransactionAttributeSource : org/springframework/transaction/interceptor/TransactionAttributeSource { | ||
| public fun <init> ()V | ||
| public fun <init> (Lorg/springframework/transaction/interceptor/TransactionAttributeSource;Ljava/util/List;)V | ||
| public synthetic fun <init> (Lorg/springframework/transaction/interceptor/TransactionAttributeSource;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
| public fun getTransactionAttribute (Ljava/lang/reflect/Method;Ljava/lang/Class;)Lorg/springframework/transaction/interceptor/TransactionAttribute; | ||
| } | ||
|
|
||
| public final class org/jetbrains/exposed/v1/spring7/reactive/transaction/SpringReactiveTransactionManager : org/springframework/transaction/reactive/AbstractReactiveTransactionManager { | ||
| public fun <init> (Lio/r2dbc/spi/ConnectionFactory;Lorg/jetbrains/exposed/v1/r2dbc/R2dbcDatabaseConfig$Builder;Z)V | ||
| public synthetic fun <init> (Lio/r2dbc/spi/ConnectionFactory;Lorg/jetbrains/exposed/v1/r2dbc/R2dbcDatabaseConfig$Builder;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import org.gradle.api.tasks.testing.logging.* | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
| import org.jetbrains.kotlin.gradle.tasks.* | ||
|
|
||
| plugins { | ||
| kotlin("jvm") | ||
|
|
||
| alias(libs.plugins.dokka) | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| kotlin { | ||
| jvmToolchain(17) | ||
| } | ||
|
|
||
| dependencies { | ||
| api(project(":exposed-core")) | ||
| api(project(":exposed-r2dbc")) | ||
| api(libs.spring7.r2dbc) | ||
| api(libs.spring7.context) | ||
| implementation(libs.kotlinx.coroutines.reactor) | ||
|
|
||
| testImplementation(project(":exposed-r2dbc-tests")) | ||
| testImplementation(kotlin("test")) | ||
| testImplementation(libs.junit6) | ||
| testRuntimeOnly(libs.junit.platform.launcher) | ||
| testImplementation(libs.kotlinx.coroutines.debug) | ||
| testImplementation(libs.kotlinx.coroutines.test) | ||
| testImplementation(libs.spring7.test) | ||
| testImplementation(libs.slf4j) | ||
| testImplementation(libs.log4j.slf4j.impl) | ||
| testImplementation(libs.log4j.api) | ||
| testImplementation(libs.log4j.core) | ||
| testImplementation(libs.r2dbc.h2) { | ||
| exclude(group = "com.h2database", module = "h2") | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
| compilerOptions { | ||
| jvmTarget.set(JvmTarget.JVM_17) | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<Test>().configureEach { | ||
| if (JavaVersion.VERSION_1_8 > JavaVersion.current()) { | ||
| jvmArgs = listOf("-XX:MaxPermSize=256m") | ||
| } | ||
| testLogging { | ||
| events.addAll(listOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED)) | ||
| showStandardStreams = true | ||
| exceptionFormat = TestExceptionFormat.FULL | ||
| } | ||
|
|
||
| useJUnitPlatform() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.jetbrains.exposed.v1.spring7.reactive.transaction | ||
|
|
||
| import io.r2dbc.spi.R2dbcException | ||
| import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource | ||
| import org.springframework.transaction.interceptor.RollbackRuleAttribute | ||
| import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute | ||
| import org.springframework.transaction.interceptor.TransactionAttribute | ||
| import org.springframework.transaction.interceptor.TransactionAttributeSource | ||
| import java.lang.reflect.Method | ||
|
|
||
| /** | ||
| * A [TransactionAttributeSource] that adds `ExposedR2dbcException` to the rollback rules of the delegate. | ||
| * | ||
| * @property delegate The delegate [TransactionAttributeSource] to use. Defaults to [AnnotationTransactionAttributeSource]. | ||
| * If you use a custom [TransactionAttributeSource], you can pass it here. | ||
| */ | ||
| class ExposedSpringReactiveTransactionAttributeSource( | ||
| private val delegate: TransactionAttributeSource = AnnotationTransactionAttributeSource(), | ||
| private val rollbackExceptions: List<Class<out Throwable>> = listOf(R2dbcException::class.java) | ||
| ) : TransactionAttributeSource { | ||
|
|
||
| override fun getTransactionAttribute(method: Method, targetClass: Class<*>?): TransactionAttribute? { | ||
| val attr = delegate.getTransactionAttribute(method, targetClass) | ||
| if (attr is RuleBasedTransactionAttribute) { | ||
| val rules = attr.rollbackRules.toMutableList() | ||
| rollbackExceptions.forEach { exception -> | ||
| val containsException = rules.any { | ||
| it is RollbackRuleAttribute && it.exceptionName == exception.name | ||
| } | ||
| if (!containsException) { | ||
| rules.add(RollbackRuleAttribute(exception)) | ||
| } | ||
| } | ||
| attr.rollbackRules = rules | ||
| } | ||
| return attr | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.