Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import io.quarkus.arc.runtime.InterceptorBindings;
import io.quarkus.narayana.jta.runtime.NotifyingTransactionManager;
import io.quarkus.narayana.jta.runtime.TransactionConfiguration;
import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.runtime.BlockingOperationNotAllowedException;
import io.quarkus.transaction.annotations.Rollback;
import io.smallrye.mutiny.Multi;
import io.smallrye.reactive.converters.ReactiveTypeConverter;
Expand Down Expand Up @@ -64,6 +66,16 @@ public Object intercept(InvocationContext ic) throws Exception {
}
}

protected void checkBlockingAllowed() {
if (!BlockingOperationControl.isBlockingAllowed()) {
throw new BlockingOperationNotAllowedException(
"@Transactional cannot start a JTA transaction within a reactive pipeline." +
" If the annotated method is intended to be blocking, ensure it is executed on a worker thread, for example by annotating it with @Blocking.");
// TODO mention reactive transactions as an alternative?
// e.g.: If the annotated method is intended to be reactive, use Hibernate Reactive, which is currently the only extension supporting @Transactional in a reactive context
}
}

protected abstract Object doIntercept(TransactionManager tm, Transaction tx, InvocationContext ic) throws Exception;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import jakarta.transaction.TransactionManager;
import jakarta.transaction.Transactional;

import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.runtime.BlockingOperationNotAllowedException;

/**
* @author paul.robinson@redhat.com 25/05/2013
*/
Expand All @@ -26,9 +23,7 @@ public TransactionalInterceptorRequired() {
@Override
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
if (!BlockingOperationControl.isBlockingAllowed()) {
throw new BlockingOperationNotAllowedException("Cannot start a JTA transaction from the IO thread.");
}
checkBlockingAllowed();
return super.intercept(ic);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import jakarta.transaction.TransactionManager;
import jakarta.transaction.Transactional;

import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.runtime.BlockingOperationNotAllowedException;

/**
* @author paul.robinson@redhat.com 25/05/2013
*/
Expand All @@ -26,9 +23,7 @@ public TransactionalInterceptorRequiresNew() {
@Override
@AroundInvoke
public Object intercept(InvocationContext ic) throws Exception {
if (!BlockingOperationControl.isBlockingAllowed()) {
throw new BlockingOperationNotAllowedException("Cannot start a JTA transaction from the IO thread.");
}
checkBlockingAllowed();
return super.intercept(ic);
}

Expand Down
Loading