Lazy initialization of transaction UUID (with deprecated getter methods)
Includes removal of trace logging for individual synchronization steps. Closes gh-26955
This commit is contained in:
parent
8680fdb8bc
commit
a07c7865a5
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,9 +20,6 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
|
|
@ -48,9 +45,6 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
|||
public static final String PREFIX_COMMIT_RULE = "+";
|
||||
|
||||
|
||||
/** Static for optimal serializability. */
|
||||
private static final Log logger = LogFactory.getLog(RuleBasedTransactionAttribute.class);
|
||||
|
||||
@Nullable
|
||||
private List<RollbackRuleAttribute> rollbackRules;
|
||||
|
||||
|
|
@ -129,10 +123,6 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
|||
*/
|
||||
@Override
|
||||
public boolean rollbackOn(Throwable ex) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Applying rules to determine whether transaction should rollback on " + ex);
|
||||
}
|
||||
|
||||
RollbackRuleAttribute winner = null;
|
||||
int deepest = Integer.MAX_VALUE;
|
||||
|
||||
|
|
@ -146,13 +136,8 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
|||
}
|
||||
}
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Winning rollback rule is: " + winner);
|
||||
}
|
||||
|
||||
// User superclass behavior (rollback on unchecked) if no rule matches.
|
||||
if (winner == null) {
|
||||
logger.trace("No relevant rollback rule found: applying default rules");
|
||||
return super.rollbackOn(ex);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -579,9 +579,6 @@ public abstract class AbstractReactiveTransactionManager implements ReactiveTran
|
|||
GenericReactiveTransaction status) {
|
||||
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering beforeCommit synchronization");
|
||||
}
|
||||
return TransactionSynchronizationUtils.triggerBeforeCommit(
|
||||
synchronizationManager.getSynchronizations(), status.isReadOnly());
|
||||
}
|
||||
|
|
@ -597,9 +594,6 @@ public abstract class AbstractReactiveTransactionManager implements ReactiveTran
|
|||
GenericReactiveTransaction status) {
|
||||
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering beforeCompletion synchronization");
|
||||
}
|
||||
return TransactionSynchronizationUtils.triggerBeforeCompletion(synchronizationManager.getSynchronizations());
|
||||
}
|
||||
return Mono.empty();
|
||||
|
|
@ -614,9 +608,6 @@ public abstract class AbstractReactiveTransactionManager implements ReactiveTran
|
|||
GenericReactiveTransaction status) {
|
||||
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering afterCommit synchronization");
|
||||
}
|
||||
return TransactionSynchronizationUtils.invokeAfterCommit(synchronizationManager.getSynchronizations());
|
||||
}
|
||||
return Mono.empty();
|
||||
|
|
@ -635,9 +626,6 @@ public abstract class AbstractReactiveTransactionManager implements ReactiveTran
|
|||
List<TransactionSynchronization> synchronizations = synchronizationManager.getSynchronizations();
|
||||
synchronizationManager.clearSynchronization();
|
||||
if (!status.hasTransaction() || status.isNewTransaction()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering afterCompletion synchronization");
|
||||
}
|
||||
// No transaction or new transaction for the current scope ->
|
||||
// invoke the afterCompletion callbacks immediately
|
||||
return invokeAfterCompletion(synchronizationManager, synchronizations, completionStatus);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,6 +23,7 @@ import java.util.UUID;
|
|||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.function.SingletonSupplier;
|
||||
|
||||
/**
|
||||
* Mutable transaction context that encapsulates transactional synchronizations and
|
||||
|
|
@ -40,7 +41,7 @@ public class TransactionContext {
|
|||
|
||||
private final @Nullable TransactionContext parent;
|
||||
|
||||
private final UUID contextId = UUID.randomUUID();
|
||||
private final SingletonSupplier<UUID> contextId = SingletonSupplier.of(UUID::randomUUID);
|
||||
|
||||
private final Map<Object, Object> resources = new LinkedHashMap<>();
|
||||
|
||||
|
|
@ -70,15 +71,18 @@ public class TransactionContext {
|
|||
return this.parent;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getName() {
|
||||
if (StringUtils.hasText(this.currentTransactionName)) {
|
||||
return this.contextId + ": " + this.currentTransactionName;
|
||||
String name = getCurrentTransactionName();
|
||||
if (StringUtils.hasText(name)) {
|
||||
return getContextId() + ": " + name;
|
||||
}
|
||||
return this.contextId.toString();
|
||||
return getContextId().toString();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public UUID getContextId() {
|
||||
return this.contextId;
|
||||
return this.contextId.obtain();
|
||||
}
|
||||
|
||||
public Map<Object, Object> getResources() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,8 +23,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
|
|
@ -71,8 +69,6 @@ import org.springframework.util.Assert;
|
|||
*/
|
||||
public class TransactionSynchronizationManager {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransactionSynchronizationManager.class);
|
||||
|
||||
private final TransactionContext transactionContext;
|
||||
|
||||
|
||||
|
|
@ -112,12 +108,7 @@ public class TransactionSynchronizationManager {
|
|||
@Nullable
|
||||
public Object getResource(Object key) {
|
||||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Object value = doGetResource(actualKey);
|
||||
if (value != null && logger.isTraceEnabled()) {
|
||||
logger.trace("Retrieved value [" + value + "] for key [" + actualKey + "] bound to context [" +
|
||||
this.transactionContext.getName() + "]");
|
||||
}
|
||||
return value;
|
||||
return doGetResource(actualKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,12 +131,8 @@ public class TransactionSynchronizationManager {
|
|||
Map<Object, Object> map = this.transactionContext.getResources();
|
||||
Object oldValue = map.put(actualKey, value);
|
||||
if (oldValue != null) {
|
||||
throw new IllegalStateException("Already value [" + oldValue + "] for key [" +
|
||||
actualKey + "] bound to context [" + this.transactionContext.getName() + "]");
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Bound value [" + value + "] for key [" + actualKey + "] to context [" +
|
||||
this.transactionContext.getName() + "]");
|
||||
throw new IllegalStateException(
|
||||
"Already value [" + oldValue + "] for key [" + actualKey + "] bound to context");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,8 +146,7 @@ public class TransactionSynchronizationManager {
|
|||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Object value = doUnbindResource(actualKey);
|
||||
if (value == null) {
|
||||
throw new IllegalStateException(
|
||||
"No value for key [" + actualKey + "] bound to context [" + this.transactionContext.getName() + "]");
|
||||
throw new IllegalStateException("No value for key [" + actualKey + "] bound to context");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
@ -182,12 +168,7 @@ public class TransactionSynchronizationManager {
|
|||
@Nullable
|
||||
private Object doUnbindResource(Object actualKey) {
|
||||
Map<Object, Object> map = this.transactionContext.getResources();
|
||||
Object value = map.remove(actualKey);
|
||||
if (value != null && logger.isTraceEnabled()) {
|
||||
logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from context [" +
|
||||
this.transactionContext.getName() + "]");
|
||||
}
|
||||
return value;
|
||||
return map.remove(actualKey);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -213,7 +194,6 @@ public class TransactionSynchronizationManager {
|
|||
if (isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Cannot activate transaction synchronization - already active");
|
||||
}
|
||||
logger.trace("Initializing transaction synchronization");
|
||||
this.transactionContext.setSynchronizations(new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +253,6 @@ public class TransactionSynchronizationManager {
|
|||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Cannot deactivate transaction synchronization - not active");
|
||||
}
|
||||
logger.trace("Clearing transaction synchronization");
|
||||
this.transactionContext.setSynchronizations(null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -913,9 +913,6 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
|||
*/
|
||||
protected final void triggerBeforeCommit(DefaultTransactionStatus status) {
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering beforeCommit synchronization");
|
||||
}
|
||||
TransactionSynchronizationUtils.triggerBeforeCommit(status.isReadOnly());
|
||||
}
|
||||
}
|
||||
|
|
@ -926,9 +923,6 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
|||
*/
|
||||
protected final void triggerBeforeCompletion(DefaultTransactionStatus status) {
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering beforeCompletion synchronization");
|
||||
}
|
||||
TransactionSynchronizationUtils.triggerBeforeCompletion();
|
||||
}
|
||||
}
|
||||
|
|
@ -939,9 +933,6 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
|||
*/
|
||||
private void triggerAfterCommit(DefaultTransactionStatus status) {
|
||||
if (status.isNewSynchronization()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering afterCommit synchronization");
|
||||
}
|
||||
TransactionSynchronizationUtils.triggerAfterCommit();
|
||||
}
|
||||
}
|
||||
|
|
@ -956,9 +947,6 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
|||
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
if (!status.hasTransaction() || status.isNewTransaction()) {
|
||||
if (status.isDebug()) {
|
||||
logger.trace("Triggering afterCompletion synchronization");
|
||||
}
|
||||
// No transaction or new transaction for the current scope ->
|
||||
// invoke the afterCompletion callbacks immediately
|
||||
invokeAfterCompletion(synchronizations, completionStatus);
|
||||
|
|
|
|||
|
|
@ -137,12 +137,7 @@ public abstract class TransactionSynchronizationManager {
|
|||
@Nullable
|
||||
public static Object getResource(Object key) {
|
||||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Object value = doGetResource(actualKey);
|
||||
if (value != null && logger.isTraceEnabled()) {
|
||||
logger.trace("Retrieved value [" + value + "] for key [" + actualKey + "] bound to thread [" +
|
||||
Thread.currentThread().getName() + "]");
|
||||
}
|
||||
return value;
|
||||
return doGetResource(actualKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -189,12 +184,8 @@ public abstract class TransactionSynchronizationManager {
|
|||
oldValue = null;
|
||||
}
|
||||
if (oldValue != null) {
|
||||
throw new IllegalStateException("Already value [" + oldValue + "] for key [" +
|
||||
actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Bound value [" + value + "] for key [" + actualKey + "] to thread [" +
|
||||
Thread.currentThread().getName() + "]");
|
||||
throw new IllegalStateException(
|
||||
"Already value [" + oldValue + "] for key [" + actualKey + "] bound to thread");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,8 +200,7 @@ public abstract class TransactionSynchronizationManager {
|
|||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Object value = doUnbindResource(actualKey);
|
||||
if (value == null) {
|
||||
throw new IllegalStateException(
|
||||
"No value for key [" + actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
|
||||
throw new IllegalStateException("No value for key [" + actualKey + "] bound to thread");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
@ -244,10 +234,6 @@ public abstract class TransactionSynchronizationManager {
|
|||
if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
|
||||
value = null;
|
||||
}
|
||||
if (value != null && logger.isTraceEnabled()) {
|
||||
logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread [" +
|
||||
Thread.currentThread().getName() + "]");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +260,6 @@ public abstract class TransactionSynchronizationManager {
|
|||
if (isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Cannot activate transaction synchronization - already active");
|
||||
}
|
||||
logger.trace("Initializing transaction synchronization");
|
||||
synchronizations.set(new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +319,6 @@ public abstract class TransactionSynchronizationManager {
|
|||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Cannot deactivate transaction synchronization - not active");
|
||||
}
|
||||
logger.trace("Clearing transaction synchronization");
|
||||
synchronizations.remove();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue