Skip to content

Commit d6e5301

Browse files
authored
Merge pull request quarkusio#47212 from gastaldi/transaction_active
`QuarkusTransaction.isActive()` should be compared with `Status.STATUS_ACTIVE`
2 parents 5fc2973 + 10c9eaf commit d6e5301

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/QuarkusTransaction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,23 @@ static void rollback() {
6969

7070
/**
7171
* If a transaction is active.
72+
* A transaction is considered active after it has been started and prior to a Coordinator issuing any prepares, unless the
73+
* transaction has been marked for rollback
7274
*
73-
* @return {@code true} if the transaction is active.
75+
* @return {@code true} if the transaction is in the {@link Status#STATUS_ACTIVE} state.
7476
*/
7577
static boolean isActive() {
78+
return getStatus() == Status.STATUS_ACTIVE;
79+
}
80+
81+
/**
82+
* Returns the status of the current transaction.
83+
*
84+
* @return The status of the current transaction based on the {@link Status} constants.
85+
*/
86+
static int getStatus() {
7687
try {
77-
return UserTransaction.userTransaction().getStatus() != Status.STATUS_NO_TRANSACTION;
88+
return UserTransaction.userTransaction().getStatus();
7889
} catch (SystemException e) {
7990
throw new QuarkusTransactionException(e);
8091
}
@@ -86,11 +97,7 @@ static boolean isActive() {
8697
* @return If the transaction has been marked for rollback
8798
*/
8899
static boolean isRollbackOnly() {
89-
try {
90-
return UserTransaction.userTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK;
91-
} catch (SystemException e) {
92-
throw new QuarkusTransactionException(e);
93-
}
100+
return getStatus() == Status.STATUS_MARKED_ROLLBACK;
94101
}
95102

96103
/**

0 commit comments

Comments
 (0)