From 1f892433612ff4edfc94afcb482848d1a16d7781 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Oct 2011 01:11:17 +0000 Subject: [PATCH] use internal Set for TransactionSynchronization objects in order to allow for equals/hashCode based replacement --- .../TransactionSynchronizationManager.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java index ff10f7fe0e..f0d23dc9ba 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -19,9 +19,10 @@ package org.springframework.transaction.support; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedList; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -79,8 +80,8 @@ public abstract class TransactionSynchronizationManager { private static final ThreadLocal> resources = new NamedThreadLocal>("Transactional resources"); - private static final ThreadLocal> synchronizations = - new NamedThreadLocal>("Transaction synchronizations"); + private static final ThreadLocal> synchronizations = + new NamedThreadLocal>("Transaction synchronizations"); private static final ThreadLocal currentTransactionName = new NamedThreadLocal("Current transaction name"); @@ -256,7 +257,7 @@ public abstract class TransactionSynchronizationManager { throw new IllegalStateException("Cannot activate transaction synchronization - already active"); } logger.trace("Initializing transaction synchronization"); - synchronizations.set(new LinkedList()); + synchronizations.set(new LinkedHashSet()); } /** @@ -287,7 +288,7 @@ public abstract class TransactionSynchronizationManager { * @see TransactionSynchronization */ public static List getSynchronizations() throws IllegalStateException { - List synchs = synchronizations.get(); + Set synchs = synchronizations.get(); if (synchs == null) { throw new IllegalStateException("Transaction synchronization is not active"); } @@ -299,8 +300,9 @@ public abstract class TransactionSynchronizationManager { } else { // Sort lazily here, not in registerSynchronization. - OrderComparator.sort(synchs); - return Collections.unmodifiableList(new ArrayList(synchs)); + List sortedSynchs = new ArrayList(synchs); + OrderComparator.sort(sortedSynchs); + return Collections.unmodifiableList(sortedSynchs); } }