mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 08:19:01 +00:00
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
This commit is contained in:
-37
@@ -19,8 +19,6 @@ package org.springframework.transaction.jta;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -54,8 +52,6 @@ import org.springframework.transaction.support.AbstractPlatformTransactionManage
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -143,10 +139,6 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||
"java:comp/TransactionSynchronizationRegistry";
|
||||
|
||||
|
||||
// JTA 2.1 UserTransaction#setReadOnly(boolean) method available?
|
||||
private static final @Nullable Method setReadOnlyMethod =
|
||||
ClassUtils.getMethodIfAvailable(UserTransaction.class, "setReadOnly", boolean.class);
|
||||
|
||||
private transient JndiTemplate jndiTemplate = new JndiTemplate();
|
||||
|
||||
private transient @Nullable UserTransaction userTransaction;
|
||||
@@ -866,12 +858,6 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||
applyIsolationLevel(txObject, definition.getIsolationLevel());
|
||||
int timeout = determineTimeout(definition);
|
||||
applyTimeout(txObject, timeout);
|
||||
|
||||
if (definition.isReadOnly()) {
|
||||
setReadOnlyIfPossible(txObject.getUserTransaction(), true);
|
||||
txObject.resetReadOnly = true;
|
||||
}
|
||||
|
||||
txObject.getUserTransaction().begin();
|
||||
}
|
||||
|
||||
@@ -918,21 +904,6 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||
}
|
||||
}
|
||||
|
||||
private void setReadOnlyIfPossible(UserTransaction ut, boolean readOnly) throws SystemException {
|
||||
if (setReadOnlyMethod != null) {
|
||||
try {
|
||||
setReadOnlyMethod.invoke(ut, readOnly);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof InvocationTargetException ute &&
|
||||
ute.getTargetException() instanceof SystemException se) {
|
||||
throw se;
|
||||
}
|
||||
ReflectionUtils.handleReflectionException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object doSuspend(Object transaction) {
|
||||
@@ -1190,14 +1161,6 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||
@Override
|
||||
protected void doCleanupAfterCompletion(Object transaction) {
|
||||
JtaTransactionObject txObject = (JtaTransactionObject) transaction;
|
||||
if (txObject.resetReadOnly) {
|
||||
try {
|
||||
setReadOnlyIfPossible(txObject.getUserTransaction(), false);
|
||||
}
|
||||
catch (SystemException ex) {
|
||||
logger.debug("Failed to reset read-only flag after after JTA completion", ex);
|
||||
}
|
||||
}
|
||||
if (txObject.resetTransactionTimeout) {
|
||||
try {
|
||||
txObject.getUserTransaction().setTransactionTimeout(0);
|
||||
|
||||
@@ -41,8 +41,6 @@ public class JtaTransactionObject implements SmartTransactionObject {
|
||||
|
||||
boolean resetTransactionTimeout = false;
|
||||
|
||||
boolean resetReadOnly = false;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new JtaTransactionObject for the given JTA UserTransaction.
|
||||
|
||||
Reference in New Issue
Block a user