diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java index 0451f0518e..250bb2a236 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java @@ -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 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); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java index 5734cf0bbd..5b6e58be45 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java @@ -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 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); diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java index a13c8caee7..280669b83f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java @@ -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 contextId = SingletonSupplier.of(UUID::randomUUID); private final Map 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 getResources() { diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java index d6daab76de..54f7cd17a0 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java @@ -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 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 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); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java index d825952eb3..74dc7a3d5a 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java @@ -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 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); diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java index e1a403ebf9..3b6e1558ac 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java @@ -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(); }