Skip to content

Commit 2f1e1d4

Browse files
committed
Remove early adaptation to JTA 2.1 setReadOnly method
The UserTransaction read-only semantics are still in discussion. If they turn out to be stricter than Spring's read-only hint, we should only apply them when configured with an explicit enforceReadOnly=true flag at the Spring JtaTransactionManager level (similar to the same-named flag in DataSourceTransactionManager). See gh-35915 See gh-35633
1 parent 24d152c commit 2f1e1d4

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed

spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.ObjectInputStream;
2121
import java.io.Serializable;
22-
import java.lang.reflect.InvocationTargetException;
23-
import java.lang.reflect.Method;
2422
import java.util.List;
2523
import java.util.Properties;
2624

@@ -54,8 +52,6 @@
5452
import org.springframework.transaction.support.DefaultTransactionStatus;
5553
import org.springframework.transaction.support.TransactionSynchronization;
5654
import org.springframework.util.Assert;
57-
import org.springframework.util.ClassUtils;
58-
import org.springframework.util.ReflectionUtils;
5955
import org.springframework.util.StringUtils;
6056

6157
/**
@@ -143,10 +139,6 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
143139
"java:comp/TransactionSynchronizationRegistry";
144140

145141

146-
// JTA 2.1 UserTransaction#setReadOnly(boolean) method available?
147-
private static final @Nullable Method setReadOnlyMethod =
148-
ClassUtils.getMethodIfAvailable(UserTransaction.class, "setReadOnly", boolean.class);
149-
150142
private transient JndiTemplate jndiTemplate = new JndiTemplate();
151143

152144
private transient @Nullable UserTransaction userTransaction;
@@ -866,12 +858,6 @@ protected void doJtaBegin(JtaTransactionObject txObject, TransactionDefinition d
866858
applyIsolationLevel(txObject, definition.getIsolationLevel());
867859
int timeout = determineTimeout(definition);
868860
applyTimeout(txObject, timeout);
869-
870-
if (definition.isReadOnly()) {
871-
setReadOnlyIfPossible(txObject.getUserTransaction(), true);
872-
txObject.resetReadOnly = true;
873-
}
874-
875861
txObject.getUserTransaction().begin();
876862
}
877863

@@ -918,21 +904,6 @@ protected void applyTimeout(JtaTransactionObject txObject, int timeout) throws S
918904
}
919905
}
920906

921-
private void setReadOnlyIfPossible(UserTransaction ut, boolean readOnly) throws SystemException {
922-
if (setReadOnlyMethod != null) {
923-
try {
924-
setReadOnlyMethod.invoke(ut, readOnly);
925-
}
926-
catch (Exception ex) {
927-
if (ex instanceof InvocationTargetException ute &&
928-
ute.getTargetException() instanceof SystemException se) {
929-
throw se;
930-
}
931-
ReflectionUtils.handleReflectionException(ex);
932-
}
933-
}
934-
}
935-
936907

937908
@Override
938909
protected Object doSuspend(Object transaction) {
@@ -1190,14 +1161,6 @@ else if (getTransactionManager() != null) {
11901161
@Override
11911162
protected void doCleanupAfterCompletion(Object transaction) {
11921163
JtaTransactionObject txObject = (JtaTransactionObject) transaction;
1193-
if (txObject.resetReadOnly) {
1194-
try {
1195-
setReadOnlyIfPossible(txObject.getUserTransaction(), false);
1196-
}
1197-
catch (SystemException ex) {
1198-
logger.debug("Failed to reset read-only flag after after JTA completion", ex);
1199-
}
1200-
}
12011164
if (txObject.resetTransactionTimeout) {
12021165
try {
12031166
txObject.getUserTransaction().setTransactionTimeout(0);

spring-tx/src/main/java/org/springframework/transaction/jta/JtaTransactionObject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public class JtaTransactionObject implements SmartTransactionObject {
4141

4242
boolean resetTransactionTimeout = false;
4343

44-
boolean resetReadOnly = false;
45-
4644

4745
/**
4846
* Create a new JtaTransactionObject for the given JTA UserTransaction.

0 commit comments

Comments
 (0)